salmon.namespace.addNamespace("boots.navigation");
boots.navigation = {
	currentWidth:0,
	currentHeight:0,
	currentTop:0,
	currentLeft:0,
	mouseoverCategory:false,
	mouseoverMenu:false,
	isIe6:$.browser.msie,
	init: function() {
			$("ul.jd_menu ul").prepend("<li class=\"top\"><span></span></li>");
			$("ul.jd_menu li.top").each(function(){
				$(this).find("span").css({
					width:$(this).parent().parent().find("a:first").width()+"px"
				});
			});
			if(this.isIe6){
			this.isIe6 = (parseInt($.browser.version)<=6);
		}
		if(this.isIe6){
			$("body").append("<iframe id=\"dropDownBoxIframe\" src=\"/wcsstore/ConsumerDirectStorefrontAssetStore/en_US/i/blank.htm\" scrolling=\"no\" frameborder=\"no\"></iframe>");
			$("#dropDownBoxIframe").css({
				height:"1px",
				position:"absolute",
				top:"0px",
				left:"0px",	
				width:"174px",
				filter:"alpha(opacity=0)"
			});
		}
		$("body").append("<div id=\"dropDownBox\"></div>");
		$("#dropDownBox").css({
			textAlign:"left",
			position:"absolute",
			top:0,
			left:0,
			width:"174px",
			zIndex:"9999"
		});
		$("ul.jd_menu > li > a").mouseover(function(){
			boots.navigation.mouseoverCategory = true;
			boots.navigation.currentWidth = $(this).width();
			boots.navigation.currentHeight = $(this).height();
			boots.navigation.currentTop = $(this).offset().top;
			boots.navigation.currentLeft = $(this).offset().left;
			if(boots.navigation.isIe6){
				$("#dropDownBoxIframe").css({
					top:(parseInt(boots.navigation.currentTop)+parseInt(boots.navigation.currentHeight))+"px",
					left:boots.navigation.currentLeft+"px"
				});
			}
			
			$("#dropDownBox").css({
				top:(parseInt(boots.navigation.currentTop)+parseInt(boots.navigation.currentHeight))+"px",
				left:boots.navigation.currentLeft+"px"
			}).empty();
	
			$(this).parent().find("ul").clone().appendTo("#dropDownBox");
			$("#dropDownBox ul").css({display:"block"});
			
			if(boots.navigation.isIe6){
				$("#dropDownBoxIframe").css({
					height:parseInt($("#dropDownBox").height())+"px"
				});
			}
		});
	
		$("ul.jd_menu > li > a").mouseout(function(){
			boots.navigation.mouseoverCategory = false;
			window.setTimeout(boots.navigation.showMenu,500);
		});
		$("#dropDownBox").mouseover(function(){
			boots.navigation.mouseoverMenu = true;
		});
		$("#dropDownBox").mouseout(function(){
			boots.navigation.mouseoverMenu = false;
			window.setTimeout(boots.navigation.showMenu,500);
		});
	
	},
	
	showMenu:function (){
		if(!boots.navigation.mouseoverCategory){
			if(!boots.navigation.mouseoverMenu){
				if(boots.navigation.isIe6){
					$("#dropDownBoxIframe").css({
						height:"1px",
						top:0,
						left:0
					});
				}
				$("#dropDownBox").css({
					height:"1px",
					top:0,
					left:0
				}).empty();
			}
		}
	}
	
};

$(document).ready(function(){boots.navigation.init();});
