/* ANIMATION ON AN OBJECT 	*/
/* FADE TRANSITION		*/

if(!par) var par = ".";
var animationFlashLike = function (pName) {
	/* ani{pName} */
	/* OBJECT NAMES 
	   *	pnl{pName}_btnc		- BUTTON CONTENT
	*/
	
	var parObj 		= window;
	this.name		= pName;
	
	/* TRANSITION */
	this.speed		= 50;		// INTERVAL IN MILISECONDS
	this.transition	= 1;		// TRANSITION TIME INTERVAL IN SECONDS
	this.animInt	= 10;		// INCREMENT OF ANIMATION
	
	this.num		= 0;		// CURRENT ACTIVE
	this.numP		= 0;		// PREVIOUS
	this.maxNum		= 1;		// MAX NUMBER: NUMBER OF ITEMS PRESENT
	
	this.obj_Opacity	= 0;		// OPACITY OF CURRENT OBJ
	this.objP_Opacity	= 0;		// OPACITY OF PREVIOUS OBJ

	this.isPlaying	= true;
	
	/* IMAGES */
	this.images 	= new Object();
	this.images.forSelectedButton 	= parObj.par + "/images/obj/jsfrontpg/btn_sel_1.gif";
	this.images.forUnselectedButton 	= parObj.par + "/images/obj/jsfrontpg/btn_sel_0.gif";
	this.images.forPlayButton		= parObj.par + "/images/obj/jsfrontpg/btn_play.gif";
	this.images.forPauseButton		= parObj.par + "/images/obj/jsfrontpg/btn_pause.gif";
	this.images.forSeparator		= parObj.par + "/images/obj/jsfrontpg/btnseparator.gif";
	
	
	/* PRIVATES */
	var ___intAnimation		= null;
	var ___animationFirstRun 	= false;	// IS ANIMATION FIRST RUN
	var ___toTransition		= null;	// TIME OUT TRANSITION HOLDER
	

	/* OTHERS */
	//this.hasButton		= false;
	
	
	/* GLOBAL FUNCHOLDER */
	if(!window.FUNCHLD) window.FUNCHLD = new Array();
	var thisInd;
	window.FUNCHLD[thisInd = window.FUNCHLD.length] = this;
	
	
	
	
	/* START ANIMATION */
	this.start = function () {
		___changePlayPause(true);
		this.changeItem();
	}
	
	/* GO TO PAGE IMMEDIATELY */
	this.switchTo = function (pNum, pStopPlaying) {
		var obj =  document.getElementById("pnl" + this.name + "_pg" + this.num);
		var objP = document.getElementById("pnl" + this.name + "_pg" + this.numP);

		/* DISAPPEARS THE OBJECT */
		var animObj = new Array(obj, objP);
		for(var i=0; i<animObj.length; i++) {
			if(animObj[i]) {
				animObj[i].style.display = "none";
				animObj[i].style.zIndex = 1;
			}
		}
		
		/* SET THE NUMBER */
		this.num = pNum;
		this.numP = this.num - 1;
		if(this.num < 1) this.num = this.maxNum;

		/* APPEARS THE APPROPRIATE OBJECT */
		var obj =  document.getElementById("pnl" + this.name + "_pg" + this.num);
		obj.style.zIndex = 5;
		obj.style.display = "";
		___setOpacity(obj,100);

		___switchButton();
		
		/* RESET ANIMATION */
		clearInterval(___intAnimation);
		clearTimeout(___toTransition);
		if(!pStopPlaying)  {
			// SET NEXT TRANSITION
			___changePlayPause(true);
			___toTransition = setTimeout("FUNCHLD["+thisInd+"].changeItem();", this.transition*1000);
		} else {
			___changePlayPause(false);
		}
	}
	
	
	/* PAUSE THE ANIMATION */
	this.pause = function () {
		clearInterval(___intAnimation);
		clearTimeout(___toTransition);
		
		// SWITCH
		___changePlayPause(false);
		
		// STOP TO CURRENT
		this.switchTo(this.num, true);
	}
	
	
	/* START TRANSITION */
	this.changeItem = function() {
		/* INCREMENT */
		this.setNextObj();
			
		___switchButton();

		/* START ANIMATION */
		clearInterval(___intAnimation);
		___animationFirstRun = true;
		___intAnimation = setInterval("FUNCHLD["+thisInd+"].___doChangeItem();", this.speed);
	}
	/* SET NEXT OBJ */
	this.setNextObj = function() {
		this.numP = this.num;
		this.num++;
		if(this.num > this.maxNum)
			this.num = 1;
	}
	
	
	/* DO THE ANIMATION */
	this.___doChangeItem = function() {
		var obj =  document.getElementById("pnl" + this.name + "_pg" + this.num);
		var objP = document.getElementById("pnl" + this.name + "_pg" + this.numP);

		/* RESET ALL */
		if(___animationFirstRun) {
			this.objP_Opacity = 100;
			this.obj_Opacity = 0;
		}
		
		/* SET OPACITY OF PREVIOUS OBJECT */
		if(objP) {
			// SET THE STACK ORDER
			if(___animationFirstRun)
				objP.style.zIndex = 4;
			if(this.objP_Opacity>0) {
				// DECREMENT OPACITY
				this.objP_Opacity -=  this.animInt;
				if(this.objP_Opacity<=0) {
					this.objP_Opacity = 0;
					objP.style.display = "none";
					objP.style.zIndex = 0;
				}
					
				// SET OPACITY
				___setOpacity(objP, this.objP_Opacity);
			}
		}
		
		
		/* SET OPACITY OF CURRENT */
		if(obj) {
			// SHOW THE OBJECT
			if(obj.style.display=="none");
				obj.style.display = "";
				
			// SET THE STACK ORDER
			if(___animationFirstRun)
				obj.style.zIndex = 5;
				
			// INCREMENT OPACITY
			this.obj_Opacity += this.animInt;
			if(this.obj_Opacity>=100) {
				this.obj_Opacity = 100;
				// CLEAR ANIMATION IF THE LIMIT HAS BEEN REACHED
				clearInterval(___intAnimation);
				clearTimeout(___toTransition);
				// SET NEXT TRANSITION
				___toTransition = setTimeout("FUNCHLD["+thisInd+"].changeItem();", this.transition*1000);
			}
				
			// SET OPACITY
			___setOpacity(obj, this.obj_Opacity);
		}
		
		/* SET ANIMATION FIRST RUN TO FALSE*/
		if(___animationFirstRun)
			___animationFirstRun = false;
	}
	
		
		
	/* TOGGLE PLAY */
	this.togglePlay = function () {
		if(this.isPlaying)
			this.pause();
		else
			this.start();
	}
	
	
	/* CREATE BUTTONS CHOOSER / INDICATOR */
	this.createButtons = function () {
		var t_IsFirstRun = true;
		var t_String = "";
		for(var rep=1; rep <= this.maxNum; rep++) {
			if(t_IsFirstRun)
				t_IsFirstRun = false;
			else
				t_String += "<IMG \nSRC='" + this.images.forSeparator + "' WIDTH=10 HEIGHT=15>";

			t_String += "<A HREF='#' ONCLICK='aniFrontPgAni.switchTo(" + rep + ", true); return false;'>" +
				"<IMG \nSRC='" + this.images.forUnselectedButton + "' HEIGHT=15 WIDTH=15 BORDER=0 ID='btn"+this.name +"_chs" + rep + "'></A>";
		}
		
		// PUT TO HTML
		var obj = document.getElementById("pnl" + this.name + "_btnc");
		obj.innerHTML = t_String;

	}
	
	/* PRIVATE FUNCTIONS */
	/* SET OPACITY */
	var ___setOpacity = function (pObj, pOpacity) {
		if(pObj.filters) {
			// -- CREATE OPACITY FILTER IF NOT EXISTS
			if(!pObj.filters["alpha"])
				pObj.style.filter = "alpha(opacity=" + pOpacity + ")";
			var objOpa = pObj.filters["alpha"];
			
			// -- SET OPACITY
			objOpa.Opacity = pOpacity;
			
			if(pOpacity == 100) 
				objOpa.Enabled = false;
			else
				objOpa.Enabled = true;
		}
		else
			pObj.style.opacity = (pOpacity/100);
	}
	
	/* SWITCH THE BUTTON */
	var thisObj = this;
	var ___prevBtnChoose = null;
	var ___switchButton = function () {
		var obj =  document.getElementById("btn" + thisObj.name + "_chs" + thisObj.num);
		
		/* CHANGE IMAGE */
		if(___prevBtnChoose)
			___prevBtnChoose.src = thisObj.images.forUnselectedButton;
		obj.src = thisObj.images.forSelectedButton;
		
		/* STORE REFERENCE TO PREVIOUS BUTTON */
		___prevBtnChoose = obj;
	}

	/* CHANGE PLAY/PAUSE */
	var ___changePlayPause = function(pIns) {
		var obj =  document.getElementById("btn" + thisObj.name + "_playpause");
		
		if(pIns==true) {
			obj.src = thisObj.images.forPauseButton;
			thisObj.isPlaying = true;
		}
		else if(pIns==false)  {
			thisObj.isPlaying = false;
			obj.src = thisObj.images.forPlayButton;
		}
	}

}



/* ---------.---------.---------.---------.---------. */
/* RANDOM JS ANI */
var animationFlashLike_Rand = function(pName) {
	var that = new animationFlashLike(pName);
	
	/* START TRANSITION */
	that.setNextObj = function() {
		/* INCREMENT */
		this.numP = this.num;
		do {
			this.num = Math.round(Math.random() * this.maxNum);
			
			if(this.num > this.maxNum)
				this.num = this.maxNum;
			else if(this.num < 1)
				this.num = 1;

		} while(this.numP == this.num);
		
	}
	
	// RETURNS OBJ
	return that;
}