/* ANIMATION ON AN OBJECT 	*/
/* FADE TRANSITION		*/

if(!par) var par = ".";

var mjrTicker_Fade = function (pName) {
	/* ani{pName} */

	/* CONSTRUCTOR FOR mjrTicker_2By1 CLASS */
	/* NAMING CONVENTION: tck{pName} */
	/* VARIABLES */
	this.name		= pName;				// NAME OF THIS
	this.data 		= new Array(); 			// data array
	this.num		= 0;					// data offset
	this.objnum		= 1;					// object offset, start at 1
	this.objnum_o	= 0;					// interval
	this.interval 	= null;				// interval on each run

	/* TICKER DATA :: DEFAULT */
	this.itempertime 	= 2;					// how many items to appear per time
	this.displayTime 	= 1000;				// item display per time
	this.animDelay 	= 50;					// time to delay per scrolling
	this.animAmount = 5;
	
	/* TICKER ITEM */
	this.alphaPrev	= 0;
	this.alphaCur	= 0;
	
	this.objToShow	= null;
	this.objToHide	= null;
	
	/* TIMEOUTS */
	this.to_waitNextAni		= null;		// TIMEOUT TO WAIT FOR NEXT ANI
	
	/* OBJECT REFERENCES */
	this.objPrev	= null;
	this.objCur		= null;
	
	
	/* GLOBAL FUNCHOLDER */
	if(!window.FUNCHLD) window.FUNCHLD = new Array();
	var thisInd = window.FUNCHLD.length;
	window.FUNCHLD[thisInd] = this;
	

	// FIRSTRUN
	this.isFirstRun = true;
	
	
	this.objToKill	= null;

	/* START TICKER */
	this.start = function () {
		/* STARTS THE TICKER */
		/* INITIAL NUMBER: 0 */
		this.num = 0;
		
		// marks of error
		/*if(this.haserror) {
			alert("Warning: there is an error in the event setup. Please contact the webmaster for details.");
		}*/
		
		// -- REFERENCES TO OBJECTS */
		var objMain = document.getElementById("pnl" + this.name + "_Main");
		var objPut 	= document.getElementById("pnl" + this.name + "_Move");
		
		// -- INITIAL TOP OF objPut IS 0 px 
		//objPut.style.top = "-" + this.eachHeight + "px";
		
		// -- INITIAL objnum_o 
		this.objnum_o = this.objnum;
		
	
		// -- PLAY THE TICKER: BUT DELAY THE INITIAL PLAYING 
		this.addItem();
	}
	
	// -- STOP ALL ANIMATION
	this.stopAll = function() {
		clearTimeout(this.to_waitNextAni);
		if(this.objPrev)		
			if(this.objPrev.stopAll) 	this.objPrev.stopAll();
		if(this.objCur)
			if(this.objCur.stopAll) 	this.objCur.stopAll();
			
		FUNCHLD[thisInd] = undefined;

	}
	
	/* ADD NEW ITEM TO THE TICKER */
	this.addItem = function () {
		var objPut = document.getElementById("pnl" + this.name + "_Move");


		// -- JUST ADD THE OBJECT TO BE ANIMATED, DONE.
		this.insertNewItem(objPut);
		
		// -- WAIT UNTIL THE NEXT ANIMATION
		var t_timeOut = this.displayTime + ((100/this.animAmount)*this.animDelay);
		this.to_waitNextAni = setTimeout("FUNCHLD["+thisInd+"].addItem();", t_timeOut);
	}
	
	/* -- INSERT AN ITEM */
	this.insertNewItem = function(objPut) {
		// PROCESS THE CONTENT STRING
		// MADE BY MJR: MAY 20, 2008. THIS ONE WILL REPLACE THE TEXT CONTAINING IN <!--t:name--> TO this.data[n][name].
		/*	Example: 
			contentTemp = "<B><!--t:date--></B>";  data[n] = { date: 12 }
			will result in
			"<B>12</B>",
		*/
		var t_contentString = this.contentTemp;
		var t_curData = this.data[this.num];
		for(var t_indexName in t_curData) {
			t_contentString = t_contentString.split("<!--t:" + t_indexName + "-->").join(t_curData[t_indexName]);
		}
	
	
		// -- CREATE ITEM NODE 
		var t_temp;
		var newnode = document.createElement("LI");
		newnode.id 			= "pnl" + this.name + "__p" + this.objnum;
		newnode.className 	= this.contentClass;
		newnode.style.height	= (t_temp = this.eachHeight) ? t_temp : "";
		newnode.innerHTML 	= t_contentString;
		objPut.appendChild( newnode );

		
		// -- SET REF
		this.objPrev = this.objCur;
		this.objCur = newnode;

		
		
		// -- SET THE OBJECT TO SHOW
		// -- SET ANIMATION
		newnode.anim = new this.anim(newnode);
		newnode.anim.play();
	
		
		
		// -- INCREMENT THE OBJECT 
		this.objnum++;		// for the object id
		if(this.objnum>100) 
			this.objnum = 1;
			
		// -- GO TO NEXT DATA 
		this.num++;			// for the data
		if(this.num >= this.data.length) 
			this.num=0;
	}
	
	
	
	
	
	// ---------.---------.---------.---------.---------.
	// THIS WILL ANIMATE INDIVIDUAL OBJECTS, THOUGH
	var thisObj = this;
	this.anim = function(pObj) {
		this.parent 	= thisObj;			// PARENT FUNCTION
		this.obj		= pObj;			// OBJECT TO BE ANIMATED
		this.state		= 1;				// 1:SHOWN, 0:HIDDEN
		this.alpha		= 0;				// ALPHA :D
		
		this.intHolder	= 0;
		this.to_hide	= 0;				// TIMEOUT HOLDER FOR HIDING
		
		var thisInd		= 0;
		FUNCHLD[thisInd = FUNCHLD.length] = this;
	
		
		// -- PLAYS THIS MOVIE
		this.play = function() {this.show();}
		// -- STOP ALL
		this.stopAll = function() {
			clearInterval(this.intHolder);
			clearTimeout(this.to_hide);
			
			FUNCHLD[thisInd] = undefined;
		}
		
		// -- MAKE IT BE SHOWN.
		this.show = function() {
			clearInterval(this.intHolder);
			this.do__show();
			this.intHolder = setInterval("FUNCHLD["+thisInd+"].do__show();", this.parent.animDelay);
		}
		this.do__show = function() {
			this.alpha += this.parent.animAmount;
			if(this.alpha>100) {
				this.alpha = 100;
				clearInterval(this.intHolder);
				
				// -- NEXT ANIMATION: HIDE THE TICKER, TO BE DELAYED AS ASSIGNED BY PARENT OBJECT
				this.to_hide = setTimeout("FUNCHLD["+thisInd+"].hide();", this.parent.displayTime);
			}
			
			___setOpacity(this.obj, this.alpha);
			
		}
		
		
		// -- MAKE IT BE HIDDEN
		this.hide = function() {
			clearInterval(this.intHolder);
			this.intHolder = setInterval("FUNCHLD["+thisInd+"].do__hide();", this.parent.animDelay);
		}
		this.do__hide = function() {
			this.alpha -= this.parent.animAmount;
			if(this.alpha<0) {
				this.alpha = 0;
				clearInterval(this.intHolder);
				
				// -- WE WILL CLEAR THIS OBJECT FROM THE PARENT.
				var objParent = this.obj.parentNode;
				objParent.removeChild(this.obj);
			}
			
			___setOpacity(this.obj, this.alpha);
		}

						
	}
	
	
	
	
	// ---------.---------.---------.---------.---------.
	// -- 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);
	}
}
