/*****************************************************************
 * esbTools.js
 * Copyright 2000 ESB Productions
 *****************************************************************/
var gbIE4 = false;
var gbNS4 = false;
var gbNS6 = false;
if(document.all) gbIE4 = true;
if(document.tags) gbNS4 = true;
if(!gbIE4 && !gbNS4) gbNS6 = true;
gsaDays = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
gsaMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
gdDate = new Date();

function oWindow( sLocation, sWinName, sArgs ){
	var sArgsString = "";
	for (var oWi=2; oWi < arguments.length; oWi++){
		var thisArgument = arguments[oWi];
		if(gbNS4){
			thisArgument = oWindowNetscapeCompat( arguments[oWi] )
		}
		sArgsString += thisArgument;
		if (oWi != arguments.length - 1){	
			sArgsString += ",";
		}
	}
	var newWin = window.open(sLocation, sWinName, sArgsString );
	return (newWin)
}

function openMaximizedWindow( sLocation, sWinName ){
	var resize = "resizable=";
	if(gbNS4) {
		resize += "yes";
	} else {
		resize += "no";
	} 
	oWindow(sLocation, sWinName, resize, "toolbar=no", "directories=no", "status=no", "scrollbars=yes")
}

function maximizeWindow(){
	window.moveTo(0,0);
	if(gbIE4) {
		window.resizeTo(screen.availWidth, screen.availHeight);
	}else {
		window.outerHeight = screen.availHeight;
		window.outerWidth  = screen.availWidth;
	}
}

function oWindowNetscapeCompat( sArg ){
	var argSearch = new RegExp("=")
	var equalIndex = sArg.search(argSearch);
	var slicedArgBegin = sArg.slice(0, equalIndex);
	var slicedArgEnd = sArg.slice(equalIndex)
	switch (slicedArgBegin){
		case "height": 
			return("innerHeight" + slicedArgEnd);
		case "width":
			return("innerWidth" + slicedArgEnd);
		case "left":
			return("screenX" + slicedArgEnd);
		case "top":
			return("screenY" + slicedArgEnd);
		default:
			return(sArg)
	}
}

function writeDate(){
	var y2kFix = gdDate.getYear();
	if(y2kFix < 1900) y2kFix += 1900;
	document.write(gsaDays[gdDate.getDay()] + ", " + gsaMonths[gdDate.getMonth()] + " " + gdDate.getDate() + ", " + y2kFix );
}

function swapper(){
	this.saTagNames = new Array();	
	this.saImgPaths = new Array();
	this.folderPath = null;	
	this.lastImages = new Array();
	this.tagNames = swapperTN;
	this.setFolder = swapperSF;
	this.images = swapperIP;
	this.swap = swapperSwap;
	this.checkResize = swapperCheckResize;
	if(gbNS4){var timeMe = setInterval(this.checkResize, 250, this);}
}

function swapperTN( name1, name2, etc){
	for( var i = 0; i<arguments.length; i++){
		this.saTagNames[this.saTagNames.length] = arguments[i];
	}
}

function swapperSF( sFolderPath ){
	this.folderPath = sFolderPath;
}


function swapperIP( path1, path2, etc){
	for( var i = 0; i<arguments.length; i++){
		if(this.folderPath != null){
			this.saImgPaths[this.saImgPaths.length] = this.folderPath + arguments[i];
		} else {
			this.saImgPaths[this.saImgPaths.length] = arguments[i];
		}
	}
}

function swapperSwap(){
	var groupings = this.saTagNames.length;
	var numImages = this.saImgPaths.length;
	var chooseNumber = Math.floor( Math.random() * (numImages/groupings) ) * groupings;
	var groupingNum = 0;
	for(var i=chooseNumber; i<chooseNumber + groupings; i++){
		if(gbIE4){eval(this.saTagNames[groupingNum++]).src = this.saImgPaths[i];}
		if(gbNS4){
			eval("document.images." + this.saTagNames[groupingNum]).src = this.saImgPaths[i];
			this.lastImages[groupingNum] = eval("document.images." + this.saTagNames[groupingNum++]).src
		}
		if(gbNS6){document.getElementById(this.saTagNames[groupingNum++]).src = this.saImgPaths[i];}
	}
}

