/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.itempertime=4//tuanpro, must greater than 1
this.hiddendivpointer=this.itempertime //index of message array for hidden div
this.widthone = 150 // width of one
this.spacebetween = 30 ;
//alert(content.length) ;

document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden">') ;

this.tickerdiv=document.getElementById(this.tickerid)
this.leftposition = Math.round((parseInt(pausescroller.getCSSwidthheight(this.tickerdiv, "width"))-this.widthone)/2) ;

for (i=0; i<=this.itempertime; i++)
{
	document.write('<div class="' + divId +'" style="position: absolute; width: 100%; '  + (i==this.itempertime?"visibility: hidden; ":"") + 'left:'  + this.leftposition +'" id="'+divId+(i+1) + '">' + content[i] + '</div>') ;
}

document.write('</div>');

	var scrollerinstance=this
	if (window.addEventListener) //run onload in DOM2 browsers
		window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
	else if (window.attachEvent) //run onload in IE5.5+
		window.attachEvent("onload", function(){scrollerinstance.initialize()})
	else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
	{	setTimeout(function(){scrollerinstance.initialize()}, 500) }
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function()
{

this.visiblediv=document.getElementById(this.tickerid+"1")
this.visibiledivheight = parseInt(pausescroller.getCSSheight(this.visiblediv, "height")) ;

this.topitem = 0 ;
this.hiddendivnumber = this.itempertime+1 ;

this.paddingtop   = parseInt(pausescroller.getCSSpadding(this.tickerdiv)) ;

this.visibledivtop = this.paddingtop ;


//document.getElementById(this.tickerid+"1").style.top = this.visibledivtop + "px" ;
//alert(document.getElementById(this.tickerid+"1").offsetHeight) ;
this.getinlineitems() ;
this.sethiddendiv() ;
//this.hiddendivnextstop = parseInt(document.getElementById(this.tickerid+this.itempertime).style.top) ;
//alert((this.tickerid+this.itempertime) + "-"  + this.hiddendivnextstop) ;
//return ;
//return ;
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)

//return ;
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function()
{
	var scrollerinstance=this
	if (parseInt(this.hiddendiv.style.top)>(this.hiddendivnextstop+5))
	{
		var elementheight ;
		var moveheight ;
		moveheight = 5 ;
		//milisecond
		for (i=0; i<this.itempertime+1; i++)
		{
			elementheight = parseInt(pausescroller.getCSSheight(document.getElementById(this.tickerid+(i+1)), "height")) ;
			//document.getElementById(this.tickerid+(i+1)).style.top = parseInt(document.getElementById(this.tickerid+(i+1)).style.top)-parseInt(elementheight/10)+"px";
			document.getElementById(this.tickerid+(i+1)).style.top = parseInt(document.getElementById(this.tickerid+(i+1)).style.top)-moveheight+"px";
		}
		setTimeout(function(){scrollerinstance.animateup()}, 50)
	}
	else
	{		
		this.topitem = (this.topitem<this.itempertime?(this.topitem+1):0) ;
		//return ;
		this.getinlineitems();
		//return ;
		this.swapdivs();
		//return ;
		setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
	}
}

