
var bridgepath="/interface/article_api.php"

function formatrssmessage(divid, msgnumber, linktarget){
	var rsscontent=rsscontentdata[divid][msgnumber];
	if(null != rsscontent && null != rsscontent.link && null != rsscontent.title){
		var linktitle='<span class="rsstitle"><a href=javascript:openPage("'+unescape(rsscontent.link)+'") target="'+linktarget+'">'+unescape(rsscontent.title)+'</a></span>';
	}else{
		var linktitle='';
	}
	return linktitle;
}

//////NO NEED TO EDIT BEHIND HERE///////////////////////////

var rsscontentdata=new Array() 

//Articlepausescroller(RSS_id, divId, divClass, delay, linktarget, optionalswitch)

function Articlepausescroller(RSS_id, divId, divClass, delay, linktarget){
	this.tickerid=divId //ID of ticker div to display information
	this.delay=delay //Delay between msg change, in miliseconds.
	this.linktarget=(typeof linktarget!="undefined")? linktarget : ""
	this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
	this.hiddendivpointer=1 //index of message array for hidden div
	this.js_is_loaded=0
	this.run=false
	this.number_of_tries=0
	document.write('<div id="'+divId+'" class="'+divClass+'"style="position:relative;overflow:hidden;"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1"><span style="position: absolute"></span></div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2"></div></div>')
	var parameters="divid="+divId
	Articlepausescroller.getXMLcontentJS(bridgepath+"?"+parameters)
}


// start scroller
Articlepausescroller.prototype.startScroller=function(){
	this.run = true
	this.do_onjsload()
}

// stop scroller
Articlepausescroller.prototype.stopScroller=function(){
	this.run = false
	this.do_unjsload()
}

// -------------------------------------------------------------------
// do_onjsload()- Checks if external JS containing RSS feed is loaded yet
// -If not, continue to check until yes, or abort after certain tries.
// -------------------------------------------------------------------

Articlepausescroller.prototype.do_onjsload=function(){
	var scrollerinstance=this
	// if JS array holding RSS content not yet loaded
	if (typeof rsscontentdata[this.tickerid]=="undefined" && this.number_of_tries<40){
		this.number_of_tries++
		window.setTimeout(function(){scrollerinstance.do_onjsload()}, 2000) //recheck
	}
	else if (typeof rsscontentdata[this.tickerid]!="undefined"){ //if JS array has loaded
		this.tickerdiv=document.getElementById(this.tickerid)
		this.visiblediv=document.getElementById(this.tickerid+"1")
		this.hiddendiv=document.getElementById(this.tickerid+"2")
		this.visibledivtop=parseInt(Articlepausescroller.getCSSpadding(this.tickerdiv))
		//set width of inner DIV to outer DIV width minus padding (padding assumed to be top padding x 2)
		this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
		this.visiblediv.innerHTML=formatrssmessage(this.tickerid, 0, this.linktarget)
		this.hiddendiv.innerHTML=formatrssmessage(this.tickerid, 1, this.linktarget)
		this.do_ondivsinitialized()
	}
	else{
		document.getElementById(this.tickerid).innerHTML=rsscontentdata+""
	}
}

Articlepausescroller.prototype.do_unjsload=function(){
	this.tickerdiv=document.getElementById(this.tickerid)
	this.visiblediv=document.getElementById(this.tickerid+"1")
	this.hiddendiv=document.getElementById(this.tickerid+"2")
	this.visibledivtop=parseInt(Articlepausescroller.getCSSpadding(this.tickerdiv))
	//set width of inner DIV to outer DIV width minus padding (padding assumed to be top padding x 2)
	this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
	this.visiblediv.innerHTML=''
	this.hiddendiv.innerHTML=''
	this.visiblediv.Visibility = 'hidden'
	this.hiddendiv.Visibility = 'hidden'
}
// -------------------------------------------------------------------
// do_ondivsinitialized()- Checks if two divs of scroller is each populated with RSS message yet
// -If not, continue to check until yes, or abort after certain tries.
// -------------------------------------------------------------------

Articlepausescroller.prototype.do_ondivsinitialized=function(){
	var scrollerinstance=this
	if (parseInt(this.visiblediv.offsetHeight)==0 || parseInt(this.hiddendiv.offsetHeight)==0)
		window.setTimeout(function(){scrollerinstance.do_ondivsinitialized()}, 100)
	else{
		this.initialize()
	}
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

Articlepausescroller.prototype.initialize=function(){
	var scrollerinstance=this
	this.getinline(this.visiblediv, this.hiddendiv)
	this.hiddendiv.style.visibility="visible"
	//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
	this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
	this.tickerdiv.onmouseover=function(){scrollerinstance.mouseoverBol=1}
	this.tickerdiv.onmouseout=function(){scrollerinstance.mouseoverBol=0}
	if (window.attachEvent){
		window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
	}
	window.setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

Articlepausescroller.prototype.animateup=function(){
	var scrollerinstance=this
	if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
		this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
		this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
		window.setTimeout(function(){scrollerinstance.animateup()}, 50)
	}
	else{
		this.getinline(this.hiddendiv, this.visiblediv)
		this.swapdivs()
		window.setTimeout(function(){scrollerinstance.rotatemessage()}, this.delay)
	}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

Articlepausescroller.prototype.swapdivs=function(){
	var tempcontainer=this.visiblediv
	this.visiblediv=this.hiddendiv
	this.hiddendiv=tempcontainer
}

Articlepausescroller.prototype.getinline=function(div1, div2){
	div1.style.top=this.visibledivtop+"px"
	div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// rotatemessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

Articlepausescroller.prototype.rotatemessage=function(){
	if(this.run){
		var scrollerinstance=this
		if (this.mouseoverBol==1){ //if mouse is currently over scoller, do nothing (pause it)
			setTimeout(function(){scrollerinstance.rotatemessage()}, 100)
		}
		else{
			var i=this.hiddendivpointer
			var ceiling=rsscontentdata[this.tickerid].length
			this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
			this.hiddendiv.innerHTML=formatrssmessage(this.tickerid, this.hiddendivpointer, this.linktarget)
			this.animateup()
		}
	}else{
		this.tickerdiv=document.getElementById(this.tickerid)
		this.visiblediv=document.getElementById(this.tickerid+"1")
		this.hiddendiv=document.getElementById(this.tickerid+"2")
		this.visibledivtop=parseInt(Articlepausescroller.getCSSpadding(this.tickerdiv))
		//set width of inner DIV to outer DIV width minus padding (padding assumed to be top padding x 2)
		this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
		this.visiblediv.innerHTML=''
		this.hiddendiv.innerHTML=''
		this.visiblediv.Visibility = 'hidden'
		this.hiddendiv.Visibility = 'hidden'
	}
}

// -------------------------------------------------------------------
// getRSScontentJS()- Fetch RSS feed as external JavaScript
// -------------------------------------------------------------------

Articlepausescroller.getXMLcontentJS=function(scripturl){
	var scriptref=document.createElement('script')
	scriptref.setAttribute("type","text/javascript")
	scriptref.setAttribute("src", scripturl)
	document.getElementsByTagName("head").item(0).appendChild(scriptref)
}


Articlepausescroller.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
	}
}
