// ++++++++++
// oConnection -- base object to manage an XMLHTTP connection
// ++++++++++

function oConnection() {
	// ==============
	// attributes
	// ==============
	this.Name =					"";
	this.Conn = 					oXmlHttp();
	this.sendMethod =			"";
	this.url =						"";
	// ==============
	// methods
	// ==============
	this.reset =					oConnectionReset;
	this.send =					oConnectionSend;
	this.sendReceive =		oConnectionSendReceive;
}

function oConnectionReset() {
	this.Conn = null;
	this.Conn = oXmlHttp();
}

function oConnectionSend(obj) {
	if ((this.sendMethod == '') || (this.url == '')) {
		return(false);
	}
	this.Conn.open(this.sendMethod,this.url,false);
	this.Conn.send(obj);
	return(true);
}

function oConnectionSendReceive(obj) {
	if ((this.sendMethod == '') || (this.url == '')) {
		return(false);
	}
	this.Conn.open(this.sendMethod,this.url,false);
	try {
		this.Conn.send(obj);
	} catch (e) {
//		alert(e.description);
	}
	return(this.Conn.responseXML);
}

// ++++++++++
// oXmlHttp -- function to create an XMLHTTP connection
// ++++++++++

function oXmlHttp() {
	var httpRequest;
	// check if mozilla
	if (window.XMLHttpRequest) { 
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('application/xml');
		}
	} 
	// check if IE
	else if (window.ActiveXObject) {
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!httpRequest) {
		alert("An error occurred: Cannot create an XMLHTTP instance");
		return false;
	} else {
		return httpRequest;
	}
}

function oXmlHttpHandleResponse(obj) {			
	try {
		if (obj.readyState == 4) {
			if (obj.status > 300) {
				alert("Server error: " + obj.status);
			} else {
				return(obj.responseXML);
			}
		}
	} catch(e) {
		alert("Caught exception while processing the response" + e.description);
	}
}


// ++++++++++
// oTransformer -- base object to transform XML into HTML
// ++++++++++

function oTransformer() {
	// attributes
	this.Processor =				oXsltProcessor();
	this.Serializer = 				oXmlSerializer();
	this.Conn =						new oConnection();
	// methods
	this.loadStylesheet =			oTransformerLoadStylesheet;
	this.transformToHtml =		oTransformerTransformToHtml;
	this.reset =						oTransformerReset;
}

function oTransformerLoadStylesheet(strUrl) {
	this.Conn.sendMethod = "GET";
	this.Conn.url = strUrl;
	var docStylesheet = this.Conn.sendReceive(null);
	if (window.ActiveXObject) {
		this.Processor.loadXML(docStylesheet.xml);
	} else {
		this.Processor.importStylesheet(docStylesheet);
	}
	return(true);
}

function oTransformerTransformToHtml(doc,docParent) {
	if (window.ActiveXObject) {
		try {
			return(doc.transformNode(this.Processor));
		} catch(e) {
			alert(e.description);
		}
	} else {
		try {
			var frag = this.Processor.transformToFragment(doc,docParent);
			return(this.Serializer.serializeToString(frag));			
		} catch(e) {
			setTimeout("self.location.reload()",500);
		}
	}
}

function oTransformerReset() {
	if (window.ActiveXObject) {
		this.Processor = null;
		this.Processor = oXsltProcessor();
	} else {
		this.Processor.reset();
	}
}

// ++++++++++
// oXsltProcessor -- function to create an XSL Processor
// ++++++++++

function oXsltProcessor() {
	var xsltProcessor;
	// check if mozilla
	if (window.XSLTProcessor) { 
		xsltProcessor = new XSLTProcessor();
	} 
	// check if IE
	else if (window.ActiveXObject) {
		try {
			xsltProcessor = new ActiveXObject("Msxml2.DOMDocument");
		} catch (e) {
			try {
				xsltProcessor = new ActiveXObject("Microsoft.DOMDocument");
			} catch (e) {}
		}
	}
	if (!xsltProcessor) {
		alert("An error occurred: Cannot create an XSLTProcessor instance");
		return false;
	} else {
		return xsltProcessor;
	}
}

// ++++++++++
// oXmlSerializer -- function to create an XML Serializer
// ++++++++++

function oXmlSerializer() {
	var xmlSerializer;
	// check if mozilla
	if (window.XSLTProcessor) { 
		xmlSerializer = new XMLSerializer();
	} 
	// check if IE
	else if (window.ActiveXObject) {
		try {
			xmlSerializer = new ActiveXObject("Msxml2.DOMDocument");
		} catch (e) {
			try {
				xmlSerializer = new ActiveXObject("Microsoft.DOMDocument");
			} catch (e) {}
		}
	}
	if (!xmlSerializer) {
		alert("An error occurred: Cannot create an XML Serializer instance");
		return false;
	} else {
		return xmlSerializer;
	}
}


// ++++++++++
// Box -- base object for the home page boxes
// ++++++++++

function Box(strName,objDiv,stage) {
	// the name
	this.name = strName;
	// the parent stage
	this.boxStage = stage;
	this.idx;
	// the HTML object
	this.obj = objDiv;
	// store original position
	this.origX = new Number(this.obj.style.left.replace("px",""));
	this.origY = new Number(this.obj.style.top.replace("px",""));
	this.origWidth = new Number(this.obj.style.width.replace("px",""));
	this.origHeight = new Number(this.obj.style.height.replace("px",""));
	// store current position
	this.x = this.origX;
	this.y = this.origY;
	this.width = this.origWidth;
	this.height = this.origHeight
	// store new position
	this.newX;
	this.newY;
	this.newWidth;
	this.newHeight;
	this.anchorPoint;
	// calculated attributes
	this.newDistance;
	this.newXStep;
	this.newYStep;
	this.newWidthStep;
	this.newHeightStep;
	// moving properties
	this.direction = "";
	this.isMoving = false;
	this.speed = 1;
	this.stepCount = 0;
	this.stepIdx = 0;
	// call-blocker
	this.blocker = "";
	// call-back function
	this.callBack = "";
	// call-waiting: stores parameters for waiting call
	this.callWaiting = new Array();
	// methods
	this.doMove = boxDoMove;
//	this.moveTo = boxMoveTo;
//	this.moveBy = boxMoveBy;
//	this.moveHome = boxMoveHome;
	this.stretch = boxStretch;
	// make it
	return this;
}

function boxDoMove() { 
	var intNewX, intNewY, intNewWidth, intNewHeight;
	// check if we've arrived
	if (this.stepIdx >= this.stepCount) {
		intNewX = this.newX;
		intNewY = this.newY;
		intNewWidth = this.newWidth;
		intNewHeight = this.newHeight;
		this.isMoving = false;
		this.direction = "";
	} else {
		// calculate new pos
		intNewX = (this.newXStep * this.speed) + this.x;
		intNewY = (this.newYStep * this.speed) + this.y;
		intNewWidth = (this.newWidthStep * this.speed) + this.width;
		intNewHeight = (this.newHeightStep * this.speed) + this.height;
	}
	// move the div
	this.obj.style.left = intNewX + "px";
	this.obj.style.top = intNewY + "px";
	this.obj.style.width = intNewWidth + "px";
	this.obj.style.height = intNewHeight + "px";
	// update internal pos
	this.x = intNewX;
	this.y = intNewY;
	this.width = intNewWidth;
	this.height = intNewHeight;
	// call again
	if (this.isMoving) {
		// update step
		this.stepIdx++;
		setTimeout(this.name + ".doMove();",this.boxStage.delay);
	} else {
		eval(this.callBack);
	}
}

function boxMoveTo(intNewX,intNewY,intSpeed,strCallBack) { 
	this.newX = intNewX;
	this.newY = intNewY;
	this.newWidth = this.width;
	this.newHeight = this.height;
	this.speed = intSpeed;
	this.callBack = strCallBack;
	// calculate moving attributes
	this.newDistance = Math.sqrt(Math.pow((this.newX - this.x),2) + Math.pow((this.newY - this.y),2));
	this.newXStep = (this.newX - this.x) / this.newDistance;
	this.newYStep = (this.newY - this.y) / this.newDistance;
	this.newWidthStep = 0;
	this.newHeightStep = 0;
	this.stepCount = Math.floor(this.newDistance / this.speed);
	this.stepIdx = 0;
	// check if we're already moving
		// alert("newX:" + this.newX + " newY:" + this.newY + " dist:" + this.newDistance + " xstep:" + this.newXStep + " ystep:" + this.newYStep);
	if (this.isMoving) {
		// do nothing, it'll take care of itself
	} else {
		// identify that we're moving
		this.isMoving = true;
		// call the move
		this.doMove();
	}
}

