/***********************************************
* 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,n){
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=n//tuanpro, must greater than 1
this.hiddendivpointer=this.itempertime //index of message array for hidden div
this.widthone = 140 // width of one
//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="innerDiv" 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.topitem = 0 ;
this.hiddendivnumber = this.itempertime+1 ;

this.paddingtop   = parseInt(pausescroller.getCSSpadding(this.tickerdiv)) ;
this.visibiledivheight = parseInt(pausescroller.getCSSwidthheight(this.visiblediv, "height")) ;
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)){
	for (i=0; i<this.itempertime+1; i++)
	{
		document.getElementById(this.tickerid+(i+1)).style.top = parseInt(document.getElementById(this.tickerid+(i+1)).style.top)-5+"px";
	}
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
	this.topitem = (this.topitem<this.itempertime?(this.topitem+1):0) ;
	this.getinlineitems();
	//return ;
	this.swapdivs()
	setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// 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()
{
	this.hiddendiv=document.getElementById(this.tickerid+this.hiddendivnumber)
	this.hiddendivnextstop = parseInt(document.getElementById(this.tickerid+(this.hiddendivnumber>1?this.hiddendivnumber-1:this.itempertime+1)).style.top) ;
}

pausescroller.prototype.getinlineitems=function(){
	for (i=this.topitem; i<this.itempertime+1; i++)
	{
		document.getElementById(this.tickerid+(i+1)).style.top = (this.paddingtop*(i-this.topitem+1)+(this.visibiledivheight*(i-this.topitem)))+"px" ;
		//alert("a(" + this.topitem + ") : " + this.tickerid+(i+1) + "-" + document.getElementById(this.tickerid+(i+1)).style.top) ;
	}
	precount = this.itempertime+1-this.topitem ;
	for (i=0; i<this.topitem; i++)
	{
		document.getElementById(this.tickerid+(i+1)).style.top = (this.paddingtop*(precount+i+1)+(this.visibiledivheight*(precount+i)))+"px" ;
		//alert("b(" + this.topitem + ") : " + this.tickerid+(i+1) + "-" + document.getElementById(this.tickerid+(i+1)).style.top + "-" + this.paddingtop + "-" + (this.paddingtop*(precount+1))  +  "-" + this.visibiledivheight + "-"  + (this.visibiledivheight*(precount))) ;
	}
	/*
	if (from)
	{
		document.getElementById(this.tickerid+"1").style.top = (starttop*(this.itempertime+1)+(this.visibiledivheight*(this.itempertime)))+"px" ;
		//alert(this.tickerid+1 + "-" + document.getElementById(this.tickerid+"1").style.top) ;
	}
	*/
}

// -------------------------------------------------------------------
// 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.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.getCSSwidthheight=function(tickerobj, widthheight){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle[widthheight]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue(widthheight)
else
return 0
}
