var gapComp=60; // Sets the gap between the dropdowns and the submenus.  Typically the CSS horizontal padding 
var vertComp=0; // Sets the gap between the bottom of the triggering row and the dropdowns
var horizComp=0; // Sets the horizontal distance between the triggering row elements and the left positioning of the dropdowns
var subVertOffset=-1; // Any additional vertical compensation needed for the submenus
var dropdownWidth=180; // Width of dropdown, in pixels
var submenuWidth=150; // Width of submenus, in pixels
var overMenu=false;
var overButton=false;
var dropOpen=-1;
var lastSub=-1;
$(document).ready(function(){
	$(".dropdown").css({"position" : "absolute", "z-index" : "100"}).mouseover(function(){
		flagOver();
		var dropIndex=parseInt(this.id.substr(4));
		MM_swapImage('topmenu_r2_c'+(dropIndex+1),'','images/topmenu_r2_c'+(dropIndex+1)+'_f2.gif',1);
	});
	$(".dropsub").css({"position" : "absolute", "z-index" : "110"}).mouseover(function(){
		flagOver();
		$(".dropdown a").removeClass("dropdownOver");
		$("#trigger"+this.id.substr(3)).addClass("dropdownOver");
	});
	$(".dropdown").mouseout(flagOut);
	$("#menuRow a").mouseover(function(){
		var index=parseInt(this.id.substr(6));
		lastSub=-1;
		if(index!=dropOpen){
			clearMenus(true);
			MM_swapImage('topmenu_r2_c'+(index+1),'','images/topmenu_r2_c'+(index+1)+'_f2.gif',1);
			$("#drop"+index).css({"top" : $(this).offset().top+$(this).height()+vertComp+"px", "left" : ($(this).offset().left-$("#container").offset().left)+horizComp+"px"}).slideDown("fast", function(){
				dropOpen=index;
			});
		} else {
			flagOver();
			clearSubs();
		}
	});
	$("#menuRow a").mouseout(function(){
		if(!document.getElementById("drop"+this.id.substr(6))){
			MM_swapImgRestore();
		}
		flagOut();
		clearMenus(false);
	});
	$(".dropdown a").mouseover(function(){
		var index=parseInt(this.id.substr(7));
		var allowVertOffset=index>0 ? 1 : 0;
		showSub(index, $(this).offset().top+(subVertOffset*allowVertOffset), (($(this).offset().left-$("#container").offset().left)+$(this).width()));
		$(".dropdown a").removeClass("dropdownOver");
		$(this).addClass("dropdownOver");
	});
	$(".dropsub a").css({"width" : submenuWidth+"px"}).mouseover(function(){
		$(this).addClass("dropdownOver");
	});
	$(".dropdown a, .dropsub a").css({"display" : "block"}).mouseout(function(){
		$(this).removeClass("dropdownOver");
	});
	$(".dropsub").mouseout(flagOut);
	$(".dropdown a, .dropsub a").click(function(){
		this.blur();
	});
});
function clearMenus(rightNow){
	overButton=rightNow;
	if(rightNow){
		deleteMenus(false);
	} else {
		setTimeout("deleteMenus(true)", 500);
	}
}
function deleteMenus(checkFirst){
	if((!checkFirst) || (!overMenu && !overButton)){
		clearSubs();
		$(".dropdown").slideUp("fast", function(){
			dropOpen=-1;
			$(".dropdown a").removeClass("dropdownOver");
		});
		MM_swapImgRestore();
		overMenu=false;
	}
}
function clearSubs(){
	$(".dropsub").hide("fast");
}
function showSub(index, posT, posL){
	if(index!=lastSub){
		clearSubs();
		$("#sub"+index).css({"top" : posT+"px", "left" : posL+gapComp+"px"}).show("normal");
		lastSub=index;
	}
}
function flagOver(){
	overMenu=true;
}
function flagOut(){
	overMenu=false;
	clearMenus(false);
}