// $Author: josterlo $
// $Revision: 1.4 $
// $Date: 2004/06/29 22:10:20 $
// $Name:  $

var onCImgs = new Array(); // used for preloading images
var offCImgs = new Array(); // used for preloading images
var stp1, stp2, stp3; // initializes variables with global scope
var agent = navigator.userAgent.toLowerCase(); // used in flash detect


// manual preload of nav menu images
menu_gameindex_off = new Image(); menu_gameindex_off.src = 'resource/img/menu_btn_gameindex_off.gif';
menu_gameindex_on = new Image(); menu_gameindex_on.src = 'resource/img/menu_btn_gameindex_on.gif';
menu_store_off = new Image(); menu_store_off.src = 'resource/img/menu_btn_store_off.gif';
menu_store_on = new Image(); menu_store_on.src = 'resource/img/menu_btn_store_on.gif';
menu_community_off = new Image(); menu_community_off.src = 'resource/img/menu_btn_community_off.gif';
menu_community_on = new Image(); menu_community_on.src = 'resource/img/menu_btn_community_on.gif';
menu_downloads_off = new Image(); menu_downloads_off.src = 'resource/img/menu_btn_downloads_off.gif';
menu_downloads_on = new Image(); menu_downloads_on.src = 'resource/img/menu_btn_downloads_on.gif';
menu_corporate_off = new Image(); menu_corporate_off.src = 'resource/img/menu_btn_corporate_off.gif';
menu_corporate_on = new Image(); menu_corporate_on.src = 'resource/img/menu_btn_corporate_on.gif';
menu_support_off = new Image(); menu_support_off.src = 'resource/img/menu_btn_support_off.gif';
menu_support_on = new Image(); menu_support_on.src = 'resource/img/menu_btn_support_on.gif';
menu_signup_off = new Image(); menu_signup_off.src = 'resource/img/menu_btn_signup_off.gif';
menu_signup_on = new Image(); menu_signup_on.src = 'resource/img/menu_btn_signup_on.gif';
searchhelp_off = new Image(); searchhelp_off.src = 'resource/img/search_help.gif';
searchhelp_on = new Image(); searchhelp_on.src = 'resource/img/search_help_on.gif';

// simpler image rollover script
function imgSwap(imgName, direction){
	if (document.images){
		document.images[imgName].src = eval(imgName + "_" + direction + ".src");
	}
}


// HIDE AND REVEAL SUB NAVIGATION *************/

// finds the X position of the object in question
function findPosX(obj){
var curleft = 0;
	if (document.getElementById || document.all){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	} else if (document.layers){
		curleft += obj.x;
	}
	return curleft;
}

