$(document).ready(function() {
	Init();
});
/************************************************
 global variables
************************************************/
var currItem = "";
var timer = 3;
var t = 0;
/************************************************
 methods
************************************************/
//initialize menu
function Init(){
	//position sub menu for ie
	var offset = $(".menu-header").offset();
	var left = offset.left;
	var top = 23 + offset.top;
	$(".menu-sub").css({"left":left,"top":top});
	
	//bind events
	$(".menu-header").bind("mouseenter",MenuHeader_RollOverEvent);
	$(".menu-header").bind("mouseleave",MenuHeader_RollOffEvent);
}
//set timer to count down till we hide the menu
function CheckStatus(){
	//prevent interval from bubbling up
	clearTimeout(t);
	
	if(timer == 0){
		timer = 3;					
		$(".menu-sub").fadeOut("slow");
	}else{
		timer--;
		t = setTimeout("CheckStatus()",700);
	}
}
/************************************************
 event handlers
************************************************/
function MenuHeader_RollOverEvent(event){
	//reset the timer
	timer = 3; 
	
	//we don't want the timer to be counting down while rolled over the sub menu
	clearTimeout(t);				
	
	//prevent items from bubbling up
	event.stopPropagation();
	
	//position sub menu for ie
	var offset = $(".menu-header").offset();
	var left = offset.left;
	var top = 23 + offset.top;
	$(".menu-sub").css({"left":left,"top":top});
	
	//show sub menu
	$(".menu-sub").fadeIn("slow");
	
	//when we roll over the links we want to keep the sub menu showing
	$(".menu-sub > li > a").bind("mouseenter",MenuSub_RollOverEvent);
	$(".menu-sub > li > a").bind("mouseleave",MenuHeader_RollOffEvent);
}
function MenuSub_RollOverEvent(event){
	//reset the timer
	timer = 3; 
	
	//we don't want the timer to be counting down while rolled over the sub menu
	clearTimeout(t);
	
	//prevent items from bubbling up
	event.stopPropagation();
}
function MenuHeader_RollOffEvent(event){
	//start the timer for hiding the menu bar
	CheckStatus();
}
//launch a popup window in center screen
function launchWindow(url, name, width, height){
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width + ", scrollbars=yes";
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}
	return window.open(url, name, str);
}