// JavaScript Document for dropdown menus
//The following code was written by Tait Chambers of WebDuck Designs 2008

var timeOut = 350;
var closeTimer = 0;
var navMenu = 0;
var navBtn = 0;
var topNavBtns = new Array('home','aboutus','signpetition','donatebtn','getinvolved','membersonly','contactus');
//function to find the top of the element or Y Value
function findTop(nav){
	var obj = document.getElementById(nav);
	var objTop = document.getElementById(nav).offsetTop;	
	//determine the most root of the element
	if(obj.offsetParent){
		//The element is not the root.	
		while(obj.offsetParent){
			objTop += obj.offsetParent.offsetTop;
			if(obj.nodeName == 'BODY'){
				break;
			}else{
				obj = obj.offsetParent;
			}
		}
	}
	return objTop;
}
//function to find the left of the element or X value
function findLeft(nav){	
	var obj = document.getElementById(nav);
	var objLeft = document.getElementById(nav).offsetLeft;
	//determine the most root of the element
	if(obj.offsetParent){
		//The element is not the root.	
		while(obj.offsetParent){
			objLeft += obj.offsetParent.offsetLeft;
			if(obj.nodeName == 'BODY'){
				break;
			}else{
				obj = obj.offsetParent;
			}
		}
	}
	return objLeft;		
}
//function for creating a menut
function openMenu(menu,btn){
	//cancel the sub menu closing 
	cancelMenuTimer();
	if(btn != navBtn){
		var menuLoc = document.getElementById(menu);
		var menuBtn = document.getElementById(btn+"_link");
		//set the global variables for the timer
		navMenu = menu;
		navBtn = btn;
		//determine the top value
		var top = findTop(menu);
		var left = findLeft(menu);
		//loop through and make sure all buttons are in mouseout state except chosen btn
		changeBtnState(menu);
		//find the stats for the menu then open the sub menu
		getNavContent(menu,btn);
		var stats = findStats_topMenu(menu,top,left);
		var subNav = document.getElementById('top_menu_container');
		//get links for the sub navigation based on the btn variable
		subNav.style.top = stats['Top']+"px";
		subNav.style.left = stats['Left']+"px";
		subNav.style.width = stats['Width']+"px";
		subNav.style.visibility = "visible";
		menuBtn.style.backgroundColor = "#7ab7dd";
		menuBtn.style.backgroundImage = "url("+siteRoot+"images/nav_images/bluearrow02.jpg)";
		menuBtn.style.border = "solid 1px #2589c8";
	}
}
//function to determine the location of the menu start or top left corner 
//for top nav menu
function findStats_topMenu(menu,top,left){
	var menu = document.getElementById(menu);
	var height = menu.offsetHeight;
	var width = menu.offsetWidth;
	var loc = new Array();
	loc['Top'] = (top+height) - 1;
	loc['Left'] = left;
	loc['Width'] = width - 15;
	return loc;
}
//function for closing the sub menu on mouseout
function closeMenu(){
	if(document.getElementById('top_menu_container')){
		var menu = document.getElementById('top_menu_container');
		if(document.getElementById(navBtn+"_link")){
			var menuBtn = document.getElementById(navBtn+"_link");
			menu.style.visibility = "hidden";
			menuBtn.style.backgroundColor = "#2589c8";
			menuBtn.style.backgroundImage = "url("+siteRoot+"images/nav_images/bluearrow01.jpg)";
			menuBtn.style.border = "none";
		}
	}
	navMenu = null;
	navBtn = null;
}
//function to start the close timer
function menuCloseTimer(){
	closeTimer = setTimeout("closeMenu()",timeOut);
}
//function for changing button states when swtiching to another button
function changeBtnState(menu){
	for(i=0; i<topNavBtns.length; i++){
		if(topNavBtns[i] != navBtn){
			if(document.getElementById(topNavBtns[i]+"_link")){
				menuBtn = document.getElementById(topNavBtns[i]+"_link");
				menuBtn.style.backgroundColor = "#2589c8";
				menuBtn.style.backgroundImage = "url("+siteRoot+"images/nav_images/bluearrow01.jpg)";
				menuBtn.style.border = "none";
			}
		}
	}
}
//function to cancel the close timer
function cancelMenuTimer(){
	if(closeTimer)
	{
		window.clearTimeout(closeTimer);
		closeTimer = null;
	}
}


