/*  ##########################################################################
'	##########################################################################

' 	scripts.js

'	Author(s)
'	David Dekker, DD, david.dekker@akqa.com

' 	Copyright 2006 AKQA.  All rights reserved.

'	Version 1.00
'	Created: 02/05/2006

'	Versions:
' 	1.00 - Initial version - DD

	##########################################################################
	##########################################################################
*/

// Return the file extension of the passed variable
function getFileExtension(fileSource) {
	var newSource = '';
	if (fileSource.lastIndexOf(".") != -1) {
		newSource = fileSource.substring(fileSource.lastIndexOf("."));
	}
	return newSource;
}

// Mouse Rollover function
function MouseOver(image) {
	if(image.src.indexOf("-over") == -1) {
		var imageExt = getFileExtension(image.src);
		image.src = image.src.substring(0,image.src.indexOf(imageExt)) + "-over" + imageExt;
	}
}

// Mouse Rollout function
function MouseOut(image) {
	if (image.src.indexOf("-over") >= 0) {
		var imageExt = getFileExtension(image.src);
		image.src = image.src.substring(0,image.src.indexOf("-over" + imageExt)) + imageExt;
	}
}

// Image rollover function
var myBodyImages = document.getElementsByTagName("img");
var myBodyInput = document.getElementsByTagName("input");
var objImage = new Image();
function loadme() {
	var j = 0;
	/* handles all images */
	for (i=0; i<myBodyImages.length; i++) {
		if (myBodyImages.item(i).className == "rollover") {
			myBodyImages.item(i).onmouseover = new Function("MouseOver(this);");
			myBodyImages.item(i).onmouseout = new Function("MouseOut(this);");
			objImage.src = myBodyImages.item(i).src;
			MouseOver(objImage);
		}
	}
	/* handles all input fields with image as a submit button */
	for (i=0; i<myBodyInput.length; i++) {
		if (myBodyInput.item(i).className == "rollover") {
			myBodyInput.item(i).onmouseover = new Function("MouseOver(this);");
			myBodyInput.item(i).onmouseout = new Function("MouseOut(this);");
			objImage.src = myBodyInput.item(i).src;
			MouseOver(objImage);
		}
	}
}


/*
window.onload = function() {
	if (typeof onLoadMeFunction == "function") {
		onLoadMeFunction();
	} 
	loadme();
}
*/


/************* POPUPS *************/


function writeToElement(text,id)
{
	if (document.getElementById) {
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	} else if (document.all) {
		x = document.all[id];
		x.innerHTML = text;
	} else if (document.layers) {
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}


function resizeThisToFull() {
	//if ((Win && Netscape) || Opera || Unknown || Mac) {
	var MSIE = navigator.appName == "Microsoft Internet Explorer";
	var Win = navigator.userAgent.indexOf("Win") > -1;
	if (!(MSIE && Win)) {
		window.moveTo(0,0);
		if (document.all) {
			window.resizeTo(screen.availWidth,screen.availHeight);
		} else if (document.layers || document.getElementById) {
			if (window.outerHeight < screen.availHeight || window.outerWidth < screen.availWidth) {
				window.outerHeight = screen.availHeight;
				window.outerWidth = screen.availWidth;
			}
		}
	}
}


function openWin(url,name,w,h) {
	var strGoTo = url;
	var strWinName = name;
	var top = screen.height/2 - h/2;
	var left = screen.width/2 - w/2;
	var strParams = "";
	if (navigator.appName.indexOf("Netscape") != -1) {
		strParams += "screenX="+left+",screenY="+top+"";
	} else {
		strParams += "left="+left+",top="+top+",fullscreen=0";
	}
	//strParams += ",width="+(w)+",height="+(h)+",scrollbars=0,resizable=0";
	strParams += ",width="+(w)+",height="+(h)+",scrollbars=1,resizable=0";
	newWindow = window.open(strGoTo,strWinName,strParams);
	if (newWindow) {
		newWindow.focus();
		newWindow = null;
	}
}


function openTerms(query){
	openWin("terms.html","terms",700,500);
}


function openPrizes(query){
	openWin("prizes.html","prizes",700,500);
}


function openHowToPlay(query){
	openWin("howtoplay.html","howtoplay",700,500);
}


