﻿var categoryToHide;
var hideTimer;
function InitialiseMenu()
{	
	$("td[category]").each
	(	
		function( intIndex )
		{			
			$(this).mouseover(	function()
							{
								this.className='highlight';
								DropDown($(this))
							}
						 );
			$(this).mousemove(	function()
							{
								if(categoryToHide==$(this).attr("category"))
								{
									clearTimeout(hideTimer);
									this.className='highlight';
								}
							}
						 );
			$(this).mouseout(	function()
							{
								this.className='';
								Hide($(this).attr("category"));
							}
						);			
		}
	);
	$(".divMenuItem").each
	(
        function (intIndex)
        {
            $(this).css("width", "100%");
            $(this).css("height", $(this).parent().innerHeight() + "px");
        }
    )
    $(".divMenuItem a").each
	(
        function (intIndex)
        {
            $(this).css("width", $(this).parent().innerWidth() + "px");
            var padding = ($(this).parent().innerHeight() - $(this).outerHeight()) / 2;
            $(this).css("padding-top", padding+ "px");
            $(this).css("padding-bottom", padding + "px");
        }
    )
		

	
	
}


function DropDown(parentTab)
{
	var categoryId = parentTab.attr("category");	
	if(categoryId>0)
	{
		var dropDown = $("#Level2-" + categoryId);
		
		if( (dropDown.length>0) && (categoryId != 250) )
		{
			
			var windowWidth = $(window).width();
			dropDown.css("top",(parentTab.offset().top+parentTab.height())+"px");
			
			var left = parentTab.offset().left+10;		
			var rightEdge = dropDown.width()+left;
			
			if (rightEdge>windowWidth)
			{
				left = left - (rightEdge - left - parentTab.width()) - 5;
				alert(left);
			}
			
			
			dropDown.css("left",left+"px");
			
			$("#Level2-"+categoryId).css("display","");
			
			
		}
	}
}


function Hide(categoryId,delayed)
{	
	if(delayed==null)
	{
		categoryToHide =categoryId;
		hideTimer = setTimeout('Hide('+categoryId+',true)',10);		
		return;
	}
	$("#Level2-"+categoryId).css("display","none");
}


$(	function() 
	{		
		InitialiseMenu();
	}
);
