/*
	GRK 12/17/08
*/
// return an array of all IDs in the page
function returnAttributes(at){
	var arr=[];
	var elem=document.getElementsByTagName('*'), i=0, e;
		while(e=elem[i++]){
			e[at]?arr[arr.length]=e[at]:null;
		}
	return arr;
}
// return url variables
function GetParameters() {
var arg = new Object();
var href = document.location.href;
	if ( href.indexOf( "?") != -1) {
  var params = href.split( "?")[1];
  var param = params.split("&");
		for (var i = 0; i < param.length; ++i) {
			var name = param[i].split( "=")[0];
			name = name.toLowerCase(); // setting to lower so can be ref as lower whether incoming lower or upper
			var value = param[i].split( "=")[1];
				arg[name] = value;
		}
	}
	return arg;
}
var URL = GetParameters();
function loadPage () {
var allIds=returnAttributes('id'); // gets list of all ids in page
var thisID, altPName, ourID, ourLen=0;
var sPath = window.location.pathname; // gets full url; www.domain.com/pagename.cfm
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); // get pagename.cfm
var sPName = sPage.slice(0, sPage.indexOf('.')); // get pagename, no extension
	if(sPName == 'ViewAll') sPName = 'ViewAll-' + URL["cat"]; // give view all it's own id based on url.cat
	
	// hide all ids in the page for starters
	for(var i=0; i< allIds.length; i++) {
		if(allIds[i] != "searchForm")
		document.getElementById(allIds[i]).style.display = 'none'; // hide each id
	}
	// reopen selected id
	for(var i=0; i< allIds.length; i++) {
		thisID = allIds[i]; // current id in loop
		thisIDlen = thisID.split("_").length; // how long is this id?
		if(thisID.split("_")[thisIDlen-1] == sPName) {
			ourLen = thisIDlen; // how many levels deep?
			ourID = thisID; // the id that matches the loaded page
		}
	}
	switch(ourLen) { // there are no breaks, this allows for fall-through
		case 4:
			document.getElementById(ourID.split("_")[0] 
				+ "_" + ourID.split("_")[1] 
				+ "_" + ourID.split("_")[2]
				+ "_" + ourID.split("_")[3]).style.display = 'block';
		case 3:
			document.getElementById(ourID.split("_")[0] 
				+ "_" + ourID.split("_")[1] 
				+ "_" + ourID.split("_")[2]).style.display = 'block';
		case 2:
			document.getElementById(ourID.split("_")[0] 
				+ "_" + ourID.split("_")[1]).style.display = 'block';
		case 1:
			document.getElementById(ourID.split("_")[0]).style.display = 'block';
			var tmpParent = document.getElementById(ourID.split("_")[0]).parentNode; // get parent node for styling
			// *****************************************//
			// do styling on active area
			tmpParent.style.backgroundImage="url(/images/menudownbg.gif)";
			tmpParent.style.backgroundRepeat="no-repeat";
			//tmpParent.style.border = '1px solid black';
			//tmpParent.style.backgroundColor = 'yellow';
			// *****************************************//
	}
	for(var i=0; i< allIds.length; i++) {
		thisID = allIds[i]; // current id in loop
		thisIDlen = thisID.split("_").length; // how long is this id?
		if((ourID) && (thisID.match(ourID.split("_")[0] + "_" + ourID.split("_")[1]) && ourLen >=2)) {
			document.getElementById(thisID).style.display = 'block';
		}
	}
}