function boxMoveBy() {
}

function boxMoveHome() {
}

function boxStretch(intNewWidth,intNewHeight,strAnchorPoint,strDirection,intSpeed,strCallBack,bolThisIsOldCall) {
	//	if (!bolThisIsOldCall) { strDebug += this.name + "(" + strDirection + "), "; }
	// check if blocked
	if (eval(this.blocker)) {
		// if this is a brand new call
		if (!bolThisIsOldCall) {
			// if there was something already in the queue
			if (this.callWaiting.length != 0) {
				// write over the queue
				this.callWaiting[0] = "";
				this.callWaiting[1] = "";
				this.callWaiting[2] = intNewWidth;
				this.callWaiting[3] = intNewHeight;
				this.callWaiting[4] = strAnchorPoint;
				this.callWaiting[5] = strDirection;
				this.callWaiting[6] = intSpeed;
				this.callWaiting[7] = strCallBack;
				// but don't recall
			} else {
				// otherwise
				// write over the queue
				this.callWaiting[0] = "";
				this.callWaiting[1] = "";
				this.callWaiting[2] = intNewWidth;
				this.callWaiting[3] = intNewHeight;
				this.callWaiting[4] = strAnchorPoint;
				this.callWaiting[5] = strDirection;
				this.callWaiting[6] = intSpeed;
				this.callWaiting[7] = strCallBack;
				// recall
				setTimeout(this.name + ".stretch('','','','','','',true);",this.boxStage.delay);
			}
		} else {
			// otherwise, just recall it
			setTimeout(this.name + ".stretch('','','','','','',true);",this.boxStage.delay);
		}
	} else {
		// if this is a return call, grab the call waiting
		if (bolThisIsOldCall) {  
			// check if call waiting has been killed
			if (this.callWaiting.length  == 0) {
				// do nothing
			} else {
				// populate attributes from call waiting
				this.newWidth = new Number(this.callWaiting[2]);
				this.newHeight = new Number(this.callWaiting[3]);
				this.anchorPoint = this.callWaiting[4];
				this.direction = this.callWaiting[5];
				this.speed = new Number(this.callWaiting[6]);
				this.callBack = this.callWaiting[7];
				// clear the call waiting
				this.callWaiting = new Array();
			}
		} else {
			// immediately kill call waiting
			this.callWaiting = new Array();
			// populate attributes from the parameter calls
			this.newWidth = intNewWidth;
			this.newHeight = intNewHeight;
			this.anchorPoint = strAnchorPoint;
			this.direction = strDirection;
			this.speed = intSpeed;
			this.callBack = strCallBack;
		}
		// calculate moving attributes
		this.newDistance = Math.sqrt(Math.pow((this.newWidth - this.width),2) + Math.pow((this.newHeight - this.height),2));
		if (this.anchorPoint == "NW") {
			this.newX = this.x;
			this.newY = this.y;
			this.newXStep = 0;
			this.newYStep = 0;
			this.newWidthStep = (this.newWidth - this.width) / this.newDistance;
			this.newHeightStep = (this.newHeight - this.height) / this.newDistance;
		}
		if (this.anchorPoint == "NE") {
			this.newX = this.x - (this.newWidth - this.width);
			this.newY = this.y;
			this.newXStep = (this.newX - this.x) / this.newDistance;
			this.newYStep = 0;
			this.newWidthStep = (this.newWidth - this.width) / this.newDistance;
			this.newHeightStep = (this.newHeight - this.height) / this.newDistance;
		}
		if (this.anchorPoint == "SE") {
			this.newX = this.x - (this.newWidth - this.width);
			this.newY = this.y - (this.newHeight - this.height);
			this.newXStep = (this.newX - this.x) / this.newDistance;
			this.newYStep = (this.newY - this.y) / this.newDistance;
			this.newWidthStep = (this.newWidth - this.width) / this.newDistance;
			this.newHeightStep = (this.newHeight - this.height) / this.newDistance;
		}
		if (this.anchorPoint == "SW") {
			this.newX = this.x;
			this.newY = this.y - (this.newHeight - this.height);
			this.newXStep = 0;
			this.newYStep = (this.newY - this.y) / this.newDistance;
			this.newWidthStep = (this.newWidth - this.width) / this.newDistance;
			this.newHeightStep = (this.newHeight - this.height) / this.newDistance;
		}
		this.stepCount = Math.floor(this.newDistance / this.speed);
		this.stepIdx = 0;
		// check if we're already moving
		// alert("newWidth:" + this.newWidth + " newHeight:" + this.newHeight + " dist:" + this.newDistance + " wstep:" + this.newWidthStep + " hstep:" + this.newHeightStep);
		if (this.isMoving) { 
			// do nothing, it'll take care of itself
		} else {
			// identify that we're moving
			this.isMoving = true;
			// call the move
			this.doMove();
		}
	}
}


// ++++++++++
// BoxStage and associated functions for home page boxes
// ++++++++++

var matrix, box0, box1, box2, box3, box4, box5, box6;
var strDebug = "";
var intSpeed = 7;
if (window.ActiveXObject) {
	// speed it up for IE
	intSpeed = 15;
}
var bolBasePosition = true;
	
function fnInitBoxes() {
	matrix = new BoxStage("matrix");
	matrix.delay = 10;
	box0 = matrix.addBox("box0",document.getElementById("divPane1Background"));
	box1 = matrix.addBox("box1",document.getElementById("divPane1"));
	box2 = matrix.addBox("box2",document.getElementById("divPane2"));
	box3 = matrix.addBox("box3",document.getElementById("divPane3"));
	box4 = matrix.addBox("box4",document.getElementById("divPane4"));
	box5 = matrix.addBox("box5",document.getElementById("divPane5"));
	box6 = matrix.addBox("box6",document.getElementById("divPane6"));
	//matrix.monitor("strDebug","testing",100);
}
	
