/*
 * global.js
 *
 * Last Update: 12-06-2004
 * geoff@choppingblock.com
 *
 */

var fver = (navigator.userAgent.indexOf('Safari')!=-1) ? 7:6;
function addHeaderFlash(section,levels){
	var path = "";;
	for(var i=0;i<levels;i++){
		path += "../";
	}
	path = path+"_media/header.swf";
	var headerFlashObj = new FlashObject(path, "flashheaderobj", "770", "200", fver);
	headerFlashObj.addParam("scale", "noscale");
	headerFlashObj.addParam("wmode", "transparent");
	headerFlashObj.addVariable("section", section);
	headerFlashObj.addVariable("levels", levels);
	headerFlashObj.addVariable("maindatapath", levels+"_xml/nav.xml");
	headerFlashObj.write('header');
}
function addRightStack(levels){
	var path = "";
	for(var i=0;i<levels;i++){
		path += "../";
	}
	path = path+"_media/rightcol.swf";
	var rightstackFlashObj = new FlashObject(path, "flashRightCol", "186", "497", fver);
	rightstackFlashObj.addParam("scale", "noscale");
	rightstackFlashObj.addVariable("levels", levels);
	rightstackFlashObj.addParam("wmode", "transparent");
	rightstackFlashObj.write('rightcol');
}
function addRig(){
	path = "_media/treysrig.swf";
	var rigFlashObj = new FlashObject(path, "flashRigObj", "500", "700", fver);
	rigFlashObj.addParam("scale", "noscale");
	rigFlashObj.addParam("wmode", "transparent");
	rigFlashObj.write('treysrig');
}

function assignRollOvers(elementid,directory){
	if(document.getElementsByTagName && document.getElementById){
		var element = document.getElementById(elementid);
		var taglist = element.getElementsByTagName("img");
		for(var i=0; i<taglist.length; i++){
			var node = taglist[i];
			addRollOver(node.id,directory);
		}
	}
}
		   
function addRollOver(id,path){
	var target = document.getElementById(id);
	target.rolloversrc = path+id+"_a.gif";
	target.origsrc = path+id+".gif";

	if(typeof rolloverPreloader != "object"){
		rolloverPreloader = new Object();
	}
	rolloverPreloader[id+"preload"] = new Image();
	rolloverPreloader[id+"preload"].src = target.rolloversrc;
	
	target.onmouseover = function(){
		this.src = this.rolloversrc;
	}
	if(typeof ci != "object"){
		target.onmouseout = function(){
				this.src = this.origsrc;
		}	
	}else{
		target.onmouseout = function(){
			if(ci != this){
				this.src = this.origsrc;
			}
		}
	}
}


// adds a function to the page onload, so we don't overwrite existing onload functions
function addOnLoad(f) {
    var currentOnLoad = window.onload;
    if (typeof window.onload != "function") {
        window.onload = f;
    } else {
        window.onload = function() {
            currentOnLoad();
            f();
        }
    }
}

/*
 * FlashObject embed
 *
 * by Geoff Stearns (geoff@choppingblock.com, http://www.choppingblock.com/)
 *
 * v1.0.7 - 11-17-2004
 *
 * Create and write a flash movie to the page, includes detection
 *
 * Usage:
 *
 *	myFlash = new FlashObject("path/to/swf.swf", "swfid", "width", "height", flashversion, "backgroundcolor");
 *	myFlash.altTxt = "Upgrade your Flash Player!";                // optional
 *	myFlash.addParam("wmode", "transparent");                     // optional
 *	myFlash.addVariable("varname1", "varvalue");                  // optional
 *	myFlash.addVariable("varname2", getQueryParamValue("myvar")); // optional
 *	myFlash.write();
 *
 */

FlashObject = function(swf, id, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver || 6; // default to 6
	this.align = "middle"; // default to middle
	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	this.altTxt = "Please <a href='http://www.macromedia.com/go/getflashplayer'>upgrade your Flash Player</a>.";
	this.bypassTxt = "<p>Already have Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
	this.params = new Object();
	this.variables = new Object();
	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'high'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
}

FlashObject.prototype.addParam = function(name, value) {
	this.params[name] = value;
}

FlashObject.prototype.getParams = function() {
    return this.params;
}

FlashObject.prototype.getParam = function(name) {
    return this.params[name];
}

FlashObject.prototype.addVariable = function(name, value) {
	this.variables[name] = value;
}

FlashObject.prototype.getVariable = function(name) {
    return this.variables[name];
}

FlashObject.prototype.getVariables = function() {
    return this.variables;
}

FlashObject.prototype.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    if (paramTags == "") {
        paramTags = null;
    }
    return paramTags;
}

FlashObject.prototype.getHTML = function() {
    var flashHTML = "";
    if (window.ActiveXObject && navigator.userAgent.indexOf('Mac') == -1) { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        if (this.getParamTags() != null) {
            flashHTML += this.getParamTags();
        }
        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    else { // Everyone else
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs() != null) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    }
    return flashHTML;	
}


