var shaders = new Array();
function ShadeEffect(){
	this.ID = shaders.length;
	shaders[this.ID] = this;

	this.elemIds = new Array();
	this.selIndex = null;
	this.shadeTimer = null;
	this.selItem = null;
	this.nextItem = null;
	
	this.Add = function( elemId ){
		this.elemIds[this.elemIds.length] = elemId;
	}
	this.Init = function(){
		for( var i in this.elemIds ){
			this.SetOpacity(document.getElementById(this.elemIds[i]), 0);
		}
		this.selIndex = Math.floor( Math.random() * this.elemIds.length );
		this.SetOpacity(document.getElementById(this.elemIds[this.selIndex]), 100);
		if ( this.elemIds.length > 1 ){
		    this.shadeTimer = setTimeout( "shaders[" + this.ID + "].Shade(0)", 9000 );
	    }
	}
	this.SetOpacity = function(obj, opacity){
	    if ( obj != null )
	    {
	        obj.style.display = ( opacity == 0 ? "none" : "inline" );
		    obj.style.zIndex = ( opacity == 100 ? 100 : 99 );

		    if ( document.all ) {
			    for(var j = 0; j < obj.children.length; j++){
			    	if(obj.children[j].className == 'box'){
			    		//obj.children[j].style.filter = "alpha(opacity=" + 55 + ")";
			    	}
			    	else{	
					    obj.children[j].style.filter = "alpha(opacity=" + opacity + ")";			    
			    	}
			    	this.SetOpacity(obj.children[j], opacity);
			    }
		    }
		    else {
			    for(var j = 0; j < obj.childNodes.length; j++){
				    var child = obj.childNodes[j];
				    if ( child.style ){
					    child.style.MozOpacity = opacity / 100;
					    this.SetOpacity(child, opacity);
				    }
			    }
		    }
		}
	}
	this.Shade = function(opacity){
	    var nextIndex = ( this.selIndex == ( this.elemIds.length - 1 )) ? 0 : ( this.selIndex + 1 );
		if ( opacity <= 100 ){
			this.SetOpacity(document.getElementById(this.elemIds[this.selIndex]), ( 100 - opacity ));
			this.SetOpacity(document.getElementById(this.elemIds[nextIndex]), opacity );
			this.shadeTimer = setTimeout( "shaders[" + this.ID + "].Shade(" + ( opacity + 5 ) + ")", 50 );
		}
		else{
			this.selIndex = nextIndex;
			this.shadeTimer = setTimeout( "shaders[" + this.ID + "].Shade(0)", 9000 );
		}
	}
}