/**
 * @namespace com.thesis.control.Shadow
 * @author 钟军锐 August.R@263.net
 */

/** @id Shadow */
function Shadow(oTarget,iOpacity,sDisplayMethod){
	if(!oTarget) return null;
	this.Target = oTarget;
	this.opacity = (typeof iOpacity == "number")? iOpacity : 1;
	this.style = (sDisplayMethod)? sDisplayMethod : "block";
	this.Interval = 50;
	this.Dispersion = 0;
	this.iTerminal = this.opacity;
	this.IntervalProcess = null;
	this.bAscend = true;
	
	
	if(typeof Shadow._initialized == "undefined"){
		Shadow._initialized = true;
		
		
		/** @id setOpacity */
		Shadow.prototype.setOpacity = function(iOpacity){
			this.opacity = (typeof iOpacity == "number")? iOpacity : 1;
			this.opacity = (this.opacity < 0)? 0 : (this.opacity > 1)? 1 : this.opacity ;
			this.Target.style.opacity = this.opacity;
			this.Target.style.filter = "Alpha(Opacity=" + this.opacity * 100 + ", Style=0);";
			if(this.opacity == 0 && this.Target.style.display != "none"){
				this.Target.style.display = "none";
			}
			else if(this.opacity > 0 && this.Target.style.display == "none"){
				this.Target.style.display = this.style;
			}
		};
		
		/** @id move */
		Shadow.prototype.move = function(Root){
			if((Root.bAscend && Root.opacity<Root.iTerminal) || (Root.bAscend==false && Root.opacity>Root.iTerminal)){
				Root.setOpacity(Root.opacity + Root.Dispersion);
			}
			else{
				clearInterval(Root.IntervalProcess);
			}
		};
		
		/** @id display */
		Shadow.prototype.display = function(iOpacity, iSecond){
			if(this.IntervalProcess)
				clearInterval(this.IntervalProcess);
			var Opcity = (typeof iOpacity == "number")? iOpacity : 1;
			Opcity = (Opcity < 0)? 0 : (Opcity >1)? 1 : Opcity;
			this.iTerminal = Opcity;
			var Second = (typeof iSecond == "number")? iSecond : 1000;
			Second = (Second < 100)? 100 : Second;
			this.Dispersion = (Opcity - this.opacity) / (Second / this.Interval);
			this.bAscend = Opcity > this.opacity;
			var Root = this;
			this.IntervalProcess = setInterval(function(){ Root.move(Root); }, this.Interval);
		};
		
		/** @id initialize */
		Shadow.prototype.initialize = function(Root){
			this.setOpacity(this.opacity);
		};
	}
	
	this.initialize(this);
}

