// imghover.js
function img_hoverover(id) {
	var obj = document.getElementById(id);
	if (!obj) return;

	var cursrc = obj.src;
	var ext = cursrc.substring(cursrc.length-4,cursrc.length);
	obj.hotsrc = cursrc.substring(0,cursrc.length-(4+3)) + "_hi" + ext;
	obj.origsrc = cursrc;

	/* force the browser to load the hover image, so it's ready */
	obj.hotimg = new Image();
	obj.hotimg.src = obj.hotsrc;

	obj.onmouseover = function() {
		this.src = this.hotsrc;
	}
	obj.onmouseout = function() {
		this.src = this.origsrc;
	}
}

// alternate version if you want things to fade in/out on hover
function img_hoveroverfade(id) {
	var obj = document.getElementById(id);
	if (!obj) return;

	var cursrc = obj.src;
	var ext = cursrc.substring(cursrc.length-4,cursrc.length);
	obj.hotsrc = cursrc.substring(0,cursrc.length-(4+3)) + "_hi" + ext;
	obj.origsrc = cursrc;

	/* force the browser to load the hover image, so it's ready */
	obj.hotimg = new Image();
	obj.hotimg.src = obj.hotsrc;
	obj.hover = false;
	obj.hoverval = 0.6;

	/* MSIE: apply transparency filter */
	if (document.body.filters) {
		obj.style.filter =
			"progid:DXImageTransform.Microsoft.Alpha(enabled='true',style='0',opacity='60')";
	}
	else if (typeof(obj.style.opacity) != 'undefined') {
		/* apparently image objects cannot have CSS styles, so apply them to the parent */
		obj.parentNode.style.opacity = "0.6";
	}

	obj.onmouseover = function() {
		this.src = this.hotsrc;
		this.hover = true;
	}
	obj.onmouseout = function() {
		this.src = this.origsrc;
		this.hover = false;
	}
	obj.tick = function() {
		var updateMe=0;
		if (this.hover) {
			if (this.hoverval < 1.0) {
				updateMe=1;
				this.hoverval += 0.25;
				if (this.hoverval > 1.0)
					this.hoverval = 1.0;
			}
		}
		else {
			if (this.hoverval > 0.6) {
				updateMe=1;
				this.hoverval -= 0.025;
				if (this.hoverval < 0.6)
					this.hoverval = 0.6;
			}
		}

		if (updateMe) {
			/* does the browser support the CSS opacity way? */
			if (typeof(this.style.opacity) != 'undefined') {
				this.parentNode.style.opacity = this.hoverval;
			}
			/* how about the MSIE filter method? */
			else if (document.body.filters) {
				this.filters(0).opacity = this.hoverval * 100;
			}
		}
	}

	document.imagehoverfadeticklist.push(obj);
}

document.imagehoverfadeticklist = new Array();
document.imagehoverfadetick = function() {
	for (i=0;i < document.imagehoverfadeticklist.length;i++) {
		var obj = document.imagehoverfadeticklist[i];
		if (!obj) continue;
		obj.tick();
	}
}

setInterval("document.imagehoverfadetick();",75);

// fadein.js
function fadein_prepare(id) {
	var obj = document.getElementById(id);
	if (!obj) return;

	/* don't do "fade in" animation if the browser doesn't support transparency */
	if (typeof(obj.style.opacity) == 'undefined')
		return;

	obj.style.opacity = 0;
	obj.fadein = new Object();
	obj.fadein.prepared = true;
}

function fadein_go(id) {
	var obj = document.getElementById(id);
	if (!obj) return;
	if (typeof(obj.fadein) == 'undefined') return;
	if (!obj.fadein.prepared) return;

	obj.fadein.prepared = false;
	obj.fadein.param = 0;
	obj.fadein.speed = 0.05;
	obj.fadein.mom = obj;
	obj.fadein.action = function() {
		this.param += this.speed;
		this.mom.style.opacity = this.param.toString();
		if (this.param >= 1.0) {
			this.action = undefined;
			clearInterval(this.interval);
			this.interval = undefined;
		}
	}
	obj.fadein.interval = setInterval("obj=document.getElementById('" + id + "'); obj.fadein.action();",75);
}

// cmd.js
/* CMD login button code. */
function isSafari() {
	if (navigator.userAgent.indexOf("Mozilla") != -1 &&
	    navigator.userAgent.indexOf("Safari") != -1)
	    return true;

	return false;
}

