/**
 *
 *	Newsticker class
 *
 */
 
 function $(e){
	 if (typeof e == 'object'){
		 return e;
	 }else if(document.getElementById(e)){
		 return document.getElementById(e);
	 }else{
		 return false;
	 }
 }
 
 Newsticker = function(id, interval){				// pass the UL element id
 
 		this.ul = document.getElementById(id);
 		if (this.ul){
			this.nodes = this.ul.getElementsByTagName('li');
			this.cloneLastNode();
			this.nodes = this.ul.getElementsByTagName('li');
			this.height = this.ul.offsetHeight;
			this.fx = [];
			this.fa = [];
			this.c = 0;
			//this.interval = interval * 1000;
			this.interval = interval * 999999999;
			this.buildFX();
			//window.setTimeout(bind(this, this.playNews), this.interval);		
 		}
 }
 
 Newsticker.prototype = {
	 
	 cloneLastNode : function(){
		 var node = this.nodes[0].cloneNode(true);
		 this.ul.appendChild(node);
	 },
	 
	 buildFX : function(){
		 
		 var n = 0;
		 for(;n<this.nodes.length;n++){
			 this.nodes[n].style.height = this.height + 'px';
			 this.nodes[n].style.overflow = 'hidden';
			 var fx = new joinkFX(this.nodes[n], 'outCubic', 40, 'height', ''+this.height, ''+0-this.height, false);
			 var fa = new Fader(this.nodes[n], 100, 0, 5);
			 fx.setFunc(bind(this, this.updateNext));
			 this.fx.push(fx);
			 this.fa.push(fa);
		 }
	 },
	
	resetPlay : function(){
		
		this.c = 0;
		var n = 0;
		for(;n<this.nodes.length;n++){
			this.nodes[n].style.height = this.height + 'px';
		}
		window.setTimeout(bind(this, this.playNews), this.interval);
		
	},
	
	 playNews : function(){
		 if (this.c < this.nodes.length){
		    this.fx[this.c].move();
		 	this.fa[this.c].fadeOut();			
		 }
	 },
	 
	 updateNext : function(){
		 this.fa[this.c].fadeIn();
		this.c++;
		if (this.c >= (this.nodes.length -1)){
			this.resetPlay();
		}else{
			window.setTimeout(bind(this, this.playNews), this.interval);	
		}
	 }
	
 }