function swapperCheckResize( sr ){
	var st = new String( eval("document.images." + sr.saTagNames[0]).src );
	if(sr.lastImages[0] != st){
		for(var i=0; i<sr.lastImages.length; i++){
			eval("document.images." + sr.saTagNames[i]).src = sr.lastImages[i];
		}
	}
}
goROP = null;

function rollover(){
	this.path = null;
	this.imageObjects = new Array();
	this.lastImageOver = null;
	this.setFolder = rolloverSetFolder;					
	this.setRoll = rolloverSetRoll;
	this.alsoRoll = rolloverAlsoRoll;
	this.brain = rolloverBrain;
	if(gbNS4) window.captureEvents(Event.MOUSEMOVE);
	goROP = this;
	if(gbNS4){window.onMouseMove = this.brain;}	
	if(gbIE4 || gbNS6){
		document.onmouseover = this.brain;
		document.onmouseout = this.brain;
	}
}

function rolloverSetFolder( sFolderPath ){
	this.path = sFolderPath;
}

function rolloverSetRoll( startImage, rolloverImage){
	var index = this.imageObjects.length;
	for(var i = 0; i<2; i++){
		this.imageObjects[index + i] = new Image();
		if(this.path != null){
			 this.imageObjects[index + i].src = this.path + arguments[i];
		} else {
			this.imageObjects[index + i].src = arguments[i];
		}
		this.imageObjects[index + i].alsoRoll = null;
	}
}


function rolloverAlsoRoll( startImage, rolloverImage){
	var index = this.imageObjects.length - 2;
	for(var i = 0; i<2; i++){
		this.imageObjects[index + i].alsoRoll = new Image();
		if(this.path != null){
			 this.imageObjects[index + i].alsoRoll.src = this.path + arguments[i];
		} else {
			this.imageObjects[index + i].alsoRoll.src = arguments[i];
		}
	}
}
 
function rolloverBrain( e ){
	if(gbNS4 || gbNS6){
		var t = e.target;
		var ev = e.type;
		var tx = e.x;
		var ty = e.y;
		var flag = false;
		if(t.constructor != Image && t.constructor != Document) flag = true;
		if(flag){
			for(var i=0; i<document.images.length; i++){
				var ix = document.images[i].x;
				var iy = document.images[i].y;
				var iw = document.images[i].width;
				var ih = document.images[i].height;
				if(tx>=ix && tx<=ix+iw && ty>=iy && ty<=iy+ih){
					t = document.images[i];
					break;
				} 
			}
		}
		if(t.constructor == Image){
			if(t != goROP.lastImageOver){
				if(goROP.lastImageOver != null) rolloverFlip(goROP.lastImageOver, -1);
				goROP.lastImageOver = t;
				rolloverFlip(t, 1);
			}
		} else{
			if(goROP.lastImageOver != null ){
				rolloverFlip(goROP.lastImageOver, -1);
				goROP.lastImageOver = null;
			}
		}
	}
	if(gbIE4){
		t = event.srcElement;
		ev = event.type;
		if(ev == "mouseover"){
			rolloverFlip(t, 1);
		}
		if(ev == "mouseout"){
			rolloverFlip(t, -1);
		}
	}
}

function rolloverFlip(oTarget, iDirection){
	var io = goROP.imageObjects;
	for(var i=0; i<io.length; i++){
		if(oTarget.src == io[i].src){
			oTarget.src = io[i + iDirection].src;
			if(io[i].alsoRoll != null){
				for(var j=0; j<document.images.length; j++){
					if(io[i].alsoRoll.src == document.images[j].src){document.images[j].src = io[i + iDirection].alsoRoll.src;}
				}
			}
			break;
		}
	}
}
