sfHover = function() {
	var sfEls = document.getElementById("navbar").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" hover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//ARE WE USING EXPLORER?
var g_isIE = navigator.appName.indexOf("Microsoft")!=-1;
var userAgent = navigator.userAgent.toLowerCase();
var version = parseFloat((userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1]);
if(g_isIE && version <='7' ){
	var oldIE = true;
}
//ABSTRACTED CONNECT EVENT FUNCTION FOR ANY BROWSER
function connectEvent(element, event, handler) {
	if (g_isIE) {
		element.detachEvent("on" + event, handler);
		element.attachEvent("on" + event, handler);
	} else {
		element.addEventListener(event, handler, false);
	}
}
function activeSections() {
	var section = "home";
	var pathString=window.location.href.split("/");

	if(typeof pathString[3] != "undefined"){
		var section = pathString[3];
		var section = section.replace(".html", "");
		
		//EXCEPTIOM MAPPING
		if(section == "about-esri"){var section = "company";}
		if(section == "user_showcase"){var section = "industries";}
		if(section == "adpages"){var section = "company";}
		if(section == "aprimoemails"){var section = "company";}
		if(section == "atponly"){var section = "training";}
		if(section == "blogs"){var section = "news";}
		if(section == "cd"){var section = "company";}
		if(section == "censuswatch"){var section = "industries";}
		if(section == "cigt"){var section = "services";}
		if(section == "data"){var section = "products";}
		if(section == "directnews"){var section = "news";}
		if(section == "disaster_response"){var section = "services";}
		if(section == "download"){var section = "products";}
		if(section == "eeap"){var section = "services";}
		if(section == "pss"){var section = "services";}
		if(section == "enewsletters"){var section = "news";}
		if(section == "esripress"){var section = "training";}
		if(section == "federalgsa"){var section = "industries";}
		if(section == "getting_started"){var section = "home";}
		if(section == "getting-started"){var section = "home";}
		if(section == "gisday"){var section = "events";}
		if(section == "grant"){var section = "industries";}
		if(section == "grants"){var section = "industries";}
		if(section == "homepage"){var section = "home";}
		if(section == "htmlemails"){var section = "news";}
		if(section == "htmlform"){var section = "news";}
		if(section == "legal"){var section = "company";}
		if(section == "intldist"){var section = "company";}
		if(section == "industries"){var section = "industries";}
		if(section == "library"){var section = "training";}
		if(section == "mapmuseum"){var section = "home";}
		if(section == "newsletters"){var section = "news";}
		if(section == "partners"){var section = "company";}
		if(section == "showcase"){var section = "industries";}
		if(section == "sag"){var section = "industries";}
		if(section == "site"){var section = "company";}
		if(section == "software"){var section = "products";}
		if(section == "surveys"){var section = "company";}
		if(section == "systemsint"){var section = "services";}
		if(section == "technology_trends"){var section = "home";}
		if(section == "universities"){var section = "industries";}
		if(section == "usersupport"){var section = "company";}
		if(section == "webmaster"){var section = "company";}		
	}
	
	if(typeof actSection != "undefined"){
		var section = actSection;
	}
	
	if(typeof section != "undefined"){
		if(document.getElementById(section)){
			document.getElementById(section).setAttribute((oldIE ? 'className' : 'class'), "on");
			
		} else {
			document.getElementById("home").setAttribute((oldIE ? 'className' : 'class'), "on");
			
		}
	}
	
	var myfilename=window.location.href.replace("http://","");
	var myfilename=myfilename.replace(pathString[2],"");

	if(myfilename == ""){
		var myfilename = "index.html";
	}
	// Gets all <a> tags in html
	// var links = document.getElementsByTagName("A"); // removed due to incompatibility with productsmenu.js
	// Gets only <a> tags in id #navbar div
	var links = document.getElementById('navbar').getElementsByTagName("a");
	for ( i=0; i < links.length; i++ ) {
		if(links[i].getAttribute('href') == myfilename || links[i].getAttribute("href",2) == myfilename) {
			links[i].setAttribute(( oldIE ? 'className' : 'class'), "on");
		}
	}
	if(document.getElementById("homeTopper")) {

		var images = [];
		var links = [];
		
		images[0]	= 'v24_business2.jpg';
		links[0]	= '/mapmuseum/mapbook_gallery/volume24/business2.html';
		
		images[1]	= 'v24_cartography2.jpg';
		links[1]	= '/mapmuseum/mapbook_gallery/volume24/cartography2.html';

		images[2]	= 'v24_cartography3.jpg';
		links[2]	= '/mapmuseum/mapbook_gallery/volume24/cartography3.html';

		images[3]	= 'v24_cartography4.jpg';
		links[3]	= '/mapmuseum/mapbook_gallery/volume24/cartography4.html';

		images[4]	= 'v24_communications1.jpg';
		links[4]	= '/mapmuseum/mapbook_gallery/volume24/communications1.html';

		images[5]	= 'v24_environment13.jpg';
		links[5]	= '/mapmuseum/mapbook_gallery/volume24/environment13.html';
		
		images[6]	= 'v24_local1.jpg';
		links[6]	= '/mapmuseum/mapbook_gallery/volume24/state-local1.html';
		
		images[7]	= 'v24_safety10.jpg';
		links[7]	= '/mapmuseum/mapbook_gallery/volume24/safety10.html';
		
		images[8]	= 'v24_safety13.jpg';
		links[8]	= '/mapmuseum/mapbook_gallery/volume24/safety13.html';
		
		images[9]	= 'v24_petroleum1.jpg';
		links[9]	= '/mapmuseum/mapbook_gallery/volume24/petroleum1.html';
		
		images[10]	= 'v24_engineering4.jpg';
		links[10]	= '/mapmuseum/mapbook_gallery/volume24/engineering4.html';
		
		images[11]	= 'v24_tourism4.jpg';
		links[11]	= '/mapmuseum/mapbook_gallery/volume24/tourism4.html';
		
		images[12]	= 'v24_transportation2.jpg';
		links[12]	= '/mapmuseum/mapbook_gallery/volume24/transportation2.html';
		
		images[13]	= 'v24_transportation10.jpg';
		links[13]	= '/mapmuseum/mapbook_gallery/volume24/transportation10.html';
		
		images[14]	= 'v24_transportation11.jpg';
		links[14]	= '/mapmuseum/mapbook_gallery/volume24/transportation11.html';
		
		images[15]	= 'v24_electric1.jpg';
		links[15]	= '/mapmuseum/mapbook_gallery/volume24/electric1.html';
		
		images[16]	= 'v24_electric2.jpg';
		links[16]	= '/mapmuseum/mapbook_gallery/volume24/electric2.html';
		
		images[17]	= 'v24_electric6.jpg';
		links[17]	= '/mapmuseum/mapbook_gallery/volume24/electric6.html';
		
		images[18]	= 'v24_agriculture4.jpg';
		links[18]	= '/mapmuseum/mapbook_gallery/volume24/agriculture4.html';
		
		images[19]	= 'v24_mining4.jpg';
		links[19]	= '/mapmuseum/mapbook_gallery/volume24/mining4.html';
		
		images[20]	= 'v24_tourism1.jpg';
		links[20]	= '/mapmuseum/mapbook_gallery/volume24/tourism1.html';
		
		images[21]	= 'v24_electric4.jpg';
		links[21]	= '/mapmuseum/mapbook_gallery/volume24/electric4.html';
		
		images[22]	= 'v24_cartography1.jpg';
		links[22]	= '/mapmuseum/mapbook_gallery/volume24/cartography1.html';
		
		images[23]	= 'v24_environment7.jpg';
		links[23]	= '/mapmuseum/mapbook_gallery/volume24/environment7.html';
		
		images[24]	= 'v24_safety11.jpg';
		links[24]	= '/mapmuseum/mapbook_gallery/volume24/safety11.html';


		var min = 1;
		var max = images.length;

		var i = Math.floor(Math.random() * (max - min + 1)) + min;
		ht = document.getElementById("homeTopper");
		ht.style.backgroundImage="url(/graphics/splash/"+images[0]+")";
		connectEvent(ht, "click", goTo);
		imgLink = links[0];

		if (typeof images[i] != "undefined") {
			document.getElementById("homeTopper").style.backgroundImage="url(/graphics/splash/"+images[i]+")";
			imgLink = links[i];
		}
	}
}

function goTo() {
	document.location.href=imgLink; 
}

var imgLink = "";

connectEvent(window, "load", activeSections);

/**
 * Fixes the xhtml strict lack of target attribute on links.
 * 
 * Usage:
 * Add the class "blankTarget" to your link and this script will open the link in a new window.
 * <a href="someLocation.html" rel="window" title="Some Title">Popup</a>  
 * 
 */
function showPopup() {
  var popup = window.open(this.href, "popup", "status=1,toolbar=1,location=1,menubar=1,scrollbars=1,resizable=1");

  return false;
}

function blankTargetLinks() {

	if (!document.getElementsByTagName) return;
	
	var anchors = document.getElementsByTagName("a");

	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		
		if (anchor.getAttribute("href")) {
			var external = /window/;
			if (anchor.getAttribute("rel")) {
				var classValue = anchor.getAttribute("rel");
			}
			else{
				var classValue = anchor.getAttribute("rel");
			}
			if (external.test(classValue)) {
				anchor.onclick = showPopup;
			}
		}
	}
	
}
connectEvent(window, "load", blankTargetLinks);