$(document).ready(function() {
	
	var currentItem = '';
	var defaultState = 'item2';
	
	$("#item2,#item4,#item5, #item7, #item6,#item8").bind('mouseenter mouseleave',function(event){
		if(event.type == 'mouseenter'){
			$(this).css("background",  "url(images/nav_rollover.jpg)");
			showSub(this);
		}else{
			$(this).css("background",  "none");
		}
	});
	
	$("#item1,#item3, #item10").bind('mouseenter mouseleave',function(event){
		if(event.type == 'mouseenter'){
			$("#" + currentItem + "subnav").stop().animate({top:"0"}, {queue:false, duration:60 })
			$(this).css("background-image",  "url(images/nav_rollover.jpg)");
			$("#" + currentItem + "").css("background-image",  "none");
		}else{
			if(defaultState!=''){
			setDefaultState();
		}
			$(this).css("background-image",  "none");
		}
	});
	
	$("#item2subnav, #item4subnav, #item5subnav, #item6subnav, #item7subnav, #item8subnav").bind('mouseenter mouseleave',function(event){
		var subnavElement =  $(this).attr('id');
		var parentElement = subnavElement.substr(0, subnavElement.length-6);
		
		if(event.type == 'mouseenter'){
			$("#" + parentElement + " a").css("background-image",  "url(images/nav_rollover.jpg)");
		}else{
			$("#" + parentElement + " a").css("background-image",  "none");
			hideSub();	
		}
	});
	
	
	$("#off, #logo, #endcap").mouseenter(function(){
		hideSub();	
	})
	
	
	function showSub(target){
		if(target.id != currentItem){ 
			hideSub(); 
			currentItem = target.id;	
		}
		
		if(defaultState!=''){
			$("#" + defaultState + "").css("background-image",  "none");
			$("#" + defaultState + "subnav").stop().animate({top:"0"}, {queue:false, duration:60 })
		}
		$("#" + currentItem + "subnav").stop().animate({top:"48"}, {queue:false, duration:120 })
	}
	
	
	function hideSub(){
		$("#" + currentItem + "subnav").stop().animate({top:"0"}, {queue:false, duration:60 })
		if(defaultState!=''){
			setDefaultState();
		}	
	}
	
	
	function setDefaultState(){
		if(defaultState!=''){
		$("#" + defaultState + "subnav").stop().animate({top:"48"}, {queue:false, duration:120 })
		$("#" + defaultState + "").css("background-image",  "url(images/nav_rollover.jpg)");
		currentItem = defaultState;
		}
	}
	
	setDefaultState();
	
});	


