/* Window onload ................................................................................................ */
window.addEvent('domready', function(){
	header();
	flashheader();
	initNav();	
});



function $showhide(id){
	$(id).style.display = ($(id).style.display == 'none') ? '' : 'none';
}



function header()
{	
	var s1 = new SWFObject("/_img/header/header.swf","header","840","120","6");
	s1.write("header");
}



function flashheader()
{
	var s1 = new SWFObject("imageheader.swf","rotator","450","150","6");
	s1.addVariable("file","playlist.xml");
	s1.addVariable("transition","slowfade");
	s1.addVariable("shuffle","true");
	s1.addVariable("overstretch","true");
	s1.addVariable("backcolor","0xFFFFFF");
	s1.write("headeranim");
}


function initNav()
{
	// Hide all lists within main navigation.
	$$('#mainnav ul').each(function(el){
		$(el).style.display = 'none';
	});
	
	// If there's a selected item, display (and its parents).
	var sel = $E('#mainnav li.selected');

	if(sel){
		elParent = sel.getParent();
		elGrandParent = sel.getParent().getParent().getParent();
		if(elParent.getStyle('display') == 'none') elParent.setStyle('display', '');
		if(elGrandParent.getStyle('display') == 'none') elGrandParent.setStyle('display', '');
	}

	// Add click and rollover events to every list item.
	$$('#mainnav li').addEvents({
		'click':function(e){
			e = new Event(e);
			e.stopPropagation();
			showNav(this);
		},
		'mouseover':function(){ this.style.cursor = 'pointer' },
		'mouseout':function(){ this.style.cursor = '' }
	});
	
}


function showNav(el)
{
	// If the clicked list item has a list inside, show/hide it.
	ul = $(el).getElement('ul');
	if(ul) $showhide(ul);
}
