//////////////////////////////////////////////////////////////////
// IMAGES
//////////////////////////////////////////////////////////////////

/*
 * In each web page, fill values according to the following
 * pattern.
 * 
 *   { 
 *     IMAGE-NAME {
 *       off { url: OFF-STATE-URL , priority: OFF-STATE-LOAD-PRIORITY },
 *       on  { url: ON-STATE-URL ,  priority: ON-STATE-LOAD-PRIORITY }
 *     }
 *   }
 *
 * For more information, see "HTML Standards" in the 
 * eSCENE documentation.
 */


/****************************
 * Image rollovers
 ****************************/
//Turn image on
function imgOn(imgName){
	imgSwap(imgName,'on');
}
//Turn image off
function imgOff(imgName){
	imgSwap(imgName,'off');
}
//Turn image to any state
//Optional 3rd arg: layer id containing the image
function imgSwap(imgName,state) {
	var theImgObj;
	if (document.images) {
		if ((arguments.length > 2) && document.layers) {
			theImgObj=document[arguments[2]].document.images[imgName];
		} else {
			theImgObj=document[imgName];
		}
		theImgObj.src=jsImages[imgName][state].url;
	}
}

/* Preload one or more priorities of graphics.
 * If two or more priorities, load them in sequence.
 */
function preload() {
	var args=new Array();
	for (var i=0; i<arguments.length; i++) args[i]=arguments[i];  //convert to Array
	if (args.length > 0) {
		preloadOne(args[0]);
		checkAndPreload(args);
	}
}

/* Preload a single priority of graphics.
 */
function preloadOne(pri) {
	for (var imagename in jsImages) {
		for (var state in jsImages[imagename]) {
			if (jsImages[imagename][state].priority == pri) {
				jsImages[imagename][state].preload=new Image();
				jsImages[imagename][state].preload.src=jsImages[imagename][state].url;
			}
		}
	}
}

/* Check whether the highest priority has finished 
 * loading. If it has, preload the rest.
 *
 * Give it an array of priorities.
 */
function checkAndPreload(args) {
//	tellit('Working on: ' + args[0]);  //debug
	if (args.length > 1) {
		if (pAllLoaded(args[0])) {
			preloadOne(args[1]);
			args=args.slice(1);  //shift
		}
		window.setTimeout('checkAndPreload([' + args +  '])', 333);
	}
}

/* Return TRUE if all images at this priority
 * have loaded; FALSE otherwise.
 */
function pAllLoaded(pri) {
	for (var image in jsImages) {
		for (var state in jsImages[image]) {
			if (jsImages[image][state].priority == pri) {
				if (!jsImages[image][state].preload.complete) return false;
			}
		}
	}
	return true;
}



//////////////////////////////////////////////////////////////////
// RUN ME FIRST
//////////////////////////////////////////////////////////////////

/****************************
 * A page can run this script, in order to do some initial setup.
 *
 * Pass it one or more of these string values.
 *   product      Pages styled after the Product section.
 *   corp         Pages styled after the Corp section.
 *   admin        Pages styled after the Admin section.
 *   homestyle    Pages styled after the Homepage.
 *
 * Note: In MSIE, stylesheets take precedence over the alinkColor.
 ****************************/
function runMeFirst() {
	for (var i = 0; i < arguments.length; i++) {
		switch (arguments[i]) {
			case "product" :
				document.alinkColor = "ffffff";
				break;
			case "corp" :
				document.alinkColor = "ffffff";
				break;
			case "admin" :
				document.alinkColor = "ffffff";
				break;
			case "homestyle" :
				document.alinkColor = "000000";
				break;
			case "other" :
				alert("other"); //debug
				break;
			default :
				// What to do with an unknown value?
				break;
		}  // end switch
	}  // end for
}



//////////////////////////////////////////////////////////////////
// POP-UP WINDOWS
//////////////////////////////////////////////////////////////////

/* a.k.a Daughter Windows.
 * 
 * Recommended use:
 * Create a new script for each functional area of the site.
 * For example, create popHelp(), popJobs(), etc.
 * 
 * -- NEW POP SCRIPTS --
 * Each pop script should in turn call popGeneric.
 *
 * Depending on how much you plan to reuse your script, you
 * can put it in the .js file, or at the top of the HTML page.
 * 
 * Here are some options for "options"...
 *  options='width=500,height=350,menubar=yes,toolbar=yes,location=yes,directories=yes,scrollbars=yes,status=yes,resizable=yes';
 * To omit a browser feature, simply delete the entry or change it to "no".
 *
 */

/****************************
 * Generic window opener.
 *
 * TODO: make optional innerWidth and innerHeight arguments work.
 ****************************/
function popGeneric(url,windowName,options) {
//optional arguments: innerWidth, innerHeight
// -if none are passed, use width and height in options
// -if one is passed, use it for Width and Height

	var innerWidth, innerHeight;
	var useInnerSizes = false;
	if (arguments.length > 3) {
		useInnerSizes = true;
		innerWidth = arguments[3];
		innerHeight = arguments.length==5 ? arguments[4] : innerWidth;
	}
	
	var optionsSized = options;
	if (useInnerSizes) {
		
	}
	
	// Do it
	var win = window.open(url, windowName, optionsSized);
	win.focus();
}

/****************************
 * Open a job window.
 ****************************/
function popJob(url) {
	var options='width=668,height=436,toolbar=yes,scrollbars=yes,status=yes,resizable=yes';
	popGeneric(url,'escene_jobs',options);
}


/****************************
 * Open a press release window.
 ****************************/
function popPressRelease(url) {
	var options='width=500,height=350,toolbar=yes,scrollbars=yes,status=yes,resizable=yes';
	popGeneric(url,'escene_press',options);
}

/****************************
 * Open a flash window.
 ****************************/
function popFlash(url) {
	var options='width=620,height=430,status=yes';
	popGeneric(url,'escene_flash',options);
}


//////////////////////////////////////////////////////////////////
// DEBUG
//////////////////////////////////////////////////////////////////

function tellit(str){
	//top.frames['message'].document.write('<pre>'+str+'</pre>')
	//alert(str);
	var now=new Date();
	var stamp=now.toLocaleString()+'.'+(''+(1000+now.getMilliseconds())).substring(1,3);
	status='('+stamp+') '+str;
}



//////////////////////////////////////////////////////////////////
// VIDEO PLAYER
//////////////////////////////////////////////////////////////////


var corpVideoPath = "http://64.209.181.29/ramgen/userdata/CorporateVideos";
var corpVideoSuffix = "?usehostname";

function playVideo(fmt) {
	document.location = corpVideoPath + "/" + videoAsset[fmt] + corpVideoSuffix;
}


