
// Static preload.
var oBgPreload = new Image();
oBgPreload.src = "media/bg.png";

// Mouseover...
function imageSwap(imgName, status){
	if(status){
		eval('document.' + imgName + '.src = "media/menu/' + imgName + '_' + status + '.jpg"');
	} else {
		eval('document.' + imgName + '.src = "media/menu/' + imgName + '.jpg"');
	}
}

// Image preload.
function preloadImages(imgArray){
	for (i = 0; i < imgArray.length; i++){
		eval("image_" + i + " = new Image();");
		eval("image_" + i + ".src = \"" + imgArray[i] + "\";");
	}
}

// Popup window.
function openWindow(path, name, width, height){
	width = width == null ? 800 : width;
	height = height == null ? 600 : height;
	wleft = (screen.width - width) / 2;
	wtop = (screen.height - height) / 2;
	// IE5 and other old browsers might allow a window that is partially offscreen or wider than the screen. Fix that. (Newer browsers fix this for us, but let's be thorough.)
	if (wleft < 0) {
		width = screen.width;
		wleft = 20;
	}
	if (wtop < 0) {
		height = screen.height;
		wtop = 20;
	}
	var win = window.open(path, name, "width=" + width + ", height=" + height + ", " + "left=" + wleft + ", top=" + wtop + ", location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=yes");
	// Just in case 'width' and 'height' are ignored
	win.resizeTo(width, height);
	// Just in case 'left' and 'top' are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}

// Welcome to AJAX - slightly modified version of http://www.hunlock.com/blogs/The_Ultimate_Ajax_Object
function ajaxObject(url, callbackFunction) {
	var that = this;      
	this.updating = false;
	this.abort = function() {
		if (that.updating) {
			that.updating = false;
			that.AJAX.abort();
			that.AJAX = null;
		}
	}
	this.update = function(passData,postMethod) { 
		if (that.updating) {
			return false;
		}
		that.AJAX = null;                          
		try {
			// Firefox, Opera 8.0+, Safari
			that.AJAX = new XMLHttpRequest();
		} catch (microsoftcompatible){
			// Internet Explorer
			try {
				that.AJAX = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (microsoftlegacy){
				that.AJAX = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		if (that.AJAX == null) {                             
			return false;                               
		} else {
			that.AJAX.onreadystatechange = function() {  
				if (that.AJAX.readyState == 4) {             
					that.updating = false;                
					that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
					that.AJAX = null;                                         
				}                                                      
			}                                                        
			that.updating = new Date();                              
			if (/post/i.test(postMethod)) {
				var uri = urlCall + '?' + that.updating.getTime();
				that.AJAX.open("POST", uri, true);
				that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				that.AJAX.setRequestHeader("Content-Length", passData.length);
				that.AJAX.send(passData);
			} else {
				var uri = urlCall + '?' + passData + '&timestamp=' + (that.updating.getTime()); 
				that.AJAX.open("GET", uri, true);                             
				that.AJAX.send(null);                                         
			}              
			return true;
		}                                                                           
	}
	var urlCall = url;        
	this.callback = callbackFunction || function () { };
}

// Weather.
function getWeather(divID){
	xmlReply = new ajaxObject("html/@weather.php", updateWeather);
	xmlReply.update("", "GET");
	function updateWeather(responseText, responseStatus, responseXML){
		document.getElementById(divID).innerHTML = responseText;
	}
}
