window.onload = function()
{

	//highlightGlobalNav('header');
	//highlightGlobalNav('topnav'); 
	highlightLocalNav('subnav');

	var thispath = window.location.toString().split('#')[0].split('?')[0];
	thispath = thispath.replace(/^http:\/\/.+?\/(.*)$/, "/$1");
	if(thispath=='/contact/') showGMap();
	
}


function highlightGlobalNav(navdiv)
{
	var thissection = window.location.toString().split('/')[3];
	var navul = document.getElementById(navdiv);
	if (navul) {
		var navanchors = navul.getElementsByTagName('a');
		if (navanchors) {
			for(var i = 0; i <= navanchors.length-1; i++) {
				if (navanchors[i].href.toString().split('/')[3] == thissection) {
					navanchors[i].className = 'here';
					break;
				} else {
					navanchors[i].className = 'nothere';
				}
			}
		}
	}
}


function highlightLocalNav(navdiv)
{
	var thispath = window.location.toString().split('#')[0].split('?')[0];
	
	var navwrap = document.getElementById(navdiv);
	
	if (navwrap) {
		var navanchors = navwrap.getElementsByTagName('a');
		if (navanchors) {
			for(var i = 0; i <= navanchors.length-1; i++) {
				if (navanchors[i].href == thispath) {
					navanchors[i].className = 'here';
					break;
				} else {
					navanchors[i].className = 'nothere';
				}
			}
		}
	}
}


function clearfield (val, element) {
   if (element.value == val) element.value = "";
}






function showGMap() {
	if (GBrowserIsCompatible()) {

		var m = document.getElementById("google-map");
		m.style.height = "350px";
		m.style.width = "580px";
		var map = new GMap(m);
		map.addControl (new GSmallMapControl());
		// Map GPoint Coordinates Here
		map.centerAndZoom(new GPoint(-122.196121, 47.61464), 2);
		var point = new GPoint(-122.196121, 47.61464);
		marker = new GMarker(point);
		// Address for Marker Popup
		var html = '<div style="white-space:nowrap;"><strong>Prometheus Energy</strong><br />500 108th Avenue NE, Suite 2340<br />Bellevue, WA 98004</div>';
			GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(html);
		});
		map.addOverlay(marker);
	}
}
//Get Directions to Location
function toTarget () {
	var addr = document.directions.address.value;
	addr = addr.replace(/\+/g, '%2B');
	addr = addr.replace(/ /g, '+');
	var googleAddress = '500+108th+Avenue+NE,';
	googleAddress += 'Bellevue,+WA';
	var txt = 'http://maps.google.com/?q=from:'+addr+'+to:+';
	txt += googleAddress;
	return txt;
}



//returns an integer between 1 and n
function rand(n)
{
	return	(Math.floor(Math.random() * n + 1 ));
}

