// (c) Xatcom.net
// Prohibida la copia o reproducción parcial o total
// Prohibido su uso sin licencia
function effectsClass() {
	this.IsMoz = ((navigator.appName).search("Microsoft")==-1) ? true : false;
	this.IDs = new Array();
	this.hTimers = new Array();
	this.fade = new Array();
	this.fade_prop = new Array();
	this.move = new Array();
	this.move_prop = new Array();
	this.size = new Array();
	this.size_prop = new Array();
	this.clip = new Array();
	this.clip_prop = new Array();
	this.onEnd = new Array();
	this.doEffect = function(i) {
		var obj = document.getElementById(this.IDs[i]);
		if (this.fade[i]) {
			var aux = 0.0, g=this.fade_prop[i][1], m=this.fade_prop[i][0];
			if (this.IsMoz) { aux = parseFloat(obj.style.opacity) + g; } else { aux = obj.filters["alpha"].opacity + g; }
			if ( ((g>0)&&(aux>m))||((g<=0)&&(aux<m)) ) { this.fade[i]=false; aux=m; }
			if (this.IsMoz) { obj.style.opacity = aux; } else { /*obj.style.filter = "Alpha(Opacity=" + aux.toString() + ")"*/ obj.filters["alpha"].opacity = aux; }
		}
		if (this.move[i]) {
			var x = 0.0, y = 0.0, sx=this.move_prop[i][2], sy=this.move_prop[i][3], mx=this.move_prop[i][0], my=this.move_prop[i][1];
			x = parseFloat(obj.style.left) + sx; y = parseFloat(obj.style.top) + sy;
			if ( ((sx>0)&&(x>mx))||((sx<0)&&(x<mx))||((sy>0)&&(y>my))||((sy<0)&&(y<my)) ) { this.move[i]=false; x=mx; y=my; }
			obj.style.left = Math.round(x).toString()+"px"; obj.style.top = Math.round(y).toString()+"px";
		}
		if (this.size[i]) {
			sw=this.size_prop[i][4], sh=this.size_prop[i][5], mw=this.size_prop[i][2], mh=this.size_prop[i][3];
			this.size_prop[i][0] += sw; this.size_prop[i][1] += sh;
			if ( ((sw>0)&&(this.size_prop[i][0]>mw))||((sw<0)&&(this.size_prop[i][0]<mw))||((sh>0)&&(this.size_prop[i][1]>mh))||((sh<0)&&(this.size_prop[i][1]<mh)) ) { this.size[i]=false; this.size_prop[i][0]=mw; this.size_prop[i][1]=mh; }
			obj.style.width = Math.round(this.size_prop[i][0]).toString()+"px"; obj.style.height = Math.round(this.size_prop[i][1]).toString()+"px";
		}
		if (this.clip[i]) {
			sw=this.clip_prop[i][4], sh=this.clip_prop[i][5], mw=this.clip_prop[i][2], mh=this.clip_prop[i][3];
			this.clip_prop[i][0] += sw; this.clip_prop[i][1] += sh;
			if ( ((sw>0)&&(this.clip_prop[i][0]>mw))||((sw<0)&&(this.clip_prop[i][0]<mw))||((sh>0)&&(this.clip_prop[i][1]>mh))||((sh<0)&&(this.clip_prop[i][1]<mh)) ) { this.clip[i]=false; this.clip_prop[i][0]=mw; this.clip_prop[i][1]=mh; }
			obj.style.clip = "rect(0px "+Math.round(this.clip_prop[i][0]).toString()+"px "+Math.round(this.clip_prop[i][1]).toString()+"px 0px)";
		}
		if ( (!this.fade[i]) && (!this.move[i]) && (!this.size[i]) && (!this.clip[i]) ) { clearInterval(this.hTimers[i]); this.IDs[i]=""; if (this.onEnd[i]!=null) this.onEnd[i](); }
	}
	this.getIndex = function(ID) {
		if (this.IDs.length==0) return -1;
		for (i=0; i<this.IDs.length; i++)
			if (this.IDs[i]==ID) return i;
		return -1;
	}
	this.getFreeIndex = function(ID) {
		var n = this.IDs.length;
		if (n==0) { this.IDs[0] = ID; return 0; }
		for (i=0; i<n; i++)
			if (this.IDs[i]=="") { this.IDs[i] = ID; return i; }
		this.IDs[n] = ID;
		return n;
	}
	this.Start = function(layer, effDesc, onEnd) {
		//arguments: [layer], [effect_description], [function_onEnd] (optional)
		var lst1 = new Array();
		var lst2 = new Array();
		var i=0, Index=0;
		var ef="";
		var dl=document.getElementById(layer);
		if (this.getIndex(layer)!=-1) return; //check if already exists
		effDesc = effDesc.replace(' ',''); //remove spaces
		if (effDesc.length<3) return; //check effect exists
		Index = this.getFreeIndex(layer);
		//set event
		if ( typeof onEnd=='undefined' ) { this.onEnd[Index] = null; } else { eval("this.onEnd[" + Index.toString() + "] = function() { " + onEnd + " }"); }
		lst1 = effDesc.split(";"); //get effects list
		for (i=0; i<lst1.length; i++) {
			if (lst1[i].length>0) {
			lst2 = lst1[i].split(":");
			ef = lst2[0];
			lst2 = lst2[1].split(",");
			if (ef=="fade") {
				this.fade[Index] = true;
				this.fade_prop[Index] = new Array();
				this.fade_prop[Index][0] = parseFloat(lst2[1]); //end
				this.fade_prop[Index][1] = 1.0*(this.fade_prop[Index][0]-parseFloat(lst2[0]))*55.0/parseFloat(lst2[2]); //step
				if (this.IsMoz) { dl.style.opacity = parseInt(lst2[0]); } else {
					this.fade_prop[Index][0] = this.fade_prop[Index][0]*100;
					this.fade_prop[Index][1] = this.fade_prop[Index][1]*100*1.3; //1.3 compensate slowdown of IE
					dl.style.filter = "alpha(opacity=" + (parseInt(lst2[0])*100).toString() + ")";
				}
			} else if (ef=="move") {
				this.move[Index] = true;
				this.move_prop[Index] = new Array();
				if (lst2.length==5) {
					this.move_prop[Index][0] = parseFloat(lst2[2]); //x2
					this.move_prop[Index][1] = parseFloat(lst2[3]); //y2
					dl.style.left = parseInt(lst2[0]); dl.style.top = parseInt(lst2[1]);
					this.move_prop[Index][2] = 1.0*(this.move_prop[Index][0]-parseFloat(lst2[0]))*55.0/parseFloat(lst2[4]); //step_x
					this.move_prop[Index][3] = 1.0*(this.move_prop[Index][1]-parseFloat(lst2[1]))*55.0/parseFloat(lst2[4]); //step_y
				} else if (lst2.length==3) {
					this.move_prop[Index][0] = parseFloat(dl.style.left) + parseFloat(lst2[0]); //x2
					this.move_prop[Index][1] = parseFloat(dl.style.top) + parseFloat(lst2[1]); //y2
					this.move_prop[Index][2] = 1.0*(this.move_prop[Index][0]-parseFloat(dl.style.left))*55.0/parseFloat(lst2[2]); //step_x
					this.move_prop[Index][3] = 1.0*(this.move_prop[Index][1]-parseFloat(dl.style.top))*55.0/parseFloat(lst2[2]); //step_y
				}
				if (!this.IsMoz) { this.move_prop[Index][2] = this.move_prop[Index][2]*1.3; this.move_prop[Index][3] = this.move_prop[Index][3]*1.3; }
			} else if (ef=="size") {
				this.size[Index] = true;
				this.size_prop[Index] = new Array();
				if (lst2.length==5) {
					for (i=0;i<4;i++) this.size_prop[Index][i] = parseFloat(lst2[i]); //w1 h1 w2 h2
					dl.offsetWidth = parseInt(lst2[0]); dl.offsetHeight = parseInt(lst2[1]);
					this.size_prop[Index][4] = 1.0*(this.size_prop[Index][0]-parseFloat(lst2[0]))*55.0/parseFloat(lst2[4]); //step_w
					this.size_prop[Index][5] = 1.0*(this.size_prop[Index][1]-parseFloat(lst2[1]))*55.0/parseFloat(lst2[4]); //step_h
				} else if (lst2.length==3) {
					var bw=0;
					this.size_prop[Index][0] = parseFloat(dl.offsetWidth); //w1
					this.size_prop[Index][1] = parseFloat(dl.offsetHeight); //h1
					if ( dl.style.borderWidth ) { bw -= parseInt(dl.style.borderWidth); }
					if ( dl.style.paddingLeft ) { this.size_prop[Index][0] -= parseInt(dl.style.paddingLeft) + bw; }
					if ( dl.style.paddingRight ) { this.size_prop[Index][0] -= parseInt(dl.style.paddingRight) + bw; }
					if ( dl.style.paddingTop ) { this.size_prop[Index][1] -= parseInt(dl.style.paddingTop) + bw; }
					if ( dl.style.paddingBottom ) { this.size_prop[Index][1] -= parseInt(dl.style.paddingBottom) + bw; }
					this.size_prop[Index][2] = this.size_prop[Index][0] + parseFloat(lst2[0]); //w2
					this.size_prop[Index][3] = this.size_prop[Index][1] + parseFloat(lst2[1]); //h2
					this.size_prop[Index][4] = 1.0*(this.size_prop[Index][2]-this.size_prop[Index][0])*55.0/parseFloat(lst2[2]); //step_w
					this.size_prop[Index][5] = 1.0*(this.size_prop[Index][3]-this.size_prop[Index][1])*55.0/parseFloat(lst2[2]); //step_h
				}
			} else if (ef=="clip") {
				this.clip[Index] = true;
				dl.style.overflow = "hidden";
				this.clip_prop[Index] = new Array();
				if (lst2.length==5) {
					for (i=0;i<4;i++) this.clip_prop[Index][i] = parseFloat(lst2[i]); //w1 h1 w2 h2
					dl.offsetWidth = parseInt(lst2[0]); dl.offsetHeight = parseInt(lst2[1]);
					this.clip_prop[Index][4] = 1.0*(this.clip_prop[Index][0]-parseFloat(lst2[0]))*55.0/parseFloat(lst2[4]); //step_w
					this.clip_prop[Index][5] = 1.0*(this.clip_prop[Index][1]-parseFloat(lst2[1]))*55.0/parseFloat(lst2[4]); //step_h
				} else if (lst2.length==3) {
					if (dl.style.clipRight && dl.style.clipBottom) {
						this.clip_prop[Index][0] = parseFloat(dl.style.clipRight); //w1
						this.clip_prop[Index][1] = parseFloat(dl.style.clipBottom); //h1
					} else {
						this.clip_prop[Index][0] = parseFloat(dl.offsetWidth); //w1
						this.clip_prop[Index][1] = parseFloat(dl.offsetHeight); //h1
					}
					this.clip_prop[Index][2] = parseFloat(lst2[0]); //w2
					this.clip_prop[Index][3] = parseFloat(lst2[1]); //h2
					this.clip_prop[Index][4] = 1.0*(this.clip_prop[Index][2]-this.clip_prop[Index][0])*55.0/parseFloat(lst2[2]); //step_w
					this.clip_prop[Index][5] = 1.0*(this.clip_prop[Index][3]-this.clip_prop[Index][1])*55.0/parseFloat(lst2[2]); //step_h
				}
			}
			}
		}
		this.hTimers[Index] = setInterval("effects.doEffect(" + Index + ")",33);
		//setTimeout("effects.doEffect(" + Index + ")",33);
	}
}