pausescroller.prototype.getinlineitems=function()
{
	//parseInt(pausescroller.getCSSheight(this.visiblediv, "height")) ;
	var topnotpx ;
	var elementid ;
	var plus ;
	plus = 0 ;
	//alert('x') ;
	topnotpx = parseInt(this.paddingtop) ;
	//alert(top) ;
	//alert(this.topitem) ;
	var xxx ;
	xxx = "" ;
	for (i=this.topitem; i<this.itempertime+1; i++)
	{
		elementid = this.tickerid+(i+1) ;		
		//alert(this.tickerid + (i+1)) ;
		//document.getElementById(this.tickerid+(i+1)).style.top = (this.paddingtop*(i-this.topitem+1)+(this.visibiledivheight*(i-this.topitem)))+"px" ;
		xxx = xxx + "[" + elementid + "][" + topnotpx + "][" + document.getElementById(elementid).style.top + "]" ;
		//alert(xxx) ;
		
		document.getElementById(elementid).style.top = (topnotpx+plus) + "px" ;
		plus += this.spacebetween ;
		//return ;
		//alert(elementid + "-" + top + "-" + this) ;
		topnotpx = topnotpx + parseInt(pausescroller.getCSSheight(document.getElementById(elementid), "height")) ;
		xxx = xxx + "[" + topnotpx + "]["  +parseInt(pausescroller.getCSSheight(document.getElementById(elementid), "height")) + "]" ;
		//alert(top) ;
		//
	}
	//alert(xxx) ;
	//return ;
	precount = this.itempertime+1-this.topitem ;
	for (i=0; i<this.topitem; i++)
	{
		elementid = this.tickerid+(i+1) ;
		//document.getElementById(this.tickerid+(i+1)).style.top = (this.paddingtop*(precount+i+1)+(this.visibiledivheight*(precount+i)))+"px" ;
		document.getElementById(elementid).style.top = (topnotpx+plus) + "px" ;//"-200px" ;//(this.paddingtop*(precount+i+1)+(this.visibiledivheight*(precount+i)))+"px" ;
		//document.getElementById(elementid).style.display = 'none';
		topnotpx = topnotpx + parseInt(pausescroller.getCSSheight(document.getElementById(elementid), "height")) ;
		plus += this.spacebetween ;
		//alert(this.tickerid+(i+1) + "-" + document.getElementById(this.tickerid+(i+1)).style.top) ;
	}
	//return ;
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function()
{
	this.hiddendivnumber = (this.hiddendivnumber<this.itempertime+1?(this.hiddendivnumber+1):1) ;
	this.sethiddendiv() ;
}

pausescroller.prototype.sethiddendiv=function()
{
	var preelementid ;
	var preelementheight ;
	var topelementheight ;
	
	this.hiddendiv         = document.getElementById(this.tickerid+this.hiddendivnumber)
	//alert(this.tickerid+(this.hiddendivnumber>1?this.hiddendivnumber-1:this.itempertime+1)) ;
	//this.hiddendivnextstop = parseInt(document.getElementById(this.tickerid+(this.hiddendivnumber>1?this.hiddendivnumber-1:this.itempertime+1)).style.top) ;
	//alert(this.tickerid+(this.hiddendivnumber>1?this.hiddendivnumber-1:this.itempertime+1) + "-" + this.hiddendivnextstop) ;
	//return ;
	//alert('hidden [' + this.tickerid+this.hiddendivnumber + ']-top [' +  this.tickerid+(this.topitem+1) + ']' + 'next ' + this.hiddendivnextstop + "-" + 'top ' + parseInt(document.getElementById(this.tickerid+this.itempertime).style.top) + '-first item id ' + this.tickerid+(this.topitem+1) + '-height ' + parseInt(pausescroller.getCSSheight(document.getElementById(this.tickerid+(this.topitem+1)), "height")) + '-new next ' + (parseInt(document.getElementById(this.tickerid+this.itempertime).style.top)+parseInt(pausescroller.getCSSheight(document.getElementById(this.tickerid+(this.topitem+1)), "height")))) ;
	
	preelementid = this.tickerid+(this.hiddendivnumber>1?this.hiddendivnumber-1:this.itempertime+1) ;
	preelementheight = parseInt(pausescroller.getCSSheight(document.getElementById(preelementid), 'height')) ;
	topelementheight = parseInt(pausescroller.getCSSheight(document.getElementById(this.tickerid+(this.topitem+1)), "height")) ;
	//alert(preelementid + '-' + preelementheight + '-' + topelementheight) ;
	this.hiddendivnextstop = parseInt(document.getElementById(preelementid).style.top) + preelementheight-topelementheight ;
	
}



// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function()
{
	var scrollerinstance=this
	if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
		setTimeout(function(){scrollerinstance.setmessage()}, 100)
	else
	{
		var i=this.hiddendivpointer
		var ceiling=this.content.length
		this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
		this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
		//this.hiddendiv.style.display = '';
		this.animateup()
	}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}

pausescroller.getCSSheight=function(tickerobj, widthheight)
{ //get CSS padding value, if any
//alert(tickerobj.clientHeight) ;
//alert(tickerobj.currentStyle.height) ;// + '-' + window.getComputedStyle(tickerobj, "").getPropertyValue("height")) ;
if (tickerobj.currentStyle)
return tickerobj.clientHeight
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue(widthheight)
else
return 0
}

pausescroller.getCSSwidthheight=function(tickerobj, widthheight){ //get CSS padding value, if any
//alert(tickerobj.clientHeight) ;
//alert(tickerobj.currentStyle.height) ;// + '-' + window.getComputedStyle(tickerobj, "").getPropertyValue("height")) ;
if (tickerobj.currentStyle)
return tickerobj.currentStyle[widthheight]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue(widthheight)
else
return 0
}