// JavaScript Document

document.observe("dom:loaded", show_menu);

var stack = new Array();

function show_menu() {

	$$('.button_selected').each ( function (n) { n.writeAttribute('selected'); } );
	
	$$('.button_selected, .button').each( function (n) {
		n.observe('mouseover', response_in.bindAsEventListener( n ) );
		n.observe('mouseout', response_out.bindAsEventListener( n ) );
		stack[n.id] = new Array();
		
		var pos = n.positionedOffset();

		if ($('submenu_' + n.id)) $('submenu_' + n.id).setStyle ({
			left : pos.left + 'px'
		});
	} ); 
	
	$$('.submenu').each( function (n) {						   
		target1 = n.id.replace('submenu_','');
		target2 = n.id.substring(0,n.id.lastIndexOf('_'));
		target3 = target1.substring(0,target1.indexOf('_'));
		target = $(target3) ? $(target3) : $(target1) ? $(target1) : $(target2);
		//alert(target.id + ' ' + n.id );
		n.observe('mouseover', response_in.bindAsEventListener( target ) );	
		n.observe('mouseout', response_out.bindAsEventListener( target ) );
	} );
	

	$$('.submenu_row').each ( function (n) { 
		n.observe ( 'mouseover', response_sub_in.bindAsEventListener( n ) ); 
		n.observe ( 'mouseout', response_sub_out.bindAsEventListener( n ) ); 
	} );
	
	$$('.subsubmenu').each( function (n) {							  
		n.observe('mouseover', show_sub.bindAsEventListener( n ) ); 
		n.observe('mouseout', hide_sub.bindAsEventListener( n ) ); 
		$('submenu_' + n.id).observe('mouseover', show_sub.bindAsEventListener( n ) ); 
		$('submenu_' + n.id).observe('mouseout', hide_sub.bindAsEventListener( n ) ); 
		stack[n.id] = new Array();
	});
	
	
	var myImage = new Image;

	myImage.src = "/img/button_rollover.png";


}

function response_in( event ) {
	
	
	this.addClassName('button_rollover');
	if ( this.readAttribute('selected') ) this.removeClassName('button_selected'); else this.removeClassName('button_selected');
	//if (!this.hasClassName('button_rollover')) this.toggleClassName('button_rollover'); 
	
	if ($('submenu_' + this.id)) {
		$('submenu_' + this.id).setStyle ({
			visibility : 'visible'
		});
	}
	
	this.setStyle ({
		backgroundImage : 'url(/img/button_rollover.png)',
		behavior : 'url("iepngfix.php")'
	});
	
	while (stack[this.id] && stack[this.id].length) clearTimeout(stack[this.id].pop());
	
	//obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/button_rollover.png', sizingMethod='scale')";										
	//obj.style.backgroundImage = "none";	
}

function response_out( event ) {
	if (this.id) stack[this.id].push ( setTimeout('delayed("'+this.id+'");',200) );
}

function delayed(obj) {
	if ($('submenu_' + obj)) 
		$('submenu_' + obj).setStyle ({
			visibility : 'hidden'
		});
	
	if ( $(obj).readAttribute('selected') ) $(obj).addClassName('button_selected'); else $(obj).addClassName('button');
	//$(obj).removeClassName('button_rollover');
	//if ($(obj).hasClassName('button_rollover')) $(obj).toggleClassName('button_rollover'); 
	
	if ( $(obj).hasClassName('button_selected') ) {
		$(obj).setStyle ({
			backgroundImage : 'url(/img/button_selected.png)',
			behavior : 'url("iepngfix.php")'
		});
	} else {
		$(obj).setStyle ({
			backgroundImage : 'url(/img/button_green.png)',
			behavior : 'url("iepngfix.php")'
		});
	}
}

function response_sub_in( event ) {
	
	this.addClassName('submenu_row_rollover');
	this.removeClassName('submenu_row');
	this.childElements().each ( 
		function (n) { 	
	   		n.setStyle ({
				backgroundImage : 'url(/img/dropdown_dark_background.png)',
				behavior : 'url("iepngfix.php")'
			});
		}
	);
	while (stack[this.id] && stack[this.id].length) clearTimeout(stack[this.id].pop());
}

function response_sub_out( event ) {
	if (!stack[this.id]) stack[this.id] = new Array();
	if (this.id) stack[this.id].push ( setTimeout('delayed_sub_out("'+this.id+'");',20) );
}

function delayed_sub_out ( objid ) {
	obj = $(objid);
	obj.addClassName('submenu_row');
	obj.removeClassName('submenu_row_rollover');
	obj.childElements().each ( 
		function (n) { 	
			n.setStyle ({
				backgroundImage : 'url(/img/dropdown_light_background.png)',
				behavior : 'url("iepngfix.php")'
			});
		}
	); 
}

function show_sub( event ) {
	
	if ($('submenu_' + this.id)) {
		var pos = this.cumulativeOffset();
		$('submenu_' + this.id).setStyle ({
			top : pos.top + 'px',
			left : ( pos.left + this.getWidth() + 20 ) + 'px',
			visibility : 'visible'
		});
	}

	while (stack[this.id] && stack[this.id].length) clearTimeout(stack[this.id].pop());
	
	//obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/button_rollover.png', sizingMethod='scale')";										
	//obj.style.backgroundImage = "none";	
}

function hide_sub ( event ) {
	if (this.id) stack[this.id].push ( setTimeout('delayed_sub("'+this.id+'");',500) );	
}

function delayed_sub(obj) {
	$('submenu_' + obj).setStyle ({
		visibility : 'hidden'
	});
}