/* ********************************	*/
/* TICKER FADER ~ MODIFIED ~	v3	*/
/* MARCO JONATHAN ROSSI			*/
/* 2008 FEB 18				*/
/* ********************************	*/

function mjrTicker_Fade(pName) {
	/* CONSTRUCTOR FOR mjrTicker_Fade CLASS */
	/* NAMING CONVENTION: tck{pName} */
	/* OBJECTS 
	   *	pnl{pName}_cont 		- CONTENT OF TICKER
	*/

	// variables
	this.data 		= new Array(); 			// data array
	this.name		= pName;				// NAME;
	this.num		= 0;					// data offset
	this.objnum		= 1;					// object offset, start at 1
	this.objnum_o	= 0;					// interval
	this.objopacity	= 0;
	this.fadedir	= 1;					// FADE DIRECTION
	this.returnFade	= false;				// RETURN FADE
	this.interval 	= null;				// interval on each run
	
	/* DEFAULT VALUES */
	this.eachheight 		= 100; 	// height of each ticker item
	//this.itempertime 	= 2;		// how many items to appear per time
	this.displayTime		= 1000;	// DISPLAY TIME
	this.fadespeed 		= 5;		// FADING SPEEC
	
	/* PRIVATE */
	this.___isFirstrun 	= true;				// FIRST RUN?
	
	
	/* START THE TICKER */
	this.start = function () {
		/* SET THE NUMBER OF DATA AVAILABLE. */
		this.num = this.data.length-1;
		
		// marks of error
		/* if(this.haserror) {
			alert("Warning: there is an error in the event setup. Please contact the webmaster for details.");
		} */
		this.changeItem();
	}


	/* ADDS THE NEW ITEM TO THE TICKER */
	this.changeItem = function () {
		/* FADE TRANSITION SETTINGS */
		/* FIRSTRUN */
		if(this.___isFirstrun || this.returnFade) {
			this.___isFirstrun = false;
			this.objopacity = -10;
			this.fadedir = -1;
		}
		/* SUCCEEDING */
		else {
			this.objopacity = 100;
			this.fadedir = -1;
		}
		
		/* PLAY THE TICKER */
		this.playTick();
		clearInterval(this.interval);
		this.interval = setInterval("tck" + this.name + ".playTick();",200);
	}
	
	/* DO THE ACTUAL CHANGING OF ITEMS */
	this.___doChangeItem = function () {
		/* CHANGE THE ITEM */
		var objPut = document.getElementById("pnl" + this.name + "_cont");
		objPut.innerHTML = 
			((this.header) ? this.header : "") +
			this.data[this.num] +
			((this.footer) ? this.footer : "");
		
		/* INCREMENT DATA */
		this.num++;
		if(this.num >= this.data.length) this.num=0;
		
		/* SET THE FADE TRANSITION */
		this.objopacity = 0;
		this.fadedir = 1;
		
		/* PLAY THE TRANSITION */
		this.playTick();
		clearInterval(this.interval);	// * bugfix
		this.interval = setInterval("tck" + this.name + ".playTick();",200);
	}
	
	/* PLAYS THE TICKER */	
	this.playTick = function () {
		var objPut = document.getElementById("pnl" + this.name + "_cont");
		
		/* ALPHA SET FOR MICROSOFT */
		if(objPut.filters) {
			objPut.style.filter = "alpha(opacity=" + this.objopacity + ")";	
		} 
		/* ALPHA SET FOR MOZILLA */
		else {
			objPut.style.opacity = (this.objopacity/100);
		}

		//alert(this.objopacity);

		//document.getElementById("status").innerHTML = this.objopacity;
		/* INCREMENT OPACITY */
		this.objopacity += this.fadespeed * this.fadedir;
		
		/* FADE SHOW THE TICKER */
		if(this.fadedir==1 && this.objopacity>100) {
			this.objopacity = 100;
			clearInterval(this.interval);
				
			/* SET THE NEXT DISPLAYITEM */
			setTimeout("tck" + this.name + ".changeItem();", this.displayTime) 
			// for the interval
			//this.fadedir = -1;
			//setTimeout(this.name+".interval = setInterval(\"" + this.name + ".playTick();\", 200);",5000) 
		} 
		
		/* FADE HIDE THE TICKER */
		else if (this.fadedir==-1 && this.objopacity<0) {
			this.objopacity = 0;
			this.fadedir = 1;
			clearInterval(this.interval);
			
			/* DO THE ACTUAL CHANGE OF ITEM */
			this.___doChangeItem();
		}  
	}
}