window.addEvent('domready', function(){

// tpilogo
if (!window.XMLHttpRequest) {
	$$('#tpilogo img')[0].src = '/images/tpi.gif';
	
	$$("#sidebar_links li").forEach(function (link){
		link.addEvent('click', function(e)
		{
			location.href = (new Event(e).target).childNodes[0].href;
		});
	});
}

// Sidebar Rollover (OBJSIDEPNG)
$$("#sidebar_links li").forEach(function (link){
	link.addEvent('mouseover', function(e)
	{
		var target = (new Event(e).target);
		if (target.tagName == 'IMG') return;
		
		$('objsidepng').setStyles({
			left: '56px',
			top:  $(link.childNodes[0]).getPosition().y - 8,
			display: 'inline'
		}).onclick = function(){
			location.href = target.tagName == 'A' ? target.href : target.childNodes[0].href;
			new Event(e).stopPropagation();
		};
	});
});

var menu = null;

$$("#navmenu li a").forEach(function (link){						  
	link.addEvent('mouseover', function(e)
	{
		if (menu && menu.parentNode)  menu.remove();
		var text = link.getNext().getValue();
		
		if (text != '') { 
			menu = new Element('ul', {id: 'dropmenu'}).inject($("wrapper"));
			text.split(';;').forEach(function (item){
				var parse = item.split(';');
				if (parse.length < 3) return;
				new Element('a', {href: parse[1], title: parse[2]}).appendText(parse[0]).inject(new Element('li').inject(menu));
				
				var pos = link.getPosition();
				
				menu.setStyles({
					top: 		pos.y + 15,
					left:		pos.x,
					display:	'inline'
				});
				
				document.body.onclick = function(){
					menu.setStyle('display', 'none');
				};
			});
		}
	});
});

});