function fnStretchBox(intBoxId,strDir) {

	if (strDir == "on") {
		bolBasePosition = false;
	} else {
		bolBasePosition = true;
	}
	fnCheckSwags();

	if (intBoxId == 2) {
		if (strDir == "on") {
			box2.blocker = "(box4.direction == 'N') || (box4.direction == 'S') || (box6.direction == 'N') || (box6.direction == 'S')";
			box1.blocker = "(box4.direction == 'N') || (box4.direction == 'S') || (box6.direction == 'N') || (box6.direction == 'S')";
			box0.blocker = "(box4.direction == 'N') || (box4.direction == 'S') || (box6.direction == 'N') || (box6.direction == 'S')";
			box2.stretch(400,box2.origHeight,"NE","W",intSpeed,"fnOpenOverlay(2);",false);
			box1.stretch(box1.origWidth - (400 - box2.origWidth),box1.origHeight,"NW","W",intSpeed,"",false);
			box0.stretch(box0.origWidth - (400 - box2.origWidth),box0.origHeight,"NW","W",intSpeed,"",false);
		} else {
			fnCloseOverlay(2);
			box2.blocker = "(box4.direction == 'N') || (box4.direction == 'S') || (box6.direction == 'N') || (box6.direction == 'S')";
			box1.blocker = "(box4.direction == 'N') || (box4.direction == 'S') || (box6.direction == 'N') || (box6.direction == 'S')";
			box0.blocker = "(box4.direction == 'N') || (box4.direction == 'S') || (box6.direction == 'N') || (box6.direction == 'S')";
			box2.stretch(box2.origWidth,box2.origHeight,"NE","E",intSpeed,"",false);
			box1.stretch(box1.origWidth,box1.origHeight,"NW","E",intSpeed,"",false);
			box0.stretch(box0.origWidth,box0.origHeight,"NW","E",intSpeed,"",false);
		}
	}
	if (intBoxId == 3) {
		if (strDir == "on") {
			box3.blocker = "(box4.direction == 'N') || (box4.direction == 'S')";
			box4.blocker = "(box4.direction == 'N') || (box4.direction == 'S')";
			box3.stretch(470,box3.origHeight,"NW","E",intSpeed,"fnOpenOverlay(3);",false);
			box4.stretch(box3.origWidth - (470 - box4.origWidth),box4.origHeight,"SE","E",intSpeed,"",false);
		} else {
			fnCloseOverlay(3);
			box3.blocker = "(box4.direction == 'N') || (box4.direction == 'S')";
			box4.blocker = "(box4.direction == 'N') || (box4.direction == 'S')";
			box3.stretch(box3.origWidth,box3.origHeight,"NW","W",intSpeed,"",false);
			box4.stretch(box4.origWidth,box4.origHeight,"SE","W",intSpeed,"",false);
		}
	}
	if (intBoxId == 4) {
		if (strDir == "on") {
			box4.blocker = "(box3.direction == 'E') || (box3.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box1.blocker = "(box3.direction == 'E') || (box3.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box0.blocker = "(box3.direction == 'E') || (box3.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box4.stretch(box4.origWidth,240,"SE","N",intSpeed,"fnOpenOverlay(4);",false);
			box1.stretch(box1.origWidth,box1.origHeight - (240 - box4.origHeight),"NW","N",intSpeed,"",false);
			box0.stretch(box0.origWidth,box0.origHeight - (240 - box4.origHeight),"NW","N",intSpeed,"",false);
		} else {
			fnCloseOverlay(4);
			box4.blocker = "(box3.direction == 'E') || (box3.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box1.blocker = "(box3.direction == 'E') || (box3.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box0.blocker = "(box3.direction == 'E') || (box3.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box4.stretch(box4.origWidth,box4.origHeight,"SE","S",intSpeed,"",false);
			box1.stretch(box1.origWidth,box1.origHeight,"NW","S",intSpeed,"",false);
			box0.stretch(box0.origWidth,box0.origHeight,"NW","S",intSpeed,"",false);
		}
	}
	if (intBoxId == 5) {
		if (strDir == "on") {
			box5.blocker = "(box6.direction == 'N') || (box6.direction == 'S') || (box2.direction == 'E') || (box2.direction == 'W')";
			box6.blocker = "(box6.direction == 'N') || (box6.direction == 'S') || (box2.direction == 'E') || (box2.direction == 'W')";
			box5.stretch(210,box5.origHeight,"NW","E",intSpeed,"fnOpenOverlay(5);",false);
			box6.stretch(box5.origWidth - (210 - box6.origWidth),box6.origHeight,"SE","E",intSpeed,"",false);
		} else {
			fnCloseOverlay(5);
			box5.blocker = "(box6.direction == 'N') || (box6.direction == 'S') || (box2.direction == 'E') || (box2.direction == 'W')";
			box6.blocker = "(box6.direction == 'N') || (box6.direction == 'S') || (box2.direction == 'E') || (box2.direction == 'W')";
			box5.stretch(box5.origWidth,box5.origHeight,"NW","W",intSpeed,"",false);
			box6.stretch(box6.origWidth,box6.origHeight,"SE","W",intSpeed,"",false);
		}
	}
	if (intBoxId == 6) {
		if (strDir == "on") {
			box6.blocker = "(box5.direction == 'E') || (box5.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box2.blocker = "(box5.direction == 'E') || (box5.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box6.stretch(box6.origWidth,240,"SE","N",intSpeed,"fnOpenOverlay(6);",false);
			box2.stretch(box2.origWidth,box2.origHeight - (240 - box6.origHeight),"NW","N",intSpeed,"",false);
		} else {
			fnCloseOverlay(6);
			box6.blocker = "(box5.direction == 'E') || (box5.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box2.blocker = "(box5.direction == 'E') || (box5.direction == 'W') || (box2.direction == 'E') || (box2.direction == 'W')";
			box6.stretch(box6.origWidth,box6.origHeight,"SE","S",intSpeed,"",false);
			box2.stretch(box2.origWidth,box2.origHeight,"NW","S",intSpeed,"",false);
		}
	}
}

function fnOpenOverlay(int) {
	document.getElementById("divOverlay" + int).style.display = "";
}

function fnCloseOverlay(int) {
	document.getElementById("divOverlay" + int).style.display = "none";
}

function fnClickPane(strUrl,int) {
	if (document.getElementById("divOverlay" + int).style.display == "") {
		if (int == 5) {
			window.open(strUrl,"og","width=970,height=600");
		} else {
			self.location = strUrl;
		}
	}
}

function fnClickPaneSocial(strUrl,int,e) {
	if (document.getElementById("divOverlay" + int).style.display == "") {
		var panex = new Number(document.getElementById('divPane2').style.left.replace("px",""));
		var paney = new Number(document.getElementById('divPane2').style.top.replace("px",""));
		var posx = 0;
		var posy = 0;
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;
		}
		// check position against links
		if (((posx - panex) > 370) && ((posx - panex) < 407) && ((posy - paney) > 254) && ((posy - paney) < 300)) {
			window.open("http://www.facebook.com/westernstartruck","social1");
		}
		if (((posx - panex) > 407) && ((posx - panex) < 457) && ((posy - paney) > 254) && ((posy - paney) < 300)) {
			window.open("http://www.twitter.com/WstrnStarTrucks","social2");
		}
		if (((posx - panex) > 457) && ((posx - panex) < 517) && ((posy - paney) > 254) && ((posy - paney) < 300)) {
			window.open("http://www.youtube.com/serioustrucks","social3");
		}
		// self.location = strUrl;
	}
}

// ++++++++++
// Box Stage
// ++++++++++

function BoxStage(strName) {
	// name
	this.name = strName;
	// array to hold boxes
	this.boxes = new Array();
	// frame delay
	this.delay = 40;
	// methods
	this.addBox = boxstageAddBox;
	this.inMotion = boxstageInMotion;
	this.monitor = boxstageMonitor;
	// monitor params
	this.expression;
	this.div;
	this.monitorDelay;
	// make it
	return this;
}

function boxstageAddBox(strName,objDiv) {
	var obj = new Box(strName,objDiv,this);
	var idx = this.boxes.push(obj);
	obj.idx = idx;
	return obj;
}

function boxstageInMotion(strExceptionName) {
	var inMotion = false;
	if (strExceptionName) {
		for (var i = 0; i < this.boxes.length; i++) {
			if ((this.boxes[i].isMoving) && (this.boxes[i].name != strExceptionName)) {
				inMotion = true;
				break;
			}
		}
	} else {
		for (var i = 0; i < this.boxes.length; i++) {
			if (this.boxes[i].isMoving) {
				inMotion = true;
				break;
			}
		}
	}
	return inMotion;
}

function boxstageMonitor(strExpression,strDiv,strDelay) {
	this.expression = strExpression;
	this.div = strDiv;
	this.monitorDelay = strDelay;
	document.getElementById(strDiv).innerHTML = eval(strExpression);
	setTimeout(this.name + ".monitor('" + this.expression + "','" + this.div + "'," + this.monitorDelay + ");",this.monitorDelay);
}

// ++++++++++
// Builds an XML component 
// ++++++++++

function fnBuildXmlComponent(strDivName,docObj,strPathToSource,docToAppend,strStylesheet,bolAppendClientData) {
	// check if we already have data for this widget
	if ((docObj == undefined) && (strPathToSource != "")) {
		// no data yet, so go get some
		var conn = new oConnection();
		conn.sendMethod = "GET";
		conn.url = strPathToSource;
		try {
			docObj = conn.sendReceive(null);
		} catch(e) {
			alert("Missing or bad XML source: " + strPathToSource);
		}
	}
	// append doc 
	if (docToAppend) { 
		var root = docObj.documentElement;
		var node = docToAppend.documentElement;
		var nodeToAdd = node.cloneNode(true);
		root.appendChild(nodeToAdd);
	}
	// append client data
	if (bolAppendClientData) {
		var intHeight, intWidth;
		if (window.innerHeight) {
			intHeight = window.innerHeight;
			intWidth = window.innerWidth;
		} else {
			intHeight = document.body.clientHeight;
			intWidth = document.body.clientWidth;
		}	
		var strXml = '<Window width="' + intWidth + '" height="' + intHeight + '"/>';
		var newNode = docObj.createElement("Client");
		newNode.setAttribute("width",intWidth);
		newNode.setAttribute("height",intHeight);
		docObj.documentElement.appendChild(newNode);
	}
	// transform
	if (strDivName != "") {
		var trans = new oTransformer();
		trans.loadStylesheet(strPathToInterface + "/" + strStylesheet);
		var strHtml = trans.transformToHtml(docObj,document);
		document.getElementById(strDivName).innerHTML = strHtml;
	}
	return docObj;
}

function fnCreateXmlDoc(strRootTag, strContent) {
	var doc;
	var text = "";
	if (strRootTag) {
		text = "<" + strRootTag + ">" + strContent + "</" + strRootTag + ">";
	}
	if (window.DOMParser) {
		var parser=new DOMParser();
		doc = parser.parseFromString(text,"text/xml");
	} else {
		doc = new ActiveXObject("Microsoft.XMLDOM");
		doc.async = "false";
		doc.loadXML(text); 
	}
	return doc;
}

// ++++++++++
// General functions
// ++++++++++

var intFlashVersion = new Number(getFlashVersion().split(',').shift());

function getFlashVersion() {
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { axo.AllowScriptAccess = 'always'; }
			catch(e) { return '6,0,0'; }
		} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
		// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}
	}
	return '0,0,0';
}

