// IE8 and before bug: an image pixel of #02050A renders as transparent when style filter:alpha specified.
// In addition to the code commented below, the image background color is set to #02050A to help mask the problem.
var TypeHaus;
if (!TypeHaus) TypeHaus = {};
TypeHaus.ImageRotator = function() {
	this.holdDuration = 2000;
	this.crossfadeDuration = 2000;
	this.images = document.getElementById("ImageRotatorImages").getElementsByTagName("img");
	this.indexCurr = Math.floor(Math.random() * this.images.length);
	var idx;
	if (TypeHaus.isMSIE) {
		for (idx=0; idx<this.images.length; ++idx)
			this.images[idx].style.filter = "alpha(opacity=0)";
		this.images[this.indexCurr].style.filter = null; // Circumvents filter:alpha #02050A transparency bug in IE
	}
	else {
		for (idx=0; idx<this.images.length; ++idx)
			this.images[idx].style.opacity = "0.0";
		this.images[this.indexCurr].style.opacity = "1.0";
	}
	this.IndexNextUpdate();
    this.state = 1;	
	this.StateTransition();
}
TypeHaus.ImageRotator.prototype.IndexNextUpdate = function() {
	this.indexNext = this.indexCurr + 1;
	if (this.indexNext >= this.images.length)
		this.indexNext = 0;
}
TypeHaus.ImageRotator.prototype.StateTransition = function() {
	switch(this.state) {
		case 1:
			this.state = 2;
			if (TypeHaus.isMSIE)
				this.images[this.indexCurr].style.filter = null; // Circumvents filter:alpha #02050A transparency bug in IE
		    setTimeout("TypeHaus.imageRotator.StateTransition();", this.holdDuration);
			break;
		case 2:
			this.state = 1;
			if (TypeHaus.isMSIE)
				this.images[this.indexCurr].style.filter = "alpha(opacity=100)"; // Spry.Effect.Fade needs filter:alpha restored in order to function
			this.faderCurr = new Spry.Effect.Fade(this.images[this.indexCurr], {duration:this.crossfadeDuration, from:100, to:0, fps:30, toggle:true} );
			this.faderNext = new Spry.Effect.Fade(this.images[this.indexNext], {duration:this.crossfadeDuration, from:0, to:100, fps:30, toggle:true, finish:function(element, effect) { TypeHaus.imageRotator.StateTransition(); } } );
			this.indexCurr = this.indexNext;
			this.IndexNextUpdate();
			setTimeout("TypeHaus.imageRotator.faderCurr.start();", 1);
			setTimeout("TypeHaus.imageRotator.faderNext.start();", 1);
			break;
	}
}
TypeHaus.BodyLoaded = function() {
	TypeHaus.isMSIE = /MSIE/.test(navigator.userAgent);
	TypeHaus.imageRotator = new TypeHaus.ImageRotator();
}
