var url,index,active,check;

$(document).ready(function() {
	//Main Navigation Dropdown
	$("#mainTabs a.drop").bind("mouseenter",function(){
		url = this.href;
		for(var i=0;i<$("#mainTabs a").length;i++){
			if($("#mainTabs li:eq("+i+") ul")[0]){
				if($("#mainTabs li:eq("+i+") a.drop")[0].innerHTML == this.innerHTML){
					var theid = "health";
					if(this.className.match("productivity")){
						theid="productivity";
					}
					if(this.className.match("employee")){
						theid="employee";
					}
					index = i;
				}
			}
		}
		var top = "<li class='headItem'><a href='"+this.href+"'>"+this.innerHTML+"</a></li>";
		
		makeDropDown("#mainTabs li:eq("+index+") ul","#mainContent",theid,top);
		this.className += " ddActive";
		return false;	
	});
	
	//Change Category Dropdown
	$("#globalNav #category a").bind("mouseenter",function(){
		var top = "<li class='invLink'><a href='"+this.href+"'>"+this.innerHTML+"</a></li>";
		makeDropDown("#globalNav #category ul","#mainContent","Category",top);
		this.className += " ddActive";
		return false;	
	});
	
	//Tools Dropdown
	$("#globalNav #tools a").bind("mouseenter",function(){	
		var top = "<li class='invLink'><a href='"+this.href+"'>"+this.innerHTML+"</a></li>";
		makeDropDown("#globalNav #tools ul","#mainContent","Tools",top);	
		this.className += " ddActive";
		return false;	
	});
});

function checkHover()
{
	if(check == false){
		$(".ddBox").remove();
		$("*").removeClass("ddActive");
	}
}

function makeDropDown(conSel,container,theid,topItems)
{	
	var contentItems = "";
	contentItems = $(conSel)[0].innerHTML;
	
	//-------------------------------- Create The Dropdown
	$(container).append("<div id='dd"+theid+"' class='ddBox' style='display:none;'><ul>"+topItems+contentItems+"</ul></div>");	
	$(".ddBox").slideDown(200).fadeIn(300);
	check = false;
	var me=setTimeout("checkHover()",800);

		//------------------
		$(".ddBox").bind("mouseleave",function(){
			$(".ddBox").remove();
			$("*").removeClass("ddActive");
		});
		$(".ddBox").bind("mouseover",function(){
			check = true;										
		});
		//------------------
}