// Resize functions

function fnResize() {
	if (bolResized) {
		docUI = undefined;
		docUI = fnBuildXmlComponent("divMain",docUI,"/_Configuration/UI.xml",doc,"Home.xsl",true);
		fnInitBoxes();
	}
	bolResized = false;
}

function fnResizeEngineering() {
	if (bolResized) {
		docCoreXml = undefined;
		docCoreXml = fnBuildXmlComponent("divMain",docCoreXml,"/_Core/EngineeringOverview.xml",docUI,"Engineering.xsl",true);
		fnInitMovingObjects();
	}
	bolResized = false;
}

// Social Menu

var bolSocialMenuIsClosing = false;

function fnOpenSocialMenu() {
	bolSocialMenuIsClosing = false;
	document.getElementById('divSocialMenu').style.display = ""; 
}

function fnCloseSocialMenu() { 
	if (bolSocialMenuIsClosing) {
		document.getElementById('divSocialMenu').style.display = 'none';
	}
}

// Truck Gallery

function fnChangeGallery(strName) { 
	var objGalleryExterior = document.getElementById("divGalleryExterior");
	var objGalleryInterior = document.getElementById("divGalleryInterior");
	var objGalleryVideos = document.getElementById("divGalleryVideos");
	var objGalleryExteriorTab = document.getElementById("divGalleryTabExterior");
	var objGalleryInteriorTab = document.getElementById("divGalleryTabInterior");
	var objGalleryVideosTab = document.getElementById("divGalleryTabVideos");
	// turn everything off
	objGalleryExterior.style.display = "none";
	objGalleryInterior.style.display = "none";
	objGalleryVideos.style.display = "none";
	objGalleryExteriorTab.className = "gallery-tab";
	objGalleryInteriorTab.className = "gallery-tab";
	objGalleryVideosTab.className = "gallery-tab";
	// turn the selected one on
	var objGallerySelected = document.getElementById("divGallery" + strName);
	var objGalleryTabSelected = document.getElementById("divGalleryTab" + strName);
	objGallerySelected.style.display = "";
	objGalleryTabSelected.className = "gallery-tab-on";
}

var strLastModelMedia = "";
var strLastModelMediaV = "";

