window.onload=function(){
	turnOnButtonCurrentPage();
	clearInputBoxDefaultsOnClick();
	splashImagesToDOM();
}
//-----------------------------
function turnOnButtonCurrentPage(){
	var fileName = location.href.substring(location.href.lastIndexOf('/') + 1);
	var anchorList = document.getElementById('navmenu').getElementsByTagName('a');
	for(var i=0; i<anchorList .length; ++i) {
		var anchorHref = anchorList[i].href;
		anchorHref = anchorHref.substring(anchorHref.lastIndexOf('/') + 1);
		if(anchorHref == fileName) {
			anchorList[i].className = 'buttonSelected';// change the class of this anchor
			break;
		}
	} 
}
//-----------------------------
function clearInputBoxDefaultsOnClick(){
	/* this adds code to all text boxes to make them clear default values on click */
	var textBoxes = new Array();
	var allInputs = new Array();
	var x = 0;
	allInputs = document.getElementsByTagName( 'input' )
	for ( i = 0; i < allInputs.length; i++ ){
		if ( allInputs[i].type == 'text' ){
            textBoxes.push( allInputs[i] );
         }
     }
	for ( i = 0; i < textBoxes.length; i++ ){ 
		if(textBoxes[i].value != ""){
			textBoxes[i].setAttribute('onblur', 'if (this.value == "") { this.value="' + textBoxes[i].value + '"; }');
			textBoxes[i].setAttribute('onfocus', 'if (this.value == "' +  textBoxes[i].value + '") { this.value=""; }');  
		}
	}  
}
//-----------------------------
function getQuerystring(key, default_){
    if (default_==null){
        default_="";
    }
    var search = unescape(location.search);
    if (search == ""){
        return default_;
    }
    search = search.substr(1);
    var params = search.split("&");
    for (var i = 0; i < params.length; i++){
        var pairs = params[i].split("=");
        if(pairs[0] == key){
            return pairs[1];
        }
    }
    return default_;
}
//-----------------------------
function swapImage(id, src) {
	document.getElementById(id).style.backgroundImage = "url('" + src + "')";
}
//-----------------------------
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//-----------------------------
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//-----------------------------
function eraseCookie(name) {
	createCookie(name,"",-1);
}
//-----------------------------
function showDiv(boxid){
	if(!document.getElementById(boxid)) return;
	document.getElementById(boxid).style.visibility="visible";
	document.getElementById(boxid).style.display="block";
}
//-----------------------------
function hideDiv(boxid){
	if(!document.getElementById(boxid)) return;
	document.getElementById(boxid).style.visibility="hidden";
	document.getElementById(boxid).style.display="none";
}
//-----------------------------
function toggleHideDiv(boxid){
	// if clicked, show if hidden, hide if visible
	if(!document.getElementById(boxid)) return;
	var boxStyle = document.getElementById(boxid).style; 
	if(boxStyle.visibility == "hidden" || boxStyle.display == "none"){
		boxStyle.visibility ="visible";
		boxStyle.display = "block";
	}
	else{
		boxStyle.visibility ="hidden";
		boxStyle.display = "none";
	}
}
//-----------------------------
function submitQueryToServer(theFormId,theBaseURL) {
	// build query string
	theForm = document.getElementById(theFormId);
	queryString = '';
	for (i=0; i < theForm.elements.length; i++) {
		element = theForm.elements[i];
		if (element.name){
			if (element.type == 'radio' || element.type == 'checkbox'){
				if (element.checked == true){
					queryString += element.name + '=' + element.value + "&";
				}
			}
			else{
				queryString += element.name + '=' + element.value + "&";
			}
		}
	}
	getResponse(theBaseURL + '?' + queryString);
	window.location.href = "#saved"; // don't put a slash after the # or it will try to load 'saved'. This just creates a history response if we press back.

}
//-----------------------------
function stateChanged() {
	idToChange = 'columnRight';
	//alert ("id to change: " + idToChange);
	if (xmlHttp.readyState==4) {
		replaceHtml(idToChange,xmlHttp.responseText)
		//document.getElementById('cityData').innerHTML=xmlHttp.responseText
		hideDiv('timer');
	}
	else {
		showDiv('timer');
		//alert ("ready state:" + xmlHttp.readyState);
	}
}
//-----------------------------
var xmlHttp
function getResponse(url){
	xmlHttp = GetXMLHttpObject()
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP request")
		return
	}
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url, true)
	xmlHttp.send(null)
	//alert ("response " + xmlHttp.responseText);
}
//-----------------------------
function GetXMLHttpObject(){
	var objXMLHttp = null
	if (window.XMLHttpRequest) {
		objXMLHttp = new XMLHttpRequest(); //Mozilla
	}
	else if  (window.ActiveXObject) {
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); //Explorer
	}
	return objXMLHttp
}
//-----------------------------
function replaceHtml(el, html) {
	var oldEl = typeof el === "string" ? document.getElementById(el) : el;
	/*@cc_on // Pure innerHTML is slightly faster in IE
	oldEl.innerHTML = html;
	return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	/* Since we just removed the old element from the DOM, return a reference
	to the new element, which can be used to restore variable references. */
	return newEl;
}
//-----------------------------
function clientSideInclude(id, url) {
	var req = false;
	if (window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		}
		catch (e) {
			req = false;
		}
	}
	else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				req = false;
			}
		}
	}
	var element = document.getElementById(id);
	if (!element) {
		alert("Bad id " + id + "passed to clientSideInclude." +	"You need a div or span element " + "with this id in your page.");
		return;
	}
	if (req) {
		req.open('GET', url, false);
		req.send(null);
		element.innerHTML = req.responseText;
	}
	else {
		element.innerHTML =
			"Sorry, your browser does not support XMLHTTPRequest objects. This page requires " +
			"Internet Explorer 5 or better for Windows, or Firefox for any system, or Safari. Other " +
			"compatible browsers may also exist.";
	}
}
//-----------------------------
var imgObj = new Array;
function splashImagesToDOM(){
	// first create the images in divs, appended to existing image
	var parentDiv = document.getElementById("splash");
	for(i=0; i<imageArray.length; i++) { 
		var newDiv = document.createElement("DIV");
		parentDiv.appendChild(newDiv);
		newDiv.setAttribute('id','splash' + i);
		newDiv.style.width = "100%";
		newDiv.style.height = "100%";
		newDiv.style.position = "absolute";
		newDiv.style.top = "0";
		newDiv.style.left = "0";
		newDiv.style.background = "url(" + imageArray[i] + ")";
		newDiv.style.backgroundRepeat = "no-repeat";
		newDiv.style.overflow = "hidden";
		newDiv.style.display = "none";
		newDiv.style.zIndex = "auto";
		imgObj.push(document.getElementById("splash" + i));
		imgObj[i].xOpacity = 0;
	}
	// now begin crossfading the images:
	imgObj[0].xOpacity = .99;
	crossFadeSplashImages(0);
}
//-----------------------------
var current=0;
function crossFadeSplashImages(){
	currentOpacity = imgObj[current].xOpacity;
	nextIndex = imgObj[current+1]?current+1:0;
	nextOpacity = imgObj[nextIndex].xOpacity;
	currentOpacity-=.05; 
	nextOpacity+=.05;
	imgObj[nextIndex].style.display = "block";
	imgObj[current].xOpacity = currentOpacity;
	imgObj[nextIndex].xOpacity = nextOpacity;

	setOpacity(imgObj[current]); 
	setOpacity(imgObj[nextIndex]);

	if(currentOpacity<=0) {
		imgObj[current].style.display = "none";
		current = nextIndex;
		setTimeout(crossFadeSplashImages,8000);
	} else {
		setTimeout(crossFadeSplashImages,40);
	}
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
}
//-----------------------------

