/*
	drop down menu scripting by Charles Fahey, Best Pitch Multi Media (http://www.bestpitch.com)
	©2006 Best Pitch Multi Media
	Usage licensed to Collins & Jewel
*/

// browser test
var IE4 = (document.all && !document.getElementById)? true : false;
var W3C = (document.getElementById)? true : false;

// default 5 second life for drop down menu
var ddm_timeout = 5;

// set default seconds count for timer
var s=0;

// set timeout as variable which can be called to stop the execution of the timer (TimerLoop)
var x=setTimeout('TimerLoop()',1000);

/*
	make a layer disappear after a timed number of seconds
*/
function TimerLoop() {
	// increase seconds count
	s=s+1;
	// if display time has expired, hide menu
	if (s == ddm_timeout) { hide_menu();}
	// and reset variable
	x=setTimeout('TimerLoop()',1000);
}

/*
	stop a running timer
*/
function TimerStop() {
	// stop execution of timer
	clearTimeout(x);
	// reset seconds counter
	s=0;
}

/*
	make drop down menu appear on mouse over
*/
function show_menu() {
	// based on DOM, display layer
	(W3C||IE4)? document.getElementById('nav_menu').style.visibility="visible" : document.getElementById('nav_menu').visibility="show";
	// stop the timer (in case it was already running)
	TimerStop();
	// now begin timer again
	TimerLoop();
}

/*
	make drop down disappear on timer limit
*/
function hide_menu() {
	// based on DOM, hide layer
	(W3C||IE4)? document.getElementById('nav_menu').style.visibility="hidden" : document.getElementById('nav_menu').visibility="hide";
}

/*
	keep the layer displaying by resetting the timer
	called on mouseover of link in drop down menu
*/
function hold_layer() {
	// stop the timer
	TimerStop();
	// restart the timer
	TimerLoop();
}

/*
	reposition and repopulate drop down menu according to proper link
	hrefObj = the specific navigation link object
	menu_array_i = index of menu_array to use as link list (array created from coldfusion)
*/
function pos_pop_menu(hrefObj, menu_array_i) {
	
	// get the horizontal poition of the navigation link
	x_coord = findPos(hrefObj);
	
	// create menu string
	menu_string = "";
	
	// loop through sub array items
	for (i=0; i<menu_array[menu_array_i].length; i++) {
		// append menu string
		menu_string = menu_string + "<div class='" + ((menu_array[menu_array_i][i][2] == 0) ? "nav_link" : "nav_link_highlighted") + "'><a href='" + menu_array[menu_array_i][i][1] + "' onmouseover='javascript:hold_layer();'>" + menu_array[menu_array_i][i][0] + "</a></div>";
	}
	
	// insert new menu items into div
	document.getElementById('nav_menu').innerHTML = menu_string;
	
	// position div horizontally
	document.getElementById('nav_menu').style.left = x_coord + 'px';
	
	// display menu
	show_menu();
	
}

/* determine horizontal position of menu */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	//return [curleft,curtop];
	return curleft;
}