/*
Additional attributes:
voffset
hoffset
*/

var dropdown_iTimeout = 700;
var dropdown_xOffset = 0;
var dropdown_yOffset = 12;
//var dropdown_bGrowWidth = true;	// if submenu's width is smaller than mainmenu item, it grows to its width
var dropdown_pTimeout;
var dropdown_bHover = false;
var dropdown_arrContainers = ['#DropDownMenu', '#DropDownTopMenu'];


$(document).ready(function() {
	for(i=0; i < dropdown_arrContainers.length; i++) {
		
		$(dropdown_arrContainers[i]).find('a').hover(
			function() {
				if($(this)[0].getAttribute("dropdown") == undefined) { return(false); }
				dropdown_bHover = true;
				clearTimeout(dropdown_pTimeout);
	
				// Hide open dropdowns
				for(d=0; d<dropdown_arrContainers.length; d++) {
					$(dropdown_arrContainers[d]).find('A:not([@dropdown="' + $(this)[0].getAttribute("dropdown") + '"])').each(
						function() {
							if($(this)[0].getAttribute("dropdown") != undefined) { $('#' + $(this)[0].getAttribute("dropdown")).hide(); }
						}
					)
				}
			
				// Positions dropdown			
				var sIdDropdown = '#' + $(this)[0].getAttribute("dropdown");
				var offset = $(this).offset();
				
				var voffset = 0;
				var hoffset = 0;

				try
				{
					if($(sIdDropdown)[0].getAttribute("voffset")) { voffset = Number($(sIdDropdown)[0].getAttribute("voffset")); }
					if($(sIdDropdown)[0].getAttribute("hoffset")) { hoffset = Number($(sIdDropdown)[0].getAttribute("hoffset")); }
		
					$(sIdDropdown)[0].style.left = (offset.left + hoffset + dropdown_xOffset) + 'px';
					$(sIdDropdown)[0].style.top = (offset.top + $(this).height() + voffset + dropdown_yOffset) + 'px';
	
					// Displays dropdown
					$(sIdDropdown).show();
		
					// Dropdown element envent handlers
					$(sIdDropdown).hover(
						function() {
							clearTimeout(dropdown_pTimeout);
						},
						function() {
							clearTimeout(dropdown_pTimeout);
							dropdown_pTimeout = setTimeout("dropdown_mouseOut('" + sIdDropdown + "')", dropdown_iTimeout);					
						}
					)
				}
				catch(err) {} 

			},
			function() {
				$('#DebugDiv').html('MouseOUT: '+$(this).attr('id'));
				if($(this)[0].getAttribute("dropdown") == undefined) { return(false); }
				dropdown_bHover = false;
				var sIdDropdown = '#' + $(this)[0].getAttribute("dropdown");
				clearTimeout(dropdown_pTimeout);
				dropdown_pTimeout = setTimeout("dropdown_mouseOut('" + sIdDropdown + "')", dropdown_iTimeout);
			}
		);
	}	//end for

});


function dropdown_mouseOut(sIdDropdown) {
	if(dropdown_bHover == false) { $(sIdDropdown).hide(); }
}