function fnOpenModelMedia(strPath,intPos) {
	// fade background
	var divGD = document.getElementById("divGalleryDetailM");
	fnFade(divGD,"up",80);
	// clear image
	document.getElementById("imgGalleryDetail").src = "/_Interface/Images/Shim.gif";
	// open image pane and set image
	var strCropPath = strPath.substring(0,strPath.indexOf(".jpg")) + "Crop.jpg";
	document.getElementById("divGalleryDetail").style.display = "";
	document.getElementById("imgGalleryDetail").src = strCropPath;
	// close old caption
	if (strLastModelMedia != "") {
		document.getElementById("divCaption" + strLastModelMedia).style.display = "none";
	}
	// open caption
	var strCaption = strPath.replace(/\//g,'_');
	strCaption = strCaption.replace(/\./g,'_');
	document.getElementById("divCaption" + strCaption).style.display = "";
	strLastModelMedia = strCaption;
}

function fnCloseModelMedia(strId) {
	document.getElementById("divGalleryDetail").style.display = "none";
	document.getElementById("imgGalleryDetail").src = "/_Interface/Images/Shim.gif";
	document.getElementById("divCaption" + strLastModelMedia).style.display = "none";
	// fade background
	var divGD = document.getElementById("divGalleryDetailM");
	fnFade(divGD,"down",0);
}

function fnOpenModelMediaV(strPath,intPos) {
	// fade background
	var divGD = document.getElementById("divGalleryDetailM");
	fnFade(divGD,"up",80);
	// open image pane and set image
	var strMoviePath = strPath;
	document.getElementById("divGalleryDetailV").style.display = "";
	// set flash vars
	var flashvars = {};
	var stageW = 830;
	var stageH = 404;
	flashvars.videoPath = strPath;
	var params = {};
	params.scale = "noscale";
	params.allowfullscreen = "true";
	params.salign = "tl";
	params.bgcolor = "000000";
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("/_Flash/Video/video-player.swf", "flashDiv", stageW, stageH, "9.0.0", false, flashvars, params, attributes);
	// close old caption
	if (strLastModelMediaV != "") {
		document.getElementById("divCaption" + strLastModelMediaV + "V").style.display = "none";
	}
	// open caption
	var strCaption = strPath.replace(/\//g,'_');
	strCaption = strCaption.replace(/\./g,'_');
	document.getElementById("divCaption" + strCaption + "V").style.display = "";
	strLastModelMediaV = strCaption;
}

function fnCloseModelMediaV(strId) {
	document.getElementById("divGalleryDetailV").style.display = "none";
	// kill flash vars
	if (navigator.appName.indexOf("Microsoft") != -1) {
		window.flashDiv.sendToActionscript();
	} else {
		document.getElementById("flashDiv").sendToActionscript();
	}
	// swfobject.removeSWF("flashDiv");
	document.getElementById("divCaption" + strLastModelMediaV + "V").style.display = "none";
	// fade background
	var divGD = document.getElementById("divGalleryDetailM");
	fnFade(divGD,"down",0);
}

// Image Swap

function fnSwap(obj) {
	var strSrc = obj.src + "";
	if ((strSrc.indexOf("Shim.gif") < 0) && (strSrc.indexOf("At.") < 0)) {
		var strBaseSrc = strSrc.substring(0,strSrc.lastIndexOf("."));
		var strExtension = strSrc.substring(strSrc.lastIndexOf("."),strSrc.length);
		if (strBaseSrc.lastIndexOf("On") == (strBaseSrc.length - 2)) {
			obj.src = strBaseSrc.substring(0,strSrc.lastIndexOf("On")) + strExtension;
		} else {
			obj.src = strBaseSrc + "On" + strExtension;
		}
	}
}

// Home box and swag swap

var numImagesForHomePane1 = 5;
var curIndex = 1;
var intHomeSwapDelay = 8000;
var intHomeSwagADelay = intHomeSwapDelay + 2000;
var intHomeSwagBDelay = intHomeSwapDelay + 4000;

function fnHomeSwapPane1() {
	var pane1 = document.getElementById("divPane1");
	// clear swags
	var imgSwagA = document.getElementById("swag" + curIndex + "a");
	imgSwagA.style.display = "none";
	var imgSwagB = document.getElementById("swag" + curIndex + "b");
	imgSwagB.style.display = "none";
	// increment curIndex
	curIndex++;
	fnFade(pane1,"down",0);
	setTimeout("fnHomeSetPane1()",intHomeSwapDelay);
	setTimeout("fnHomeSetSwagA()",intHomeSwagADelay);
	setTimeout("fnHomeSetSwagB()",intHomeSwagBDelay);
}

function fnHomeSetPane1() {
	var pane1 = document.getElementById("divPane1");
	var strSrc = pane1.style.backgroundImage + "";
	var strBaseSrc = strSrc.substring(0,strSrc.lastIndexOf(".jpg"));
	var strExtension = strSrc.substring(strSrc.lastIndexOf(".jpg"),strSrc.length);
	// clear swags
	var imgSwagA = document.getElementById("swag" + curIndex + "a");
	imgSwagA.style.display = "none";
	var imgSwagB = document.getElementById("swag" + curIndex + "b");
	imgSwagB.style.display = "none";
	// increment curIndex
	if (curIndex == numImagesForHomePane1) {
		curIndex = 1;
	} else {
		curIndex++;
	}
	pane1.style.backgroundImage = strBaseSrc.substring(0,strBaseSrc.length - 1) + curIndex + strExtension;
	fnFade(pane1,"up",100);
	setTimeout("fnHomeSetPane1Background()",intHomeSwapDelay);
	setTimeout("fnHomeSetSwagA()",intHomeSwagADelay);
	setTimeout("fnHomeSetSwagB()",intHomeSwagBDelay);
}

function fnHomeSetPane1Background() {
	var pane1 = document.getElementById("divPane1");
	var pane1Background = document.getElementById("divPane1Background");
	var strSrc = pane1Background.style.backgroundImage + "";
	var strBaseSrc = strSrc.substring(0,strSrc.lastIndexOf(".jpg"));
	var strExtension = strSrc.substring(strSrc.lastIndexOf(".jpg"),strSrc.length);
	// clear swags
	var imgSwagA = document.getElementById("swag" + curIndex + "a");
	imgSwagA.style.display = "none";
	var imgSwagB = document.getElementById("swag" + curIndex + "b");
	imgSwagB.style.display = "none";
	// increment curIndex
	if (curIndex == numImagesForHomePane1) {
		curIndex = 1;
	} else {
		curIndex++;
	}
	pane1Background.style.backgroundImage = strBaseSrc.substring(0,strBaseSrc.length - 1) + curIndex + strExtension;
	fnFade(pane1,"down",0);
	setTimeout("fnHomeSetPane1()",intHomeSwapDelay);
	setTimeout("fnHomeSetSwagA()",intHomeSwagADelay);
	setTimeout("fnHomeSetSwagB()",intHomeSwagBDelay);
}

function fnHomeSetSwagA() {
	if (bolBasePosition) {
		var imgSwagA = document.getElementById("swag" + curIndex + "a");
		imgSwagA.style.display = "";
	}
}

function fnHomeSetSwagB() {
	if (bolBasePosition) {
		var imgSwagB = document.getElementById("swag" + curIndex + "b");
		imgSwagB.style.display = "";
	}
}

function fnCheckSwags() {
	var imgSwagA = document.getElementById("swag" + curIndex + "a");
	var imgSwagB = document.getElementById("swag" + curIndex + "b");
	// if (imgSwagA.style.display == "") {
	if (!bolBasePosition) {
		imgSwagA.style.display = "none";
		imgSwagB.style.display = "none";
	} else {
		imgSwagA.style.display = "";
		imgSwagB.style.display = "";
	}
}

// Object fade

var objFading = "";
var strFadingDir = "up";
var bolFading = false;
var intFadeDelay = new Number(150);
var numFadeStep = new Number(20);
var intTargetOpacity = new Number(0);

function fnFade(obj,strDir,intTarget) {
	strFadingDir = strDir;
	bolFading = true;
	objFading = obj;
	intTargetOpacity = intTarget;
	fnDoFade();
}

function fnDoFade() {
	if (bolFading) {
		var numCurOpacity = new Number(objFading.style.opacity + "");
		numCurOpacity = numCurOpacity * 100;
		var newOpacity = new Number(0);
		if (strFadingDir == "up") {
			if (numCurOpacity == 0) { objFading.style.display = ""; }
			newOpacity = Math.round(numCurOpacity + numFadeStep);
		} else {
			newOpacity = Math.round(numCurOpacity - numFadeStep);
			if (newOpacity <= 0) { objFading.style.display = "none"; }
		}
		if ((strFadingDir == "up") && (newOpacity >= intTargetOpacity)) {
			newOpacity = intTargetOpacity;
			bolFading = false;
		}
		if ((strFadingDir == "down") && (newOpacity <= intTargetOpacity)) {
			newOpacity = intTargetOpacity;
			bolFading = false;
		}
		objFading.style.opacity = (newOpacity / 100) + "";
		objFading.style.filter = "alpha(opacity=" + newOpacity + ")";
		setTimeout("fnDoFade();",intFadeDelay);
	}
}

// Engineering functions

function fnEngineeringOpenVocational(intClientWidth) {
	fnGoEngineering(0);
	document.getElementById("imgEngineeringSubtitle").style.display = "none";
	document.getElementById("divEngineeringButtons").style.display = "none";
	document.getElementById("imgEngineeringButtonHighway").style.display = "";
	document.getElementById("imgEngineeringButtonVocational").style.display = "none";
	document.getElementById("divText").style.display = "none";
	document.getElementById("divEngineeringVocationalOverlays").style.display = "";
	document.getElementById("divEngineeringHighwayOverlays").style.display = "none";
}

function fnEngineeringOpenHighway(intClientWidth) {
	fnGoEngineering(0 - (1959 - (intClientWidth - 150)));
	document.getElementById("imgEngineeringSubtitle").style.display = "none";
	document.getElementById("divEngineeringButtons").style.display = "none";
	document.getElementById("imgEngineeringButtonHighway").style.display = "none";
	document.getElementById("imgEngineeringButtonVocational").style.display = "";
	document.getElementById("divText").style.display = "none";
	document.getElementById("divEngineeringVocationalOverlays").style.display = "none";
	document.getElementById("divEngineeringHighwayOverlays").style.display = "";
}

function fnEngineeringBack(intClientWidth) {
	fnGoEngineering((0 - (1959 - (intClientWidth - 150))) / 2);
	document.getElementById("imgEngineeringSubtitle").style.display = "";
	document.getElementById("divEngineeringButtons").style.display = "";
	document.getElementById("imgEngineeringButtonHighway").style.display = "none";
	document.getElementById("imgEngineeringButtonVocational").style.display = "none";
	document.getElementById("divText").style.display = "";
	document.getElementById("divEngineeringVocationalOverlays").style.display = "none";
	document.getElementById('divEngineeringVocationalTruckHood').style.display = 'none';
	document.getElementById('divEngineeringVocationalTruck').style.display = '';
	document.getElementById("divEngineeringHighwayOverlays").style.display = "none";
	document.getElementById('divEngineeringHighwayTruckHood').style.display = 'none';
	document.getElementById('divEngineeringHighwayTruck').style.display = '';
}

// Main Menu functions

var bolOpening = false;
var bolOpened = false;
var bolClosing = false;
var bolClosed = true;
var bolWaitingToClose = false;
var bolMenuIsHideable = false;
var bolOnContainer = false;
var bolHidden = false;
var strLastMenuName = "";

function fnOpenMenu(strMenuName,objImg) {
	bolOpening = true;
	bolWaitingToClose = false;
	if ((bolClosing) || (bolClosed)) {
		bolClosing = false;
		bolClosed = false;
		fnGo();
		var objEdgeImg = document.getElementById("imgLeftMenuEdge");
		objEdgeImg.src = "/_Interface/Images/Shim.gif";
	}
	if (strLastMenuName != "") {
		document.getElementById("divMenu" + strLastMenuName).style.display = "none";
		// change menu image back
		fnSwap(document.getElementById("imgMenu" + strLastMenuName));
	}
	document.getElementById("divMenu" + strMenuName).style.display = "";
	// change menu image
	fnSwap(objImg);
	// store the menu name
	strLastMenuName = strMenuName;
}

function fnCloseMenu(strMenuName,objImg) {
	bolWaitingToClose = true;
	setTimeout("fnDelayCloseMenu()",250);
}

function fnDelayCloseMenu() {
	if (bolWaitingToClose) {
		bolOpening = false;
		bolOpened = false;
		bolClosing = true;
		fnGoBack();
		if (strLastMenuName != "") {
			document.getElementById("divMenu" + strLastMenuName).style.display = "none";
			// change menu image back
			fnSwap(document.getElementById("imgMenu" + strLastMenuName));
		}
		strLastMenuName = "";
	}
}

function fnFinishMenuAnimOpen() {
	bolOpening = false;
	bolOpened = true;
}

function fnFinishMenuAnimClose() {
	bolClosed = true;
	bolClosing = false;
	if (!bolOpening && !bolOpened) {
		var objEdgeImg = document.getElementById("imgLeftMenuEdge");
		objEdgeImg.src = "/_Interface/Images/LeftMenuOpenEdge.png";
	}
}

function fnUnHideMenu() {
	bolMenuIsHideable = true;
	bolHidden = false;
	var objMenuContainer = document.getElementById("divMenuContainer");
	var objMenuText = document.getElementById("divMenuText");
	var objClosedMenuArrow = document.getElementById("imgClosedMenuArrow");
	objMenuContainer.style.left = 0;
	objMenuText.style.display = "";
	objClosedMenuArrow.style.display = "none";
}

function fnHideMenu() {
	if ((!bolOnContainer) && (bolMenuIsHideable) && (!bolHidden)) {
		bolHidden = true;
		var objMenuContainer = document.getElementById("divMenuContainer");
		var objMenuText = document.getElementById("divMenuText");
		var objClosedMenuArrow = document.getElementById("imgClosedMenuArrow");
		objMenuContainer.style.left = "-137px";
		objMenuText.style.display = "none";
		objClosedMenuArrow.style.display = "";
	}
}

// News Bar

var divNews;
var intDivNewsMinimum = -1500;
var intSpaceStep = 2;
var intTimeStep = 60;

function fnStartNewsBar(strDiv) {
	divNews = document.getElementById(strDiv);
	setTimeout("fnMoveNewsBar()",5000);
}

function fnResetNewsBar() {
	divNews.style.left = "0px";
	setTimeout("fnMoveNewsBar()",3000);
}

function fnMoveNewsBar() {
	var intNewsLeft = new Number(divNews.style.left.replace("px",""));
	if (intNewsLeft > intDivNewsMinimum) {
		intNewsLeft = intNewsLeft - intSpaceStep;
		divNews.style.left = intNewsLeft + "px";
		setTimeout("fnMoveNewsBar()",intTimeStep);
	} else {
		setTimeout("fnResetNewsBar()",2000);
	}
}

// Media

var intLastMediaPos = 0;
var intLastMediaPosV = 0;

function fnOpenMedia(strPath,intPos) {
	var strCropPath = strPath.substring(0,strPath.indexOf(".jpg")) + "Crop.jpg";
	document.getElementById("divGalleryDetail").style.display = "";
	document.getElementById("imgGalleryDetail").src = strCropPath;
	document.getElementById("divCaption" + intPos).style.display = "";
	intLastMediaPos = intPos;
}

function fnCloseMedia(strId) {
	document.getElementById("divGalleryDetail").style.display = "none";
	document.getElementById("imgGalleryDetail").src = "/_Interface/Images/Shim.gif";
	document.getElementById("divCaption" + intLastMediaPos).style.display = "none";
}

function fnOpenMediaV(strPath,intPos) {
	// open image pane and set image
	var strMoviePath = strPath;
	document.getElementById("divGalleryDetailV").style.display = "";	
	// set caption
	document.getElementById("divCaption" + intPos + "V").style.display = "";
	intLastMediaPosV = intPos;
	// set flash vars
	var flashvars = {};
	var stageW = 830;
	var stageH = 404;
	flashvars.videoPath = strPath;
	var params = {};
	params.scale = "noscale";
	params.allowfullscreen = "true";
	params.salign = "tl";
	params.bgcolor = "000000";
	var attributes = {};
	swfobject.embedSWF("/_Flash/Video/video-player.swf", "flashDiv", stageW, stageH, "9.0.0", false, flashvars, params, attributes);
}

function fnCloseMediaV(strId) {
	document.getElementById("divGalleryDetailV").style.display = "none";
	// kill flash vars
	// swfobject.removeSWF("flashDiv");
	document.getElementById("divCaption" + intLastMediaPosV + "V").style.display = "none";
}


// OGMedia

var strLastOGMediaPos = "";

function fnOpenOGMedia(strUserName,strPath) {
	document.getElementById("divGalleryDetail").style.display = "";
	document.getElementById("imgGalleryDetail").src = "http://www.dtna-apps.com" + strPath;
	if (strLastOGMediaPos != "") {
		document.getElementById("divCaption" + strLastOGMediaPos).style.display = "none";
	}
	var strCaption = strPath.replace(/\//g,'');
	strCaption = strCaption.replace(/\./g,'');
	document.getElementById("divCaption" + strCaption).style.display = "";
	strLastOGMediaPos = strCaption;
}

function fnCloseOGMedia() {
	document.getElementById("divGalleryDetail").style.display = "none";
	document.getElementById("imgGalleryDetail").src = "/_Interface/Images/Shim.gif";
	document.getElementById("divCaption" + strLastOGMediaPos).style.display = "none";
}

// Parts Index

var strBrand = "Wst";
function fnOpenIndex() {
	var tempWin = window.open('http://www.sterling-apps.com/productindex/default.asp?Brand=' + strBrand,strBrand,'width=700,height=550,scrollbars=yes');
	tempWin.focus();
}

// STAF

function fnOpenStaf() {
	document.getElementById("divSTAFDarken").style.display = "";
	document.getElementById("divSTAF").style.display = "";
	document.getElementById("frmStafUrl").value = self.location;
}

function fnCloseStaf() {
	document.getElementById("divSTAFDarken").style.display = "none";
	document.getElementById("divSTAF").style.display = "none";
}

function fnSubmitStaf() {
	var bolSubmit = true;
	if (document.getElementById("frmStafName").value == "") { bolSubmit = false; }
	if (document.getElementById("frmStafTo").value == "") { bolSubmit = false; }
	if (document.getElementById("frmStafFrom").value == "") { bolSubmit = false; }
	
	if (bolSubmit) {
		document.frmStaf.submit();
		fnCloseStaf();
	} else {
		alert("Please confirm that you have entered values in all fields");
	}
}

// Spec Table

function fnSwapSpecTable(strConfig) {
	var strCurrentSpecTableConfig = "";
	if (document.getElementById("divSpecTableEX")) {
		if (document.getElementById("divSpecTableEX").style.display == "") {
			strCurrentSpecTableConfig = "EX";
		}
	}
	if (document.getElementById("divSpecTableSB")) {
		if (document.getElementById("divSpecTableSB").style.display == "") {
			strCurrentSpecTableConfig = "SB";
		}
	}
	if (document.getElementById("divSpecTableSF")) {
		if (document.getElementById("divSpecTableSF").style.display == "") {
			strCurrentSpecTableConfig = "SF";
		}
	}
	if (document.getElementById("divSpecTableXD")) {
		if (document.getElementById("divSpecTableXD").style.display == "") {
			strCurrentSpecTableConfig = "XD";
		}
	}
	if (document.getElementById("divSpecTableTS")) {
		if (document.getElementById("divSpecTableTS").style.display == "") {
			strCurrentSpecTableConfig = "TS";
		}
	}
	document.getElementById("divSpecTable" + strCurrentSpecTableConfig).style.display = "none";
	document.getElementById("divSpecTable" + strConfig).style.display = "";
	var imgLast = document.getElementById("imgSpecTableSelector" + strCurrentSpecTableConfig);
	var strSrc = imgLast.src;
	var strBaseSrc = strSrc.substring(0,strSrc.lastIndexOf("."));
	var strExtension = strSrc.substring(strSrc.lastIndexOf("."),strSrc.length);
	imgLast.src = strBaseSrc.substring(0,strSrc.lastIndexOf("_At")) + strExtension;
	imgLast = document.getElementById("imgSpecTableSelector" + strConfig);
	strSrc = imgLast.src;
	strBaseSrc = strSrc.substring(0,strSrc.lastIndexOf("."));
	strExtension = strSrc.substring(strSrc.lastIndexOf("."),strSrc.length);
	imgLast.src = strBaseSrc + "_At" + strExtension;
}

var strCurPackage = "Base";
var strCurView = "Dash";

// Color Table

function fnColorSwap(strPackage,strView) {
	document.getElementById("imgColorSampleThumb" + strCurView).style.border = "4px solid #ffffff";
	document.getElementById("imgColorArrow" + strCurPackage).src = "/_Interface/Images/Shim.gif";
	if (strPackage != " ") {
		strCurPackage = strPackage;
	}
	if (strView != " ") {
		strCurView = strView;
	}
	document.getElementById("imgColorSample").src = "/_Assets/Trucks/Highway/Sleepers/Color" + strCurView + strCurPackage + "Crop.jpg";
	document.getElementById("imgColorSampleThumb" + strCurView).style.border = "4px solid #a92426";
	document.getElementById("imgColorArrow" + strCurPackage).src = "/_Interface/Images/RedArrow.gif";
}

// App feature table

var strLastAppFeatureName = "none";

function fnSwapFeatureThumb(strName,strFirstAppFeatureName) {
	document.getElementById("featthumb" + strName).style.border = "2px solid #a92426";
	document.getElementById(strName).style.display = "";
	if (strLastAppFeatureName == "none") {
		strLastAppFeatureName = strFirstAppFeatureName;
	}
	document.getElementById("featthumb" + strLastAppFeatureName).style.border = "2px solid #e6e4e2";
	document.getElementById(strLastAppFeatureName).style.display = "none";
	strLastAppFeatureName = strName;
}

// OG

function fnSubmitOg() {
	var path = 	"default.asp";
	path +=		"?ogCat=" + document.ogform.ogCat.value;
	path +=		"&ogCountry=" + document.ogform.ogCountry.value;
	path +=		"&ogModel=" + document.ogform.ogModel.value;
	path +=		"&ogYear=" + document.ogform.ogYear.value;
	self.location = path;
}

// ++++++++++
// Moving objects
// ++++++++++

var stage = new Stage("stage",20);
var objBox1, objBox2, objBox3, objBox4, objBoxListing, objBoxSlider;

function fnGo() {
	objBox1.moveTo(0,0,1,true,"fnFinishMenuAnimOpen()");
}

function fnGoBack() {
	objBox1.moveTo(-854,0,1,true,"fnFinishMenuAnimClose()");
}

function fnGoCover() {
	objBox2.moveTo(0,169,1,true,"");
}

function fnGoEngine() {
	objBox3.moveTo(30,58,0.7,true,"");
	objBox4.moveTo(30,322,0.7,true,"");
}

function fnGoComponent() {
	objBox3.moveTo(30,0,0.7,true,"");
	objBox4.moveTo(30,0,0.7,true,"");
}

function fnGoEngineering(intXOffset) {
	objBoxEngineeringBackground.moveTo(intXOffset,0,1,true,"");
}

function fnInitMovingObjects() { 
	objBox1 = stage.addObject(document.getElementById("divMenuPanel"));
	if (document.getElementById("divCoverLayer")) {
		objBox2 = stage.addObject(document.getElementById("divCoverLayer"));
	}
	if (document.getElementById("imgEngine")) {
		objBox3 = stage.addObject(document.getElementById("imgEngine"));
		objBox4 = stage.addObject(document.getElementById("imgEngineShadow"));
	}
	if (document.getElementById("imgComponent")) { 
		objBox3 = stage.addObject(document.getElementById("imgComponent"));
		objBox4 = stage.addObject(document.getElementById("imgComponentShadow"));
	}
	if (document.getElementById("divPageSlider")) {
		objBoxSlider = stage.addObject(document.getElementById("divPageSlider"));
	}
	if (document.getElementById("divEngineeringBackground")) {
		objBoxEngineeringBackground = stage.addObject(document.getElementById("divEngineeringBackground"));
	}
}

function Stage(strName,intFramesPerSecond) {
	this.name = strName;
	this.framesPerSecond = intFramesPerSecond;
	this.delay = Math.ceil(1000 / intFramesPerSecond);
	this.objects = new Array();
	this.addObject = stageAddObject;
	this.drawObject = stageDrawObject;
}

function stageAddObject(objDiv) {
	var obj = new MovingObject(objDiv,this);
	var idx = this.objects.push(obj);
	obj.idx = idx;
	return obj;
}

function stageDrawObject(intIdx,strCallBack) { 
	obj = this.objects[intIdx - 1];
	if (obj.isMoving) { 
		if (obj.curFrame < obj.framesX.length) {
			// move it
			obj.obj.style.left = obj.framesX[obj.curFrame] + "px";
			obj.obj.style.top = obj.framesY[obj.curFrame] + "px";
			// update internal position
			obj.x = obj.framesX[obj.curFrame];
			obj.y = obj.framesY[obj.curFrame];
			// set for next frame
			obj.curFrame++;
			// call it again
			setTimeout(this.name + ".drawObject(" + obj.idx + ",'" + strCallBack + "')",this.delay);
		} else {
			// zero the current frame
			obj.curFrame = 0;
			// stop the object
			obj.isMoving = false;
			if (strCallBack != "") {
				eval(strCallBack);
			}
		}
	}
}

function MovingObject(objDiv,stage) { 
	this.obj = objDiv;
	this.stage = stage;
	this.x = new Number(this.obj.style.left.replace("px",""));
	this.y = new Number(this.obj.style.top.replace("px",""));
	this.framesX = new Array();
	this.framesY = new Array();
	this.isMoving = false;
	this.curFrame = 0;
	this.idx = "";
	this.move = moMove;
	this.moveTo = moMoveTo;
	this.moveToAndBounce = moMoveToAndBounce;
}

function moMove() {
}

function moMoveTo(intEndX,intEndY,intTime,bolBallistic,strCallBack) {
	// clear frame arrays
	this.framesX = new Array();
	this.framesY = new Array();
	// set current location
	var intStartX = this.x;
	var intStartY = this.y;
	// calculate number of frames
	var intNumFrames = Math.ceil(intTime * this.stage.framesPerSecond);
	// check if ballistic
	if (bolBallistic) {
		var accelX = (intEndX - intStartX) / (0.25 * (intTime * intTime));
		var accelY = (intEndY - intStartY) / (0.25 * (intTime * intTime));
		var posX, posY, intElapsedTime;
		var frameCounter = 0;
		for (var i = 0; i < (intNumFrames * 0.5); i++) {
			intElapsedTime = (intTime / intNumFrames) * frameCounter;
			posX = Math.round((0.5 * accelX * (intElapsedTime * intElapsedTime)) + intStartX);
			posY = Math.round((0.5 * accelY * (intElapsedTime * intElapsedTime)) + intStartY);
			this.framesX[i] = posX;
			this.framesY[i] = posY;
			frameCounter++;
		}
		frameCounter = 0;
		for (var i = intNumFrames - 1; i >= (intNumFrames * 0.5); i--) {
			intElapsedTime = (intTime / intNumFrames) * frameCounter;
			posX = intEndX - Math.round((0.5 * accelX * (intElapsedTime * intElapsedTime)));
			posY = intEndY - Math.round((0.5 * accelY * (intElapsedTime * intElapsedTime)));
			this.framesX[i] = posX;
			this.framesY[i] = posY;
			frameCounter++;
		}
	} else {
		for (var i = 0; i < intNumFrames; i++) {
			var posX = Math.round((((intEndX - intStartX) / intNumFrames) * i) + intStartX);
			var posY = Math.round((((intEndY - intStartY) / intNumFrames) * i) + intStartY);
			this.framesX[i] = posX;
			this.framesY[i] = posY;
		}
	}
	this.isMoving = true;
	this.curFrame = 0;
	// tell stage which object to draw
	this.stage.objBeingDrawn = this;
	// call stage to draw it
	this.stage.drawObject(this.idx,strCallBack);	
}

function moMoveToAndBounce(intEndX,intEndY,intTime,intBounce,bolBallistic,strCallBack) {
	// clear frame arrays
	this.framesX = new Array();
	this.framesY = new Array();
	// set current location
	var intStartX = this.x;
	var intStartY = this.y;
	// calculate number of frames
	var intNumFrames = Math.ceil(intTime * this.stage.framesPerSecond);
	// check if ballistic
	if (bolBallistic) {
		var accelX = (intEndX - intStartX) / (0.5 * (intTime * intTime));
		var accelY = (intEndY - intStartY) / (0.5 * (intTime * intTime));
		var posX, posY, intElapsedTime;
		var frameCounter = 0;
		for (var i = 0; i < intNumFrames; i++) {
			intElapsedTime = (intTime / intNumFrames) * frameCounter;
			posX = (0.5 * accelX * (intElapsedTime * intElapsedTime)) + intStartX;
			posY = (0.5 * accelY * (intElapsedTime * intElapsedTime)) + intStartY;
			this.framesX[i] = posX;
			this.framesY[i] = posY;
			frameCounter++;
		}
	} else {
		for (var i = 0; i < intNumFrames; i++) {
			var posX = (((intEndX - intStartX) / intNumFrames) * i) + intStartX;
			var posY = (((intEndY - intStartY) / intNumFrames) * i) + intStartY;
			this.framesX[i] = posX;
			this.framesY[i] = posY;
		}
	}
	// do the bounce
	
	// set params
	this.isMoving = true;
	this.curFrame = 0;
	// tell stage which object to draw
	this.stage.objBeingDrawn = this;
	// call stage to draw it
	this.stage.drawObject(this.idx);	
}

var intLeftMax = 0;

// slide page

function fnSlidePage(strDir,intPages,intMultiplier) { 
	var intCurPosition = objBoxSlider.x;
	var intDistance = 750;
	if (intMultiplier) {
		intDistance = intDistance * intMultiplier;
	}
	intLeftMax = 0 - ((intPages - 1) * 750);
	if (strDir == "right") {
		if (intCurPosition > intLeftMax) {
			intNewPosition = intCurPosition - intDistance;
		}
	} else {
		if (intCurPosition < 0) {
			intNewPosition = intCurPosition + intDistance;
		}
	}
	objBoxSlider.moveTo(intNewPosition,0,0.7,true,"fnSlidePageCheckArrows()");
}

function fnSlidePageCheckArrows() {
	var imgLeft = document.getElementById("imgBigArrowLeft");
	var imgRight = document.getElementById("imgBigArrowRight");
	var strSuffixLeft = "";
	var strSuffixRight = "";
	if (imgLeft.src.indexOf("On.") > 0) {
		strSuffixLeft = "On";
	}
	if (imgRight.src.indexOf("On.") > 0) {
		strSuffixRight = "On";
	}
	if (objBoxSlider.x <= intLeftMax) {
		imgRight.src = "/_Interface/Images/BigArrowRight.gif";
		imgRight.style.opacity = "0.1";
		imgRight.style.filter = "alpha(opacity=10)";
	} else {
		imgRight.src = "/_Interface/Images/BigArrowRight" + strSuffixRight + ".gif";
		imgRight.style.opacity = "1.0";
		imgRight.style.filter = "alpha(opacity=100)";
	}
	if (objBoxSlider.x >= 0) {
		imgLeft.src = "/_Interface/Images/BigArrowLeft.gif";
		imgLeft.style.opacity = "0.1";
		imgLeft.style.filter = "alpha(opacity=10)";
	} else {
		imgLeft.src = "/_Interface/Images/BigArrowLeft" + strSuffixLeft + ".gif";
		imgLeft.style.opacity = "1.0";
		imgLeft.style.filter = "alpha(opacity=100)";
	}
}

// ++++++++++
// Box Shift
// ++++++++++

var intReturnChange = 0;
var strReturnDirection = "n";
var strReturnBoxId = "";
var strReturnAffectedBoxId = "";

function fnBoxShiftReturn() {
	if (strReturnBoxId != "") {
		fnBoxShift(strReturnBoxId,intReturnChange,strReturnDirection,strReturnAffectedBoxId);
		strReturnBoxId = "";
		intReturnChange = 0;
		strReturnDirection = "n";
		strReturnAffectedBoxId = "";
	}
}

function fnBoxShift(strBoxId,intNewSize,strDirection,strAffectedBoxId) {
	var divBox = document.getElementById(strBoxId);
	var divBoxTop = new Number(divBox.style.top.replace("px",""));
	var divBoxLeft = new Number(divBox.style.left.replace("px",""));
	var divBoxHeight = new Number(divBox.style.height.replace("px",""));
	var divBoxWidth = new Number(divBox.style.width.replace("px",""));
	var divAffectedBox = document.getElementById(strAffectedBoxId);
	var divAffectedBoxTop = new Number(divAffectedBox.style.top.replace("px",""));
	var divAffectedBoxLeft = new Number(divAffectedBox.style.left.replace("px",""));
	var divAffectedBoxHeight = new Number(divAffectedBox.style.height.replace("px",""));
	var divAffectedBoxWidth = new Number(divAffectedBox.style.width.replace("px",""));
	var intChange = 0;
	if (strDirection == "n") {
		intChange = intNewSize - divBoxHeight;
		// set return
		intReturnChange = divAffectedBoxHeight;
		strReturnDirection = "s";
		strReturnBoxId = strAffectedBoxId;
		strReturnAffectedBoxId = strBoxId;
		// decrease top edge
		divBox.style.top = (divBoxTop - intChange) + "px";
		// increase height
		divBox.style.height = (divBoxHeight + intChange) + "px";
		// decrease affected box height
		divAffectedBox.style.height = (divAffectedBoxHeight - intChange) + "px";
	}
	if (strDirection == "e") {
		intChange = intNewSize - divBoxWidth;
		// set return
		intReturnChange = divAffectedBoxWidth;
		strReturnDirection = "w";
		strReturnBoxId = strAffectedBoxId;
		strReturnAffectedBoxId = strBoxId;
		// increase width 
		divBox.style.width = (divBoxWidth + intChange) + "px";
		// increase affected box left
		divAffectedBox.style.left = (divAffectedBoxLeft + intChange) + "px";
		// decrease affected box width
		divAffectedBox.style.width = (divAffectedBoxWidth - intChange) + "px";
	}
	if (strDirection == "s") {
		intChange = intNewSize - divBoxHeight;
		// set return
		intReturnChange = divAffectedBoxHeight;
		strReturnDirection = "n";
		strReturnBoxId = strAffectedBoxId;
		strReturnAffectedBoxId = strBoxId;
		// increase height
		divBox.style.height = (divBoxHeight + intChange) + "px";
		// increase affected box top
		divAffectedBox.style.top = (divAffectedBoxTop + intChange) + "px";
		// decrease affected  box height
		divAffectedBox.style.height = (divAffectedBoxHeight - intChange) + "px";
	}
	if (strDirection == "w") {
		intChange = intNewSize - divBoxWidth;
		// set return
		intReturnChange = divAffectedBoxWidth;
		strReturnDirection = "e";
		strReturnBoxId = strAffectedBoxId;
		strReturnAffectedBoxId = strBoxId;
		// decrease left
		divBox.style.left = (divBoxLeft - intChange) + "px";
		// increase width
		divBox.style.width = (divBoxWidth + intChange) + "px";
		// decrease affected box width
		divAffectedBox.style.width = (divAffectedBoxWidth - intChange) + "px";
	}
}

// ++++++++++
// Flash 
// ++++++++++

function fnDrawFlashObject(strPath) {
	var str = "";
	str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" type="application/x-shockwave-flash" data="' + strPath + '" width="100%" height="100%" style="visibility: visible; ">';
	str += '<param name="allowscriptaccess" value="always"/>';
	str += '<param name="bgcolor" value="#262422"/>';
	str += '<param name="menu" value="false"/>';
	str += '<param name="movie" value="' + strPath + '"/>';
	str += '<param name="wmode" value="opaque"/>';
	str += '<param name="flashvars" value="domain=*"/>';
	str += '<embed quality="high" bgcolor="#262422" width="100%" height="100%" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" src="' + strPath + '"></embed>';
	str += '</object>';
	return (str);
}