// finds the Y position of the object in question
function findPosY(obj){
var curtop = 0;
	if (document.getElementById || document.all){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (document.layers){
		curtop += obj.y;
	}
	return curtop;
}

// function to show/Hide Amazon divs
function showHide(theDiv, direction){

	// discount browser detect
	IE = (document.all) ? 1 : 0;
	DOM = (document.getElementById && !IE) ? 1 : 0;

	// set up some aliases
	if (IE){
		d1 = "document.all['";
		d2 = "'].style";
	} else if (DOM){
		d1 = "document.getElementById('";
		d2 = "').style";
	}

	if (direction == 'on'){
		opposite = 'off';
	} else {
		opposite = 'on';
	}

	// get the X and Y of the OFF object
	theLeft = findPosX(eval("document.images.menu_" + theDiv ));
	theTop = findPosY(eval("document.images.menu_" + theDiv));

	// now position the ON div so it's at the right place
	eval(d1 + "div_" + theDiv + "_" + "on" + d2 + ".top = '" + theTop + "px' ");
	eval(d1 + "div_" + theDiv + "_" + "on" + d2 + ".left = '" + theLeft + "px'");

	// turn on or off the correct div
	if (direction == 'on'){
		eval(d1 + "div_" + theDiv + "_on" + d2 + ".visibility = 'visible'");
	} else {
		eval(d1 + "div_" + theDiv + "_on" + d2 + ".visibility = 'hidden'");
	}
}

// *************************************/




function preLoad() { // takes array of images names and populates two other arrayts with image name and src
	for (var i = 0; i <= cImgs.length - 1; i++) {
		var onPath = mTP + cImgs[i] + '_on.gif';
		onCImgs[cImgs[i]] = new Image();
		onCImgs[cImgs[i]].src = onPath;
		var offPath = mTP + cImgs[i] + '_off.gif';
		offCImgs[cImgs[i]] = new Image();
		offCImgs[cImgs[i]].src = offPath;
	}
	pLoaded = true; //let's rollover scripts know that the page is comepletely loaded
}

function dSetUp() { // sets up variables as references to layers, no NS4x as JS can't change textDecoration in NS4x anyway
	if (document.all) {
		stp1 = stptitle1.style;
		stp2 = stptitle2.style;
		stp3 = stptitle3.style;
	} else if (document.getElementById) {
		stp1 = document.getElementById("stptitle1").style;
		stp2 = document.getElementById("stptitle2").style;
		stp3 = document.getElementById("stptitle3").style;
	}

}

function swapOff(imgName,tSrc,lName) { // allows for rollover of image or another image
	if ((tSrc == null) || (tSrc == '') || !tSrc) {
		target = imgName;
	} else {
		target = tSrc;
	}
	if(document.images && pLoaded) {
		if (document.layers && (lName != null)) {
			window.document.layers[lName].document.images[target].src = offCImgs[imgName].src; 
		} else {
			window.document.images[target].src = offCImgs[imgName].src;
		}
	}
}

function swapOn(imgName,tSrc,lName) { // allows for rollover of image or another image
	if ((tSrc == null) || (tSrc == '') || !tSrc) {
		target = imgName;
	} else {
		target = tSrc;
	}
	if(document.images && pLoaded) {
		if (document.layers && (lName != null)) {
				window.document.layers[lName].document.images[target].src = onCImgs[imgName].src; 
		} else {
			window.document.images[target].src = onCImgs[imgName].src;
		}
	}
}

function tiSwap(onOff,cls,imgName,tSrc) { // swaps image and changes text decoration: underline for 'cls' layer, purposely no NS4x
	if(onOff == 'on') {
		if (!document.layers) {
			eval(cls + '.textDecoration = \'underline\'');
		}
		swapOn(imgName,tSrc,null);
	} else if(onOff == 'off') {
		if (!document.layers) {
			eval(cls + '.textDecoration = \'none\'');
		}
		swapOff(imgName,tSrc,null);
	}
}

function winOpen(winName,doc) {
	var wOArg = 'var ' + winName + ' = window.open(\'' + doc + '\',\'' + winName + '\',\'width=600,height=350\');';
	eval(wOArg);
}

/*******************************************************************************
	Window properties -- Requires browserdetect_lite.js
*******************************************************************************/

// Get the width of the current window
function getWindowWidth(aWindow) {
    BrowserDetectLite();
    if (this.ns) return aWindow.innerWidth;
    if (this.ie) return aWindow.document.body.clientWidth;
    if (document.compatMode=="CSS1Compat") return document.documentElement.clientWidth;
}

// Get the height of the current window
function getWindowHeight(aWindow) {
    BrowserDetectLite();
    if (this.ns) return aWindow.innerHeight;
    if (this.ie) return aWindow.document.body.clientHeight;
    if (document.compatMode=="CSS1Compat") return document.documentElement.clientHeight;
}

// Open a window that is 70% the size of this one
function openExternalSite(url,name) {
    openCenteredWindow(url, name, getWindowWidth(window)*0.7, getWindowHeight(window)*0.7, true, true, 'resizable=yes', '')
}