function cmd_make_login_button(id) {
	var obj = document.getElementById(id);
	if (!obj) return;

	obj.myID = id;

	/* Safari screws up the placement and fonts of our login box,
	   so don't bother */
	if (isSafari()) return;

	var content = document.getElementById("content");
	if (!content) return;

	obj.loginBox = document.createElement("div");
	if (!obj.loginBox) return;
	obj.loginBox.style.visibility = "hidden";

	obj.loginBox.mom = obj;
	obj.loginBox.id = id + "_login";
	obj.loginBox.innerHTML = "<div align=right><form method=\"post\" action=\"http://www.impactstudiopro.com/videos/\">" +
		"<table border=0 cellpadding=0 cellspacing=4>" +
		"<tr valign=top><td style=\"font-family: arial; font-size: 16px; color: #4F4F4F;\">Video code:</td><td><input id=\"loginbox_vcode\" style=\"border: 1px #4F4F4F solid; width: 125px;\" type=text name=vcode></td></tr>" +
		"<tr valign=top><td style=\"font-family: arial; font-size: 16px; color: #4F4F4F;\">Password:</td><td><input  style=\"border: 1px #4F4F4F solid; width: 125px;\" type=password name=pass></td></tr>" +
		"<tr valign=top><td>&nbsp;</td><td align=right><input style=\"border: 1px #4F4F4F solid; color: #4F4F4F; background-color: white;\" type=submit name=go value=\" Go \"></td></tr>" +
		"</table>" +
		"</form></div>";
	obj.loginBox.style.position = "relative";
	obj.loginBox.style.left = 0;
	obj.loginBox.style.top = 0;
	obj.loginBox.style.textAlign = "right";
	obj.loginBox.alphaParam = 0;

	obj.loginBox.startTimer = function() {
		if (this.interval != undefined)
			return;
		this.interval = setInterval("obj=document.getElementById('" + this.mom.myID + "'); if (obj.loginBox.timerTick) obj.loginBox.timerTick();",200);
	}
	obj.loginBox.stopTimer = function() {
		if (this.interval == undefined)
			return;
		clearInterval(this.interval);
		this.interval = undefined;
	}
	obj.loginBox.isTimerRunning = function() {
		if (this.interval != undefined)
			return true;
		return false;
	}

	obj.hideLoginBox = function() {
		this.loginBox.timerTick = function() {
			if (typeof(this.style.opacity) != 'undefined') {
				this.alphaParam -= 0.1;
				if (this.alphaParam < 0) this.alphaParam = 0;
				this.style.opacity = this.alphaParam.toString();
				if (this.alphaParam <= 0) {
					this.style.position = "absolute";
					this.style.visibility = "hidden";
					this.style.width = "1px";
					this.style.height = "1px";
					this.style.overflow = "hidden";
					this.shown = false;
					this.stopTimer();
				}
			}
			else {
				this.style.position = "absolute";
				this.style.visibility = "hidden";
				this.style.width = "1px";
				this.style.height = "1px";
				this.style.overflow = "hidden";
				this.shown = false;
				this.stopTimer();
			}
		}
		this.loginBox.startTimer();
	}
	obj.showLoginBox = function() {
		this.loginBox.style.position = "relative";
		this.loginBox.style.visibility = "visible";
		this.loginBox.style.width = "";
		this.loginBox.style.height = "";
		this.loginBox.style.overflow = "";
		this.loginBox.shown = true;

		if (typeof(this.offsetParent) != 'undefined') {
			if (typeof(this.offsetParent.offsetLeft) != 'undefined')
				this.loginBox.style.width = this.offsetParent.offsetLeft + this.offsetParent.offsetWidth;
		}

		var o = document.getElementById("loginbox_vcode");
		if (o) o.focus();

		this.loginBox.timerTick = function() {
			if (typeof(this.style.opacity) != 'undefined') {
				this.alphaParam += 0.1;
				if (this.alphaParam > 1.0) this.alphaParam = 1.0;
				this.style.opacity = this.alphaParam;
				if (this.alphaParam >= 1.0) {
					this.stopTimer();
				}
			}
			else {
				this.stopTimer();
			}
		}
		this.loginBox.startTimer();
	}
	obj.hideLoginBox();

	content.appendChild(obj.loginBox);

	/* override the default behavior of the A HREF link,
	   so that it brings up an HTML form rather than going
	   directly to the page */
	obj.onclick = function() {
		if (this.loginBox.shown)
			obj.hideLoginBox();
		else
			obj.showLoginBox();
		return false;
	}
}
