// Menu Navigation and Div hiding
var menuItems = new Object;
var menuStatus = new Object;
var hovering = false;
var hoveringTop = false;



function initNavigation(){
	var topAS = $("#menuTop  a[header='']");
	var topASnormal = $("#menuTop  a[header!='']");
	var subDIVs = $("#subMenus .menuBottom a");

	$("#subMenus div:not(.default):not(#editionDrop)").hide();

	checkTop();
	
	topASnormal.hover(resetTopHover);
	topAS.hover(manageTop, checkTopOut);
	subDIVs.hover(manageSub, manageSubOut);
	
}


function resetTopHover(){
	
	if($(".default").length != 1){
		$(".topSelected").removeClass("topSelected");
	}
	
	hoveringTop = false;
}

function manageTop(){
	
	//alert(getTarget(this));
	hoveringTop = true;
	var subID = $(this).attr("sub");
	if($("#subMenus").is(":hidden")){
		$("#subMenus").slideToggle();
	}
	$(".topSelected").removeClass("topSelected");
	$(this).addClass("topSelected");
	$("#subMenus div:visible").hide();
	$(subID).show();
}


function manageSub(){
	thisParent = $(this).attr("thisParent");
	//$(thisParent).addClass("active");
	hovering = true;
	hoveringTop = false;
}

function manageSubOut(){
	thisParent = $(this).attr("thisParent");
	
	hovering = false;
	
	if($(thisParent).hasClass("default")){return;}
	
	
	
}

function checkTop(){
	if($("#subMenus").is(":hidden") && $(".default").length > 0){
		$("#subMenus").show();
	}
}


function checkTopOut(){
	

		if (hoveringTop) {return; }
		
	
	
}

function checkMenu() {
	m = $("#subMenus");
	v = $(".menuBottom:visible");
	d = $(".default");
	dID = "#" + d.attr("id");
	
	//alert($([sub=dID]).length);
	
	
	//alert(dID);
	if (hovering || hoveringTop || dropHover) {return;}
	else{
		
		if (d.length==1) {
			if (d.attr("id") == v.attr("id")) {
				return;
			}
			else {
				m.slideUp(function(){
					$(".topSelected").removeClass("topSelected");
					$("[sub="+ dID+ "]").addClass("topSelected");
					v.hide();
					d.show();
					m.slideDown();	
				});
				
			}
		}
		else {
			if($(".default").length != 1){
				$(".topSelected").removeClass("topSelected");
			}
			m.slideUp();	
		}
	}
}


$(document).ready(function() {
	// Stuff to do as soon as the DOM is ready;

	initNavigation();
	
	
	var currentPage = $("#pageID").attr("rel");

	
	
		
	window.setInterval(checkMenu, 3000);
	
	
	
	

	
	
});


