var topHeadLinesChange ={
	ticks:"",
	thisTick:"",
	nextTick:"",
	state:"",
	current:0,
	delay:4500,
	speed:10,
	value:1,
	loopTimeOutPointer:'',
	faderTimeOutPointer:'',	
	navEnable:false,
	rotateNews:function(){
		for (i=0; i < this.ticks.length; i++) {
			if (i==0 && this.navEnable == false) {
				this.ticks[i].style.opacity = 1;
				this.ticks[i].style.filter = "alpha(opacity=100)";
			}else if(i == this.current && this.navEnable == true){
				this.ticks[i].style.opacity = 1;
				this.ticks[i].style.filter = "alpha(opacity=100)";
			}else {
				this.ticks[i].style.opacity = 0;
				this.ticks[i].style.filter = "alpha(opacity=0)";
				this.ticks[i].style.display = 'none';
			}
		}
		this.loopNews();
	},

	loopNews:function(){
		
		
		
		
		if(this.current >= this.ticks.length){ 
			this.current = 0;
		}
		this.thisTick = (this.nextTick)?this.nextTick:this.ticks[this.current];
		this.nextTick = (this.ticks[++this.current])?this.ticks[this.current]:this.ticks[this.current = 0];
		this.thisTick.style.display = "block";
		this.state = 'on';
		this.value = 1;
		this.chBackColor(this.current);
		if(this.navEnable == false)
			this.loopTimeOutPointer = window.setTimeout("topHeadLinesChange.fader()", this.delay);
	},

	fader:function(){
		if (this.state=='on') {
			this.value = this.value - 0.1;
			this.value = parseInt(this.value*100)/100;
			if (this.value >= 0) {
				this.thisTick.style.opacity = this.value;
				this.thisTick.style.filter = "alpha(opacity="+(this.value*100)+")";
				window.setTimeout("topHeadLinesChange.fader()",this.speed);
			} else {
				this.thisTick.style.display = "none";
				this.nextTick.style.display = "block";
				this.state='off';
				window.setTimeout("topHeadLinesChange.fader()", this.speed);
			}
		}else if (this.state=='off') {
			this.value = this.value + 0.1;
			this.value = parseInt(this.value*100)/100;
			if(this.value <= 1){
				this.nextTick.style.opacity = this.value;
				this.nextTick.style.filter = "alpha(opacity="+(this.value*100)+")";
				window.setTimeout("topHeadLinesChange.fader()",this.speed);
			} else {
				if(this.navEnable == false)
					this.loopNews();
			}
		}
	},
	
	chBackColor:function(n){
		if(n == 0)
			n=this.ticks.length;
		for(i=1;i<=this.ticks.length;i++){
			if (i==n)
				document.getElementById('newsTickP'+i).style.backgroundColor = '#B90000';
			else
				document.getElementById('newsTickP'+i).style.backgroundColor = '#1D2B60';
		}
	},
	goPage:function(n){
		clearTimeout(this.loopTimeOutPointer);
		this.nextTick = '';
		this.navEnable = true;
		this.current = n;
		this.rotateNews();
		var nav = document.getElementById('newsTickNav');
		nav.innerHTML = '&gt;';
		nav.style.backgroundColor = '#B90000';
		//alert(this.ticks[this.current].style.opacity);
	},
	playPause:function(e){
		if(e.val == 'pause'){
			clearTimeout(this.loopTimeOutPointer);
			this.navEnable = true;
			e.innerHTML = '&gt;';
			e.val = 'play';
			e.style.backgroundColor = '#B90000';
		}else if(e.val == 'play'){
			this.navEnable = false;
			e.innerHTML = 'II';
			e.val = 'pause';
			e.style.backgroundColor = '#1D2B60';
			this.fader();
		}
	},
	init:function(){
		// event listener
		var ticker = document.getElementById("topHeadlinesLu");
		this.ticks = ticker.getElementsByTagName("li");

		
		var tickerCol = document.getElementById('newsTickerToolbar');
		var ul = document.createElement('ul');
		ul.setAttribute('id', 'pageNums');

		var li = document.createElement('li');
		var a=document.createElement('a');
		a.setAttribute('id','newsTickNav');
		a.setAttribute('href','#');
		a.innerHTML = 'II';
		a.val = new Object('pause');
		a.onclick = function(){topHeadLinesChange.playPause(this); return false;};
		li.appendChild(a);
		ul.appendChild(li);
		var tickLen = (this.ticks.length +1);
		for (i=1;i<tickLen;i++){
			var li = document.createElement('li');
			var a=document.createElement('a');
			a.setAttribute('id','newsTickP'+i);
			a.setAttribute('href','#');
			a.val = new Object(i-1);
			a.innerHTML = i;
			a.onclick = function(){topHeadLinesChange.goPage(this.val); return false;};
			li.appendChild(a);
			ul.appendChild(li);
		}
		tickerCol.appendChild(ul);
		this.rotateNews();
		/*
		if(window.addEventListener) 
			window.addEventListener('load', function(){ticker2.rotateNews()}, false); // gecko, safari, konqueror and standard
		else if(document.addEventListener) 
			document.addEventListener('load', function(){ticker2.rotateNews}, false); // opera 7
		else if(window.attachEvent) { // win/ie
			window.attachEvent('onload', function(){ticker2.rotateNews});
		} else { // mac/ie5
		  if(typeof window.onload == 'function') {
			var existing = onload;
			window.onload = function() {
			  existing();
			  ticker2.rotateNews();
			}
		  } else {
			window.onload = function() {
			  ticker2.rotateNews();
			}
		  }
		}
		*/	
	}
}