/* GRK 5/09 mod from birch  */
/*
	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
var protectIDs = "_yui_eu_dr,Wrapper,WrapperOpen,Image1,Image2,Search,keywordautosuggest,keyword,keywordloadingicon,keyword_cf_button,keywordcontainer,vdividermenu"; // add ids here to not be hidden by process
	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(!protectIDs.match(allIds[i]))
		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';
			var tmpParent3 = document.getElementById(ourID.split("_")[0] 
				+ "_" + ourID.split("_")[1] 
				+ "_" + ourID.split("_")[2]).parentNode; // get parent node for styling
			//tmpParent3.style.backgroundImage="url(/Images/buttons/arrow-up.jpg)";
			//tmpParent3.style.backgroundRepeat="no-repeat";
		case 2:
			document.getElementById(ourID.split("_")[0] 
				+ "_" + ourID.split("_")[1]).style.display = 'block';
			var tmpParent2 = document.getElementById(ourID.split("_")[0] 
				+ "_" + ourID.split("_")[1]).parentNode; // get parent node for styling
			if(!tmpParent2.className.match("no-sub")) {
				tmpParent2.style.backgroundImage="url(/Images/buttons/arrow-up.jpg)";
				tmpParent2.style.backgroundRepeat="no-repeat";
			}
		case 1:
			document.getElementById(ourID.split("_")[0]).style.display = 'block';
			var tmpParent1 = document.getElementById(ourID.split("_")[0]).parentNode; // get parent node for styling
			// *****************************************//
			// do styling on active area
			if(!tmpParent1.className.match("no-sub")) {
				tmpParent1.style.backgroundImage="url(/Images/buttons/arrow-up.jpg)";
				tmpParent1.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';
		}
	}
}