//Api for mears site
//Global
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;
var currNav;

function initAPI(){
	if(document.images){
		isCSS = (document.body && document.body.style) ? true : false;
		isW3C = (isCSS && document.getElementById) ? true : false;
		isIE4 = (isCSS && document.all) ? true : false;
		isNN4 = (document.layers) ? true : false
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	}
}
function initPage(){
	initAPI();
	CheckNav();
	soopaPopSetup();
}
//set event handler
window.onload = initPage;

function seekLayer(doc,name){
	var theObj;
	for (var i =0; i< doc.layers.length; i++){
	if(doc.layers[i].name == name){
	theObj = doc.layers[i];
	break;
	}
//Dive into nested layers if necessary
if (doc.layers[i].document.layers.length > 0){
		theObj =  seekLayer(document.layers[i].document, name);
		}
	}
	return theObj;
}
	
// Convert object name string or object reference
// into a valid element object reference

function getRawObject(obj){
	var theObj;
	if(typeof obj == "string") {
		if(isW3C){
				theObj = document.getElementById(obj);
			} else if (isIE4) {
				theObj = document.all(obj);
			} else if (isNN4) {
				theObj = seekLayer(document, obj);
			}
		} else {
			//pass through object reference
			theObj = obj;
		}
			return theObj;
	}
	
//Convert object name string or object reference
//into a valid style (orNN4 layer) reference
function getObject(obj){
	var theObj = getRawObject(obj);
	if(theObj && isCSS) {
	theObj = theObj.style;
	}
	return theObj;
}
	
//Set the visibily to visible
function SwapLayers(obj){
	var theObj = getObject(obj);
	if(theObj) {
		if(theObj.display == "none")
			theObj.display = "";
		else
			theObj.display = "none";
	}
}

function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//Preload the nav and utility images
if(document.images){
	var imgLoc = "../images/nav/";
	//create 'on' array and populate with images
	var onImgArray = new Array();
	onImgArray["homeMenuButt"] = new Image();
	onImgArray["aboutMenuButt"] = new Image();
	onImgArray["approachMenuButt"] = new Image();
	onImgArray["policiesMenuButt"] = new Image();
	onImgArray["caseMenuButt"] = new Image();
	onImgArray["contactMenuButt"] = new Image();
	onImgArray["powerMenuButt"] = new Image();
	
	//Set URL for images
	onImgArray["homeMenuButt"].src = imgLoc + "home_on.gif";
	onImgArray["aboutMenuButt"].src = imgLoc + "about_on.gif";
	onImgArray["approachMenuButt"].src = imgLoc + "approach_on.gif";
	onImgArray["policiesMenuButt"].src = imgLoc + "policies_on.gif";
	onImgArray["caseMenuButt"].src = imgLoc + "case_on.gif";
	onImgArray["contactMenuButt"].src = imgLoc + "contact_on.gif";
	onImgArray["powerMenuButt"].src = imgLoc + "power_on.gif";
	
	//create 'off' array and populate with images
	var offImgArray = new Array();
	offImgArray["homeMenuButt"] = new Image();
	offImgArray["aboutMenuButt"] = new Image();
	offImgArray["approachMenuButt"] = new Image();
	offImgArray["policiesMenuButt"] = new Image();
	offImgArray["caseMenuButt"] = new Image();
	offImgArray["contactMenuButt"] = new Image();
	offImgArray["powerMenuButt"] = new Image();
	
	//Set URL for images
	offImgArray["homeMenuButt"].src = imgLoc + "home_off.gif";
	offImgArray["aboutMenuButt"].src = imgLoc + "about_off.gif";
	offImgArray["approachMenuButt"].src = imgLoc + "approach_off.gif";
	offImgArray["policiesMenuButt"].src = imgLoc + "policies_off.gif";
	offImgArray["caseMenuButt"].src = imgLoc + "case_off.gif";
	offImgArray["contactMenuButt"].src = imgLoc + "contact_off.gif";
	offImgArray["powerMenuButt"].src = imgLoc + "power_off.gif";
}

function imageOn(imgName){
	if(document.images){
			document.images[imgName].src = onImgArray[imgName].src;
	}
}
function imageOff(imgName){
	if(document.images){
		if(imgName != currNav){
			document.images[imgName].src = offImgArray[imgName].src;}
	}
}
function navOn(obj){
	var theObj = document.anchors[obj];
	if(theObj) {
			theObj.className = "selected";
	}
}
function setMsg(msg){
	window.status = msg;
	return true;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function soopaPopSetup() {
	var a;
	for (var i = 0; (a = document.links[i]); i++) {
		if (a.target && a.target.indexOf("_soopaPop") == 0) {
			a.onclick = soopaPop;
		}
	}
}

function soopaPop() {
	var a = this.target.split(":");
	var sFeatures = a[1];
	window.open(this.href, a.length > 2 ? a[2] : String((new Date()).getTime()), sFeatures);
	return false;
}


function CheckNav(){
PageTitle= self.document.title.substring(15,80)
PageURL  = self.document.location.href			

	if (location.href.indexOf('/home/') != -1){
		imageOn('homeMenuButt'); currNav = 'homeMenuButt';}	
	if (location.href.indexOf('/about/') != -1){
		imageOn('aboutMenuButt');currNav = 'aboutMenuButt';}	
	if (location.href.indexOf('/approach/') != -1){
		imageOn('approachMenuButt');currNav = 'approachMenuButt';}	
	if (location.href.indexOf('/policies/') != -1){
		imageOn('policiesMenuButt');currNav = 'policiesMenuButt';}	
	if (location.href.indexOf('/contact/') != -1){
		imageOn('contactMenuButt');currNav = 'contactMenuButt';}	
	if (location.href.indexOf('/case_studies/') != -1){
		imageOn('caseMenuButt');currNav = 'caseMenuButt';}	
	if (location.href.indexOf('/powersave/') != -1){
		imageOn('powerMenuButt');currNav = 'powerMenuButt';}	
}
