// TICKER 2 BY 1
// MARCO JONATHAN ROSSI
// 2007 JULY 12 - 

function mjrTicker_2By1() {
	// constructor for mjrTicker_2By1 Objec
	// variables
	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
	
	this.objToKill	= null;
	
	// functions
	this.start = function () {
		// STARTS THE TICKER
		
		// default
		// eachheight: height of ticker
		if(!this.eachheight) 	this.eachheight = 100; 		// height of each ticker item
		if(!this.itempertime) 	this.itempertime = 2;		// how many items to appear per time
		if(!this.displayTime) 	this.displayTime = 1000;	// item display per time
		if(!this.scrollDelay) 	this.scrollDelay = 50;		// time to delay per scrolling
		if(!this.scrollAmount)	this.scrollAmount = 5;		// amount of scrolling
		if(!this.idmain) 		this.haserror = true;		// how many items to appear per time
		if(!this.idsub) 		this.haserror = true;		// how many items to appear per time
		if(!this.name) 		this.haserror = true;		// how many items to appear per time
		
		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.");
		}
		
		// the creating of the lists
		objMain = document.getElementById(this.idmain);
		objput = document.getElementById("" + this.idsub + "_move");
		objput.style.top = "-" + this.eachheight + "px";
		this.objnum_o = this.objnum;
		
		// the first ticker items are inserted here
		for(rx=0; rx < this.itempertime + 1; rx++) {
			newnode = document.createElement("DIV");
			newnode.id = "" + this.idsub + this.objnum;
			newnode.className = "evtick_content";
			newnode.innerHTML = 
			  "<TABLE WIDTH=100% HEIGHT=100% CELLSPACING=0 CELLPADDING=0 BORDER=0><TD>" + 
				((this.header) ? this.header : "") +
				this.data[this.num] + 
				((this.footer) ? this.footer : "") +
			  "</TD></TABLE>";
			objput = document.getElementById("" + this.idsub + "_move");
			objput.appendChild(newnode);
			
			// object incrementing
			this.objnum++;		// for the object id
			if(this.objnum>100) 
				this.objnum = 1;
				
			this.num++;			// for the data
			if(this.num >= this.data.length) 
				this.num=0;
		}

		// let it play
		addItem = this.addItem;
		setTimeout(this.name + ".addItem();", this.itempertime);
	}
	
	this.addItem = function () {
		// adds new item to the ticker
		
		objMain = document.getElementById("" + this.idsub + "_move");
		
		//clear previous one
		objItem = document.getElementById("" + this.idsub + this.objnum_o); 
		objItem.style.display="none";
		objMain.style.top = "0px"; 
		/* modification */ 
		{
			this.objToKill = objItem;
		}
//		objMain.removeChild( objItem ); 

		this.objnum_o++;		// for the object id old
		if(this.objnum_o>100) 
			this.objnum_o = 1;
	
		// add the item
		newnode = document.createElement("DIV");
		newnode.id = "" + this.idsub + this.objnum;
		newnode.className = "evtick_content";
		newnode.innerHTML = 
		  "<TABLE WIDTH=100% HEIGHT=100% CELLSPACING=0 CELLPADDING=0 BORDER=0><TD>" + 
		      ((this.header) ? this.header : "") +
			this.data[this.num] + 
		      ((this.footer) ? this.footer : "") +
		  "</TD></TABLE>";
		objMain.appendChild( newnode );
		
		// object incrementing
		this.objnum++;		// for the object id
		if(this.objnum>100) 
			this.objnum = 1;
			
		this.num++;			// for the data
		if(this.num >= this.data.length) 
			this.num=0;
		clearInterval(this.interval);
		this.interval = setInterval(this.name + ".playTick();", this.scrollDelay);
	}
	
	this.playTick = function () {
		// plays the ticker
		objMain = document.getElementById("" + this.idsub + "_move");
		objtop = parseInt(objMain.style.top);
		if(isNaN(objtop)) objtop = 0;
		objtop -= this.scrollAmount;
		objMain.style.top = "" + objtop + "px";
		
		if(objtop <= -this.eachheight) {
			/* MODIFICATION */
			{
				if(this.objToKill) objMain.removeChild( this.objToKill );
			}
			objMain.style.top = "-" + this.eachheight + "px";
			clearInterval(this.interval);
			setTimeout(this.name + ".addItem();", this.displayTime);
		}
	}
}