FlashObject.prototype.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
        variablePairs.push(name + "=" + escape(this.getVariable(name)));
    }
    if (variablePairs.length > 0) {
        return variablePairs.join("&");
    }
    else {
        return null;
    }
}

FlashObject.prototype.write = function(elementId) {
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (elementId) {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			document.location.replace(this.redirect);
		} else {
			if (elementId) {
				document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
			} else {
				document.write(this.altTxt +""+ this.bypassTxt);
			}
		}
	}		
}

function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.plugins.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x){
			if (x.description) {
				var y = x.description;
	   			flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
	} else {
		result = false;
	    for(var i = 15; i >= 3 && result != true; i--){
   			execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
   			flashversion = i;
   		}
	}
	return flashversion;
}

function detectFlash(ver) {	
	if (getFlashVersion() >= ver) {
		return true;
	} else {
		return false;
	}
}

// get value of querystring param
function getQueryParamValue(param) {
	var q = document.location.search;
	var detectIndex = q.indexOf(param);
	var endIndex = (q.indexOf("&", detectIndex) != -1) ? q.indexOf("&", detectIndex) : q.length;
	if(q.length > 1 && detectIndex != -1) {
		return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
	} else {
		return "";
	}
}

/* add Array.push if needed */
if(Array.prototype.push == null){
	Array.prototype.push = function(item){
		this[this.length] = item;
		return this.length;
	}
}

/* * QTObject embed * http://blog.deconcept.com/2005/01/26/web-standards-compliant-javascript-quicktime-detect-and-embed/ * * by Geoff Stearns (geoff@deconcept.com, http://www.deconcept.com/) * * v1.0.1 - 02-11-2005 * * Embeds a quicktime movie to the page, includes plugin detection * * Usage: * *	myQTObject = new QTObject("path/to/mov.mov", "movid", "width", "height"); *	myQTObject.altTxt = "Upgrade your Quicktime Player!";    // optional  *  myQTObject.addParam("controller", "false");              // optional *	myQTObject.write(); * */QTObject = function(mov, id, w, h) {	this.mov = mov;	this.id = id;	this.width = w;	this.height = h;	this.redirect = "";	this.sq = document.location.search.split("?")[1] || "";	this.altTxt = "This content requires the QuickTime Plugin. <a href='http://www.apple.com/quicktime/download/'>Download QuickTime Player</a>.";	this.bypassTxt = "<p>Already have QuickTime Player? <a href='?detectqt=false&"+ this.sq +"'>Click here.</a></p>";	this.params = new Object();	this.doDetect = getQueryParamValue('detectqt');}QTObject.prototype.addParam = function(name, value) {	this.params[name] = value;}QTObject.prototype.getParams = function() {    return this.params;}QTObject.prototype.getParam = function(name) {    return this.params[name];}QTObject.prototype.getParamTags = function() {    var paramTags = "";    for (var param in this.getParams()) {        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';    }    if (paramTags == "") {        paramTags = null;    }    return paramTags;}QTObject.prototype.getHTML = function() {    var qtHTML = "";	if (navigator.plugins && navigator.plugins.length) { // not ie        qtHTML += '<embed type="video/quicktime" src="' + this.mov + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '"';        for (var param in this.getParams()) {            qtHTML += ' ' + param + '="' + this.getParam(param) + '"';        }        qtHTML += '></embed>';    }    else { // pc ie        qtHTML += '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '">';        this.addParam("src", this.mov);        if (this.getParamTags() != null) {            qtHTML += this.getParamTags();        }        qtHTML += '</object>';    }    return qtHTML;}QTObject.prototype.getVariablePairs = function() {    var variablePairs = new Array();    for (var name in this.getVariables()) {        variablePairs.push(name + "=" + escape(this.getVariable(name)));    }    if (variablePairs.length > 0) {        return variablePairs.join("&");    }    else {        return null;    }}QTObject.prototype.write = function(elementId) {	if(isQTInstalled() || this.doDetect=='false') {		if (elementId) {			document.getElementById(elementId).innerHTML = this.getHTML();		} else {			document.write(this.getHTML());		}	} else {		if (this.redirect != "") {			document.location.replace(this.redirect);		} else {			if (elementId) {				document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;			} else {				document.write(this.altTxt +""+ this.bypassTxt);			}		}	}		}function isQTInstalled() {	var qtInstalled = false;	qtObj = false;	if (navigator.plugins && navigator.plugins.length) {		for (var i=0; i < navigator.plugins.length; i++ ) {         var plugin = navigator.plugins[i];         if (plugin.name.indexOf("QuickTime") > -1) {			qtInstalled = true;         }      }	} else {		execScript('on error resume next: qtObj = IsObject(CreateObject("QuickTimeCheckObject.QuickTimeCheck.1"))','VBScript');		qtInstalled = qtObj;	}	return qtInstalled;}