/***********************************************
* 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.
***********************************************/
// with DST changes

SHIFT = 300;

function stringOrNothing(s) {
    if (typeof(s)=="undefined") { return ""; }
    return s;
}

function pausescroller(imgSrcsStr, titlesStr, idsStr, divId, divClass, delay){
   this.content = new Array(); //message array content
   var imgSrcs = imgSrcsStr.split(";");
   var titles = titlesStr.split(";");
   var ids = idsStr.split(";");
   for(i in imgSrcs){
      this.content[i] = '<table border="0" width="100%" class="dia"><tr><td align="center"><a href="/shop/product/' + stringOrNothing(ids[i]) + '"><img src="' + stringOrNothing(imgSrcs[i]) + '" width="110" alt="" border="0" /><br />' + stringOrNothing(titles[i]) +  '</a><br /><br /></td></tr></table>';
   }

	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.hiddendivpointer=2 //index of message array for hidden div
	document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'2">'+content[1]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'3">'+content[2]+'</div></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.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv1=document.getElementById(this.tickerid+"1")
this.visiblediv2=document.getElementById(this.tickerid+"2")
this.hiddendiv=this.hiddendiv=document.getElementById(this.tickerid+"3")

this.visiblediv1.innerHTML = this.content[0]
this.visiblediv2.innerHTML = this.content[1]
this.hiddendivpointer = 2
this.hiddendiv.innerHTML = this.content[scroller.hiddendivpointer]

this.visibledivtop1=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
this.visibledivtop2=parseInt(pausescroller.getCSSpadding(this.tickerdiv)) + SHIFT
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv1.style.width=this.visiblediv2.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop1*2)+"px"
this.getinline(this.visiblediv1, this.visiblediv2, this.hiddendiv)
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.visibledivtop2+5)){
this.visiblediv1.style.top=parseInt(this.visiblediv1.style.top)-5+"px"
this.visiblediv2.style.top=parseInt(this.visiblediv2.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.visiblediv2, this.hiddendiv, this.visiblediv1)
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(){
var tempcontainer=this.visiblediv1
this.visiblediv1=this.visiblediv2
this.visiblediv2=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2, div3){
div1.style.top=this.visibledivtop1+"px";
div2.style.top=this.visibledivtop2+"px";
div3.style.top=(2*SHIFT) + "px";
//div3.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// 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.visiblediv1.innerHTML = this.content[(i-1 < 0)? ceiling-1 : i-1]
this.visiblediv2.innerHTML = this.content[i]
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
}


function back() {
var i=scroller.hiddendivpointer
var ceiling=scroller.content.length
if (i - 3 >= 0) {
	v1 = i-3;
	v2 = i-2;
	h = i-1;
} else if (i - 3 == -1) {
	v1 = ceiling - 1;
	v2 = i-2;
	h = i-1;
} else if (i - 3 == -2) {
	v1 = ceiling - 2;
	v2 = ceiling - 1;
	h = i-1;
} else {
	v1 = ceiling - 3;
	v2 = ceiling - 2;
	h = ceiling - 1;
}

scroller.visiblediv1.innerHTML = scroller.content[v1]
scroller.visiblediv2.innerHTML = scroller.content[v2]
scroller.hiddendivpointer=h
scroller.hiddendiv.innerHTML=scroller.content[scroller.hiddendivpointer]
scroller.getinline(scroller.visiblediv2, scroller.hiddendiv, scroller.visiblediv1)
scroller.swapdivs()
}


function forward() {
var i=scroller.hiddendivpointer
var ceiling=scroller.content.length
scroller.visiblediv1.innetHTML = scroller.content[(i-1 < 0)? ceiling-1 : i-1]
scroller.visiblediv2.innetHTML = scroller.content[i]
scroller.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
scroller.hiddendiv.innerHTML=scroller.content[scroller.hiddendivpointer]
scroller.getinline(scroller.visiblediv2, scroller.hiddendiv, scroller.visiblediv1)
scroller.swapdivs()
}

