// vars to store the animation timeouts - these are cleared to stop the animation when another one is started.
timelyrCursorTop = timelyrCursorBottom = boolCursorsUp = false;

// store the .left's and widths of the rollover states.
arLefts = new Array();
arLefts["news"] = new Array(492, 62);
arLefts["members"] = new Array(552, 88);
arLefts["mixes"] = new Array(639, 63);
arLefts["events"] = new Array(701, 70);

boolLoaded = false;

function initDHTML() {
	if(document.layers) {
		strShow = "show"; strHide = "hide";
	} else {
		strShow = "visible"; strHide = "hidden";
	}

	if(arLefts[strCurrentPage]) {
		document.getElementById("lyrCursorTop").style.left = document.getElementById("lyrCursorBottom").style.left = arLefts[strCurrentPage][0];
		document.getElementById("lyrCursorTop").style.width = document.getElementById("lyrCursorBottom").style.width = arLefts[strCurrentPage][1];
		clipTo("lyrCursorTop", 0, arLefts[strCurrentPage][1], 4, 0);
		clipTo("lyrCursorBottom", 0, arLefts[strCurrentPage][1], 4, 0);
		document.getElementById("lyrCursorTop").style.visibility = document.getElementById("lyrCursorBottom").style.visibility = strShow;
	}
	boolLoaded = true;
}

function mOver(strWhich) {
	if((arLefts[strCurrentPage]) && (boolLoaded)) {
		// if the objects are moving, stop them before running another animation.
		if(timelyrCursorTop) { clearTimeout(timelyrCursorTop); }
		if(timelyrCursorBottom) { clearTimeout(timelyrCursorBottom); }
		// the top one moves faster to the right, but the bottom one moves faster to the left.. just for kicks.
		var intTopSpeed = (parseInt(document.getElementById("lyrCursorTop").style.left) < arLefts[strWhich][0]) ? 3 : 4;
		var intBottomSpeed = (parseInt(document.getElementById("lyrCursorBottom").style.left) < arLefts[strWhich][0]) ? 4 : 3;
		// run the animation
		slide("lyrCursorTop", arLefts[strWhich][0], arLefts[strWhich][1], intTopSpeed);
		slide("lyrCursorBottom", arLefts[strWhich][0], arLefts[strWhich][1], intBottomSpeed);
	}
}

// generic slide/grow/shrink function. ignore last three arguments.
// call with: slide(id of object to slide, .left to slide to, clip width to set to, speed to slide)
function slide(strId, intLeft, intWidth, intSpeed, intStep, intNumSteps, intOriginalClip) {
	// setting the .left
	var objIn = document.getElementById(strId);
	var intCurLeft = parseInt(objIn.style.left);
	if(intLeft < intCurLeft) { intSpeed *= -1; } // moving to the left
	objIn.style.left = (((intCurLeft + intSpeed > intLeft) && (intSpeed > 0)) || ((intCurLeft + intSpeed < intLeft) && (intSpeed < 0))) ? intLeft : intCurLeft + intSpeed;
	// setting the clip
	if(arguments.length == 4) {
		intStep = 0;
		intNumSteps = Math.round(Math.abs(intCurLeft - intLeft) / Math.abs(intSpeed));
		intOriginalClip = getClip(strId, "r");
	}
	intStep++;
	var intAddToClip = Math.round(scale(intStep, 1, intNumSteps, Math.abs(intWidth - intOriginalClip)));
	if(intWidth < intOriginalClip) { intAddToClip *= -1; }
	var intNewClip = ((intOriginalClip + intAddToClip > intWidth) && (intWidth > intOriginalClip)) ? intWidth : intOriginalClip + intAddToClip;
	if(isNaN(intNewClip)) { intNewClip = intWidth }
	objIn.style.width = intNewClip;
	clipTo(strId, 0, intNewClip, 4, 0);
	
	if(((intCurLeft < intLeft) && (intSpeed > 0)) || ((intCurLeft > intLeft) && (intSpeed < 0))) {
		// store the timeout so it can be cleared to stop the animation.
		var strSlide = "slide('" + strId + "'," + intLeft + "," + intWidth + "," + Math.abs(intSpeed) + "," + intStep + "," + intNumSteps + "," + intOriginalClip + ")";
		eval("time" + strId + " = setTimeout(\"" + strSlide + "\", 10);")
	}
}

// a document.getElementById method for non-compliant browsers.
if(!document.getElementById) {
	document.getElementById = function(strId) {
		if(document.layers) {
			var objOut = document.layers[strId];
			objOut.style = objOut;
			return objOut;
		} else if(document.all) {
			return document.all[strId];
		}
	}
}

// scale() - scales a value to its relative position between two others.
function scale(intVal, intLowVal, intHighVal, intMaxVal) {
	if(intVal == intLowVal) {
		return 0;
	} else if(intVal == intHighVal) {
		return intMaxVal;
	} else {
		var intRatio = intMaxVal / (intHighVal - intLowVal);
		var scaledVal = (intVal * intRatio) - (intHighVal * intRatio) + intMaxVal;
		return scaledVal;
	}
}

// a generic function to retrieve the clipping properties of a layer.
function getClip(strId, side) {
	if(document.layers) {
		var objClip = document.layers[strId].clip;
		strClip = new Array(objClip.left, objClip.right, objClip.bottom, objClip.left);
	} else {
		var strClip = document.getElementById(strId).style.clip;
		strClip = strClip.split("rect(")[1].split(")")[0].split("px");
	}
	if(side == "t") return Number(strClip[0]);
	if(side == "r") return Number(strClip[1]);
	if(side == "b") return Number(strClip[2]);
	if(side == "l") return Number(strClip[3]);
}

// a generic function to set the clipping properties of a layer.
function clipTo(strWhich, intTop, intRight, intBottom, intLeft) {
	if(document.layers) {
		var objClip = document.layers[strWhich].clip;
		objClip.top = intTop;
		objClip.right = intRight;
		objClip.bottom = intBottom
		objClip.left = intLeft;
	} else {
		document.getElementById(strWhich).style.clip = "rect(" + intTop + "px " + intRight + "px " + intBottom + "px " + intLeft + "px)";
	}
}

// nn4 resize bug...
if(document.layers) {
	intOriginalWidth = window.innerWidth;
	intOriginalHeight = window.innerHeight;
}

// ...more nn4 resize bug
window.onresize = function() {
	if(document.layers) {
		if((intOriginalWidth != window.innerWidth) || (intOriginalHeight != window.innerHeight)) {
			window.location = window.location;
		}
	}
}

function popPhoto(intWidth, intHeight, strPhoto) {
	photoWindow = window.open("/events/photos.php?strPhoto=" + escape(strPhoto), "photoWindow", "width=" + intWidth + ",height=" + intHeight + ",resizable=no,status=yes");
	photoWindow.focus();
}