//Image Fader: Works in Navigator 5+ & derivatives (Mozilla) and IE 4+

var execImgPath = "/resources/images/exec/";

function writeDiv(id, file, height, width, center) {
	var filterString;
	var centerString = "";
	var centerString1 = "";
	if(is.nav5up) filterString = "opacity: 0.2;";
	if(is.ie4) filterString = "filter:Alpha(opacity=20);";
	if(is.ie5up) filterString = "filter:progid:DXImageTransform.Microsoft.Alpha(opacity=20);"
	if(center) {
		centerString = "<div align=\"left\">";
		centerString1 = "</div>";
	}
	
	if(filterString)
		document.write(centerString + "<div id=\"" + id + "Img\" class=\"imgDiv\" style=\"height:" + height + ";background-image:url('" + execImgPath + file + "');" + filterString + "\"></div>" + centerString1);
	else
		document.write("<img src=\"" + execImgPath + file + "\" width=" + width + " height=" + height + "><p>");
}

//Image Fader Object

function imageFader(id, file, width, height, center) {
	this.id = id;
	this.maxWidth = width;
	this.maxHeight = height;
	this.center = center;
	writeDiv(id,file,height, this.maxWidth, center);
	
	if(is.ie5up || is.nav5up) {
		//alert(document.getElementById(this.id + "Img").style.height);
		this.style = document.getElementById(this.id + "Img").style
	}
	
	if(is.ie4) {
		this.alpha = eval(id + "Img.filters.Alpha");
		this.style = eval(this.id + "Img.style");
	}
	else if(is.ie5up) 
		{this.alpha = document.getElementById(id + "Img").filters("DXImageTransform.Microsoft.Alpha")}
	else if(is.nav5up) 
		{this.alpha = document.getElementById(id + "Img").style}
	
}
imageFader.prototype.fadeIn = fadeIn;
imageFader.prototype.fadeOut = fadeOut;
imageFader.prototype.init = init;
imageFader.prototype.getAlpha = getAlpha;
imageFader.prototype.setAlpha = setAlpha;
imageFader.prototype.setWidth = setWidth;
imageFader.prototype.getWidth = getWidth;
imageFader.prototype.setHeight = setHeight;
imageFader.prototype.getHeight = getHeight;
imageFader.prototype.getCellWidth = getCellWidth;
imageFader.prototype.getCellHeight = getCellHeight;
imageFader.prototype.inc = 10;
imageFader.prototype.slideInc = 3;
imageFader.prototype.bgLevel = 20;
imageFader.prototype.fgLevel = 100;
imageFader.prototype.speed = 30;

function setAlpha(level) {
	if (is.nav) this.alpha.opacity = level / 100;
	else this.alpha.opacity = level;
}

function getAlpha() {
	if (is.nav) return this.alpha.opacity * 100;
	else return this.alpha.opacity;
}

function fadeIn() {
var fading;
var sliding;
	if(!is.nav5 && !is.ie4up) return;
	
	clearTimeout(this.fadeOutTimer);
	clearTimeout(this.fadeInTimer);
	fading = (this.getAlpha() < this.fgLevel);
	hSliding = (this.getWidth() < this.maxWidth);
	vSliding = (this.getHeight() < this.maxHeight);
	
	if(fading) this.setAlpha(this.getAlpha() + this.inc);
	if(hSliding) this.setWidth(this.getWidth() + this.slideInc);
	if(vSliding) this.setHeight(this.getHeight() + this.slideInc);
	
	if(fading || hSliding || vSliding)
		this.fadeInTimer = setTimeout("faders." + this.id + ".fadeIn()",this.speed);
}

function fadeOut() {
	if(!is.nav5 && !is.ie4up) return;
	
	clearTimeout(this.fadeOutTimer);
	clearTimeout(this.fadeInTimer);
	fading = (this.getAlpha() > this.bgLevel);
	hSliding = (this.getWidth() > this.getCellWidth());
	vSliding = (this.getHeight() > this.getCellHeight());
	
	if(fading) this.setAlpha(this.getAlpha() - this.inc);
	if(hSliding) this.setWidth(this.getWidth() - this.slideInc);
	if(vSliding) this.setHeight(this.getHeight() - this.slideInc);
	
	if(fading || hSliding || vSliding)
		this.fadeOutTimer = setTimeout("faders." + this.id + ".fadeOut()",this.speed);
}

function getWidth() {
	return parseInt(this.style.width);
}

function getHeight() {
	return parseInt(this.style.height);
}

function setWidth(width) {
	this.style.width = width + "px";
}

function setHeight(height) {
	this.style.height = height + "px";
}

function getCellHeight() {
	offset = 50;
	if(this.center) offset = 70;
	
	if(is.ie5up || is.nav5up)
		return document.getElementById(this.id).offsetHeight - offset;
	if(is.ie4)
		return eval(this.id + ".offsetHeight") - offset;
}

function getCellWidth() {
	if(is.ie5up || is.nav5up)
		return document.getElementById(this.id).offsetWidth - 8;
	if(is.ie4)
		return eval(this.id + ".offsetWidth") - 8;
}

function init() {
	this.setWidth(this.getCellWidth());
	this.setHeight(this.getCellHeight());
}

function resize() {
	for(x in faders) {
		if (faders[x].id) faders[x].init();
	}
}

function test() {
	//mycell = document.getElementById("cPresCell");
	//cPresImg.style.width = 40;
	//alert(document.getElementById("cPresImg").style.top);
	alert(document.getElementById('cPres').offsetHeight);
}

// Faders collection:

function Faders() {}
Faders.prototype.add = addFader;
Faders.prototype.pasteLink = pasteLink;

function addFader(id, file, width, height, center) {
	this[id] = new imageFader(id, file, width, height, center);
}
function pasteLink(id) {
	text = "<img src=\"/resources/images/enlarge.gif\" width=\"20\" height=\"20\" border=\"0\" alt=\"Reveal Photo\">";
	document.write("<a href=\"#\" onmouseover=\"faders." + id + ".fadeIn()\" onmouseout=\"faders." + id + ".fadeOut()\" onclick=\"return false\">" + text + "</a>");
}

faders = new Faders();

window.onresize=resize;
runMisc = "resize();";