﻿function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		nav_company_out = newImage("http://www.rhedpixel.com/images/navigation/nav_company-out.gif");
		nav_company_over = newImage("http://www.rhedpixel.com/images/navigation/nav_company-over.gif");
		nav_capabilities_over = newImage("http://www.rhedpixel.com/images/navigation/nav_capabilities-over.gif");
		nav_capabilities_out = newImage("http://www.rhedpixel.com/images/navigation/nav_capabilities-out.gif");
		nav_people_over = newImage("http://www.rhedpixel.com/images/navigation/nav_people-over.gif");
		nav_people_out = newImage("http://www.rhedpixel.com/images/navigation/nav_people-out.gif");
		nav_place_over = newImage("http://www.rhedpixel.com/images/navigation/nav_place-over.gif");
		nav_place_out = newImage("http://www.rhedpixel.com/images/navigation/nav_place-out.gif");
		nav_work_over = newImage("http://www.rhedpixel.com/images/navigation/nav_work-over.gif");
		nav_work_out = newImage("http://www.rhedpixel.com/images/navigation/nav_work-out.gif");
		nav_resources_over = newImage("http://www.rhedpixel.com/images/navigation/nav_resources-over.gif");
		nav_resources_out = newImage("http://www.rhedpixel.com/images/navigation/nav_resources-out.gif");
		preloadFlag = true;
	}
}

function winOpen(url){
	openSizedWindow(url,"350", "226");
	//popupwin=window.open(url,"popup","width=350,height=226,top=100,left=100,resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no");
}

function openSizedWindow(url, w, h) {
	popupwin=window.open(url,"popup","width="+w+",height="+h+",top=100,left=100,resizable=yes,scrollbars=no,menubar=no,toolbar=no,status=no,location=no");	
}


NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
W3C = (document.getElementById) ? 1 : 0; 

function hideLayer(id) {
	if (W3C) {
		document.getElementById(id).style.display = "none";
	} else if (NS4) {
		document.layers[id].display = "none";
	} else {
		document.all[id].style.display = "none";
	}
}

function showLayer(id) {
	if (W3C) {
		document.getElementById(id).style.display = "block";
	} else if (NS4) {
		document.layers[id].display = "block";
	} else {
		document.all[id].style.display = "block";
	}
}

/* Utilizing 1 function call to hide all handouts in side panel */

function hideHandouts(){
	hideLayer('handoutlist');
	hideLayer('nabpostplus');
	hideLayer('nab');
	hideLayer('dvexpo');
	hideLayer('photoshopworld');
	hideLayer('dmdc');
	hideLayer('MacLive');
	hideLayer('avid');
}


/*
setupMenu() applies the active CSS style (defined in rhedpixel.css) to the selected navigation and displays its submenu if it exists.
For submenus they must have the same name as their parent but with "_sub" at the end of the ID name.
In addition they must have the style "display" set to "none".


Example:
	<a href="portfolio.html" id="portfolio">Portfolio</a>    // Main Section
	<div id="portfolio_sub" style="display:none">			 // Sub Menu
		<a href="casestudies.html">Case Studies</a>			 // Sub Menu Item
		<a href="motioncontrol.html">Motion Control</a>		 // Sub Menu Item
	</div>
*/
		
		
		// get URL and substring from last forward slash to last period and use that to tell which menu(s) to highlight
		// if there's an underscore in the string need to find out which upper section it is.
		//			if there's no column add level 1 css
		//			if there is, parse, add level 1 and 2 css
		//	if page is index nothing is highlighted
/*  OLD  function setupMenu() {
	var URL = window.location.href;
	var page = URL.substring(URL.lastIndexOf("/")+1, URL.lastIndexOf("."));
	//alert("Page: " + page);
	if (page != "index") { // no highlighting on index pages
		var elem;
		var subelem;
		var subsection;
		
		if (page.indexOf("_") == -1) { // if this is a main section
			elem = document.getElementById(page);
			if (elem)
			{
				elem.className = "sidenav_level1_active";
				// check for subsection
				subsection = document.getElementById(page + "_sub");
				if (subsection) {
					subsection.style.display = "block";  // display subsection
				}
			}
		} else {
			// this is if we are in a subsection already, ie. portfolio_motioncontrol
			// need to highlight motioncontrol and portfolio (parent)
			
			var parentSection = page.substring(0,page.indexOf("_"));  // get parent section - ie., portfolio_motioncontrol  - we're getting portfolio
			//var childSection = page.substring(page.indexOf("_")+1);   // get child section - ie., portfolio_motioncontrol  - we're getting motioncontrol
		//	alert("Parent Section: " + parentSection);
			elem = document.getElementById(parentSection);
			if (elem) { elem.className = "sidenav_level1_active"; }
			
			subsection = document.getElementById(parentSection + "_sub");
			if (subsection) {
				subsection.style.display = "block";
				subelem = document.getElementById(page);
				if (subelem) {
					subelem.className = "sidenav_level2_active";  // highlight sub
				}
			}
		}
	}
}*/


function setupMenu() {
	var URL = window.location.href;
	var page = URL.substring(URL.lastIndexOf("/")+1, URL.lastIndexOf("."));
	//alert("Page: " + page);
	if (page != "index") { // no highlighting on index pages
		var elem;
		var subelem;
		var subsection;
		
		if (page.indexOf("_") == -1) { // if this is a main section
			elem = document.getElementById(page);
			if (elem)
			{
				elem.className = page + "_active";
				// check for subsection
				subsection = document.getElementById(page + "_sub");
				if (subsection) {
					subsection.style.display = "block";  // display subsection
				}
			}
		} else {
			// this is if we are in a subsection already, ie. portfolio_motioncontrol
			// need to highlight motioncontrol and portfolio (parent)
			
			var parentSection = page.substring(0,page.indexOf("_"));  // get parent section - ie., portfolio_motioncontrol  - we're getting portfolio
			//var childSection = page.substring(page.indexOf("_")+1);   // get child section - ie., portfolio_motioncontrol  - we're getting motioncontrol
			elem = document.getElementById(parentSection);
			if (elem) { elem.className = parentSection + "_active"; } //"sidenav_level1_active"; }
			
			subsection = document.getElementById(parentSection + "_sub");
			if (subsection) {
				subsection.style.display = "block";

				var temp = page.substring(0, page.lastIndexOf("_"));
				if (temp.indexOf("_") != -1) {  // we're at 3rd level portfolio - ie, portfolio_government_fcc, need to get portfolio_government
					page = temp;
				}
				
				subelem = document.getElementById(page);
				if (subelem) {
					subelem.className = "sidenav_level2_active";  // highlight sub
				}
			}
		}
	}
}

	/*if (section != "") {
		if (state == 'block') {
			state = 'none';
		}
		else {
			state = 'block';
		}

		if (document.all) { //IS IE 4 or 5 (or 6 beta)
			eval( "document.all." + layer_ref + ".style.visibility = state");
		}

		if (document.layers) { //IS NETSCAPE 4 or below
			document.layers[layer_ref].visibility = state;
		}

		if (document.getElementById && !document.all) {
			document.getElementById(layer_ref).style.visibility = state;
		}
	}*/

function init(){
	setupMenu();
	preloadImages();
}

window.onload = init;