// H array
var arrH = [];
// H update state
var bolUpdateH = false;
// fnOnH
function fnOnH(obj) {
	obj.mode = "up";
	if (!obj.h_state) {
		obj.h_state = 0;
	}
	if (obj.h_state == 0) {
		arrH.push(obj);
	}
	if (!bolUpdateH) {
		bolUpdateH = true;
		fnUpdateH();
	}
}
// fnOffH
function fnOffH(obj) {
	obj.mode = "down";
	if (!bolUpdateH) {
		bolUpdateH = true;
		fnUpdateH();
	}
}
// fnUpdateH
function fnUpdateH() {
	if (bolUpdateH) {
		for (var i = 0; i < arrH.length; i++) {
			var obj = arrH[i];
			if (obj.mode == "up") {
				// check if it's not fully up
				if (obj.h_state < 6) {
					// move it up one
					obj.h_state++;
					fnDrawH(obj);
				}
			} else {
				// check if it's fully down
				if (obj.h_state == 0) {
					// remove it
					arrH.splice(i,1);
				} else {
					// move it down one
					obj.h_state--;
					// set color
					fnDrawH(obj);
				}
			}
		}
		if (arrH.length == 0) {
			bolUpdateH = false;
		}
		setTimeout("fnUpdateH()",200);
	}
}
// fnDrawH
function fnDrawH(obj) {
	if (obj.h_state == 0) { obj.style.backgroundColor = "#FFFFFF"; }
	if (obj.h_state == 1) { obj.style.backgroundColor = "#FFFDF0"; }
	if (obj.h_state == 2) { obj.style.backgroundColor = "#FFFAE0"; }
	if (obj.h_state == 3) { obj.style.backgroundColor = "#FFF7CF"; }
	if (obj.h_state == 4) { obj.style.backgroundColor = "#FEF5BE"; }
	if (obj.h_state == 5) { obj.style.backgroundColor = "#FFF2AC"; }
	if (obj.h_state == 6) { obj.style.backgroundColor = "#FEEF9A"; }
}
// fnSwap
function fnSwap(imgObj) {
	var strSrc = imgObj.src;
	var strPrefix = strSrc.substring(0,strSrc.lastIndexOf("."));
	var strSuffix = strSrc.substring(strSrc.lastIndexOf("."),strSrc.length);
	if (strSrc.indexOf("On.") > 0) {
		strPrefix = strPrefix.substring(0,strPrefix.lastIndexOf("On"));
		strSrc = strPrefix + strSuffix;
	} else {
		strSrc = strPrefix + "On" + strSuffix;
	}
	imgObj.src = strSrc;
}
// MovingObject
function MovingObject(strDirection,intDistance,intTime,intFramesPerSecond,bolBallistic,objDiv) {
	this.obj = objDiv;
	this.direction = strDirection
	this.ballistic = bolBallistic;
	this.startX = new Number(this.obj.style.left.replace("px",""));
	this.startY = new Number(this.obj.style.top.replace("px",""));
	if (strDirection == "N") {
		this.endX = this.startX;
		this.endY = this.startY - intDistance;
	}
	if (strDirection == "S") {
		this.endX = this.startX;
		this.endY = this.startY + intDistance;
	}
	if (strDirection == "E") {
		this.endX = this.startX + intDistance;
		this.endY = this.startY;
	}
	if (strDirection == "W") {
		this.endX = this.startX - intDistance;
		this.endY = this.startY;
	}
	this.framesX = new Array();
	this.framesY = new Array();
	var intNumFrames = Math.ceil(intTime * intFramesPerSecond);
	if (this.ballistic) {
		var accelX = (this.endX - this.startX) / (0.25 * (intTime * intTime));
		var accelY = (this.endY - this.startY) / (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 = (0.5 * accelX * (intElapsedTime * intElapsedTime)) + this.startX;
			posY = (0.5 * accelY * (intElapsedTime * intElapsedTime)) + this.startY;
			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 = this.endX - (0.5 * accelX * (intElapsedTime * intElapsedTime));
			posY = this.endY - (0.5 * accelY * (intElapsedTime * intElapsedTime));
			this.framesX[i] = posX;
			this.framesY[i] = posY;
			frameCounter++;
		}
	} else {
		for (var i = 0; i < intNumFrames; i++) {
			var posX = (((this.endX - this.startX) / intNumFrames) * i) + this.startX;
			var posY = (((this.endY - this.startY) / intNumFrames) * i) + this.startY;
			this.framesX[i] = posX;
			this.framesY[i] = posY;
		}
	}
	this.inMotion = false;
	this.inDirection = 1;
	this.curFrame = 0;
	this.tween = moTween;
}
// moTween
function moTween() {
	if (this.inMotion) {
		this.obj.style.left = this.framesX[this.curFrame];
		this.obj.style.top = this.framesY[this.curFrame];
		this.curFrame = this.curFrame + this.inDirection;
		if ((this.curFrame == this.framesX.length) || (this.curFrame == -1)) {
			this.inMotion = false;
			this.inDirection = this.inDirection * -1;
			this.curFrame = this.curFrame + this.inDirection;
		} 
	}
}
// fnMoveContacts
function fnMoveContacts() {
	if (objContacts.inMotion) {
		objContacts.tween();
		setTimeout("fnMoveContacts()",(intSecondsToMove/intFramesPerSecond) * 100);
	}
}
// fnCallMoveContacts
function fnCallMoveContacts() {
	objContacts.inMotion = true;
	fnMoveContacts();
}
// fnInitContactsPanel
var objContacts = "";
var intSecondsToMove = 3;
var intFramesPerSecond = 20;
function fnInitContactsPanel() { 
	objContacts = new MovingObject("E",240,intSecondsToMove,intFramesPerSecond,true,document.getElementById("contactsPanel"));
}
