//dhtml menu_______________________________________________


var runOnce = 0;
function initMenu(c) { //first called from HTML to initialize menu
	//alert("initMenu="+c);

	var browserWidth = document.documentElement.clientWidth; //ff or ie
	var browserHeight = document.documentElement.clientHeight; //ff or ie
	var scrollWidth = document.documentElement.scrollWidth;
	var scrollHeight = document.documentElement.scrollHeight;
	var offsetWidth = document.documentElement.offsetWidth;
	var offsetHeight = document.documentElement.offsetHeight;
	
	//run once
	if (!runOnce && !c) {
		//alert("running once");

		//btn 
		btnFileName_arr = new Array();
		btnFileName_arr[1] = "nav-clients";
		btnFileName_arr[2] = "nav-services";
		btnFileName_arr[3] = "nav-fees";
		btnFileName_arr[4] = "nav-candidates";
		btnFileName_arr[5] = "nav-contact";
		
		//create dropDown_collapse_hitArea
		var newDiv = document.createElement('div');
		newDiv.setAttribute('id',"dropDown_collapse_hitArea");
		if (document.body) {
			document.body.appendChild(newDiv);
			document.getElementById("dropDown_collapse_hitArea").onmouseover = hideAllDivs;
			document.getElementById("dropDown_collapse_hitArea").style.position = "absolute";
			document.getElementById("dropDown_collapse_hitArea").style.zIndex = "90"; //below hiddenMenu & navHead
			//document.getElementById("dropDown_collapse_hitArea").style.backgroundColor = "#00ff00"; //only for debuggin
		}

		//services page stuff
		hideAllServicesItems();
		showServicesItem(1,true);

		runOnce = 1;
	}
	hideAllDivs();
	
	//position hiddenMenu
	if (browserWidth > 946) {
		var pos = (browserWidth - 946) / 2;
	} else {
		var pos = 0;
	}
	pos = Math.floor(pos);
	if ( document.getElementById("dropDown_collapse_hitArea") ) {
		//(re)position dropDown_collapse_hitArea
		document.getElementById("dropDown_collapse_hitArea").style.top = "0px";
		document.getElementById("dropDown_collapse_hitArea").style.left = "0px";
		document.getElementById("dropDown_collapse_hitArea").style.width = scrollWidth+"px";
		document.getElementById("dropDown_collapse_hitArea").style.height = browserHeight+"px"; //cuz scrollHeight doesn't work in Safari
		document.getElementById("dropDown_collapse_hitArea").style.backgroundImage = "url(images/blank.gif)"; //need invisible gif bg for IE
	
		//to fix ie 7 empty invisible div onmouseover problem, add invisible gif inside the div:
		//document.getElementById("dropDown_collapse_hitArea").innerHTML=" <img width="+ scrollWidth +" height="+ browserHeight +" src=\"images/blank.gif\"> ";
	}
}
if (runOnce) {
	window.onresize = initMenu(1);
	window.onscroll = initMenu(2);
}

function hideDiv(id) {
	var id = "dropDown_"+id;
	if (document.getElementById) {
		document.getElementById(id).style.display = 'none';
	}
}

function showDiv(TARGET) {
	hideAllDivs();
	var id = 0;

	//swap drop down btn
	id = "btn_"+TARGET;
	if (document.getElementById(id)) {
		//alert("x="+id);
		document.getElementById(id).src = "images/nav/"+btnFileName_arr[TARGET]+"_b.gif";
	}

	//drop down
	id = "dropDown_"+TARGET;
	if (document.getElementById(id)) {
		//alert("x="+id);
		document.getElementById(id).style.display = 'block';
	}

	//drop down bg
	id = "dropDown_bg_"+TARGET;
	if (document.getElementById(id)) {
		//alert("x="+id);
		document.getElementById(id).style.display = 'block';
	}

	if (document.getElementById("dropDown_collapse_hitArea")) {
		document.getElementById("dropDown_collapse_hitArea").style.display = "block"; //show collapse_hitArea
		//alert("showDiv complete");
	}
}

function hideAllDivs() {
	//alert("hidealldivs");
	var i = 0;
	var id = 0;

	//swap all drop down btn to OFF
	for (i=1;i<6;i++) {
		id = "btn_"+i;
		if (document.getElementById(id)) {
			//alert("x="+id);
			document.getElementById(id).src = "images/nav/"+btnFileName_arr[i]+".gif";
		}
	}

	//drop downs
	for (i=1;i<6;i++) {
		id = "dropDown_"+i;
		//alert(id);
		if (document.getElementById(id)) {
			document.getElementById(id).style.display = "none";
		}
		//alert(i);
	}

	//drop down bgs
	for (i=1;i<6;i++) {
		id = "dropDown_bg_"+i;
		//alert(id);
		if (document.getElementById(id)) {
			document.getElementById(id).style.display = "none";
		}
		//alert(i);
	}

	if (document.getElementById("dropDown_collapse_hitArea")) {
		document.getElementById("dropDown_collapse_hitArea").style.display = "none"; //hide collapse_hitArea
	}


}

//services page drop down functions
//===========================================================
function hideAllServicesItems() {
	//alert("hideAllServicesItems");
	var i = 0;
	var id = 0;
	for (i=1;i<30;i++) {
		id = "services_item_"+i;
		if (document.getElementById(id)) {
			document.getElementById(id).style.display = "none";
		}
	}
}
function showServicesItem(id,fromRunOnce) {
	//alert("showServicesItem");
	hideAllServicesItems();
	var id = "services_item_"+id;

	//if URL has showItem=?id, then go to that one by default. but only do this
	if (fromRunOnce) {
		//get parameter from query string
		var param = gup( 'showItemID' );
		if (param) {
			id = param;
		}
	}

	//show item
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'block';
	}

	//not on services.html page? then go to it
	if (!fromRunOnce) {
		//window.location="http://www.w3schools.com" 
		//alert(location.pathname);
	
		//search pathname for "services.html"
		var str = location.pathname;
		var searchStr = "services.html";
		var onSearchPage = false;
		if ( str.indexOf(searchStr) > -1) {
			//alert("on services page");
			onSearchPage = true;
		}
		if (!onSearchPage) {
			//alert("going to search page");
			document.location.href="services.html?showItemID="+id;
		}
	}
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
