/***********************************************
* 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 scr_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.hiddendivpointer=1; //index of message array for hidden div

	if(typeof document.getElementById('mod_ShowScrollContent_').parentElement=="undefined")
	{
		document.getElementById('mod_ShowScrollContent_').parentNode.setAttribute("valign","top");
	}else
	{
		document.getElementById('mod_ShowScrollContent_').parentElement.setAttribute("valign","top");
	}
			document.getElementById('mod_ShowScrollContent_').innerHTML='<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%; visibility: hidden" id="'+divId+'2">'+content[1]+'</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
// -------------------------------------------------------------------

scr_pausescroller.prototype.initialize=function()
{
	this.tickerdiv=document.getElementById(this.tickerid);
	this.visiblediv=document.getElementById(this.tickerid+"1");
	this.hiddendiv=document.getElementById(this.tickerid+"2");
	this.visibledivtop=parseInt(scr_pausescroller.getCSSpadding(this.tickerdiv));
	//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.getinline(this.visiblediv, 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
// -------------------------------------------------------------------

scr_pausescroller.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";
		setTimeout(function(){scrollerinstance.animateup()}, 50);
	}
	else{
		this.getinline(this.hiddendiv, this.visiblediv);
		this.swapdivs();
		setTimeout(function(){scrollerinstance.setmessage()}, this.delay);
	}	
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

scr_pausescroller.prototype.swapdivs=function()
{
	var tempcontainer=this.visiblediv;
	this.visiblediv=this.hiddendiv;
	this.hiddendiv=tempcontainer;
}

scr_pausescroller.prototype.getinline=function(div1,div2)
{
	div1.style.top=this.visibledivtop+"px";
	div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px";
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

scr_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();
	}
}

scr_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;
}

// -------------------------------------------------------------------
// Ajax XML Ticker (txt file source)
// Author: Dynamic Drive (http://www.dynamicdrive.com)
// -------------------------------------------------------------------
function scr_createAjaxObj()
{
	var httprequest=false;
	if (window.XMLHttpRequest)
	{ // if Mozilla, Safari etc
		httprequest=new XMLHttpRequest();
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml');
	}
	else if (window.ActiveXObject){ // if IE
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		}	 
		catch (e){
			try{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	return httprequest;
}
// -------------------------------------------------------------------
// Main Ajax Ticker Object function
// scr_ajax_ticker(xmlfile, divId, divClass, delay, optionalfadeornot)
// -------------------------------------------------------------------
function scr_ajax_ticker(xmlfile, divId, divClass, delay, fadeornot)
{
	this.xmlfile=xmlfile; //Variable pointing to the local ticker xml file (txt)
	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 ticker (and pause it if it is)
	this.pointer=0;
	this.opacitystring=(typeof fadeornot!="undefined")? "width: 100%; filter:progid:DXImageTransform.Microsoft.alpha(opacity=100); -moz-opacity: 1" : "";
	if(this.opacitystring!="")
		this.delay+=500; //add 1/2 sec to account for fade effect, if enabled
	this.opacitysetting=0.2; //Opacity value when reset. Internal use.
	this.messages=[]; //Arrays to hold each message of ticker
	this.ajaxobj=scr_createAjaxObj();
	document.write('<div id="'+divId+'" class="'+divClass+'"><div style="'+this.opacitystring+'">Loading...</div></div>');
	this.getXMLfile();
}
// -------------------------------------------------------------------
// getXMLfile()- Use Ajax to fetch xml file (txt)
// -------------------------------------------------------------------
scr_ajax_ticker.prototype.getXMLfile=function()
{
	if (this.ajaxobj)
	{
		
		var instanceOfTicker=this;
		var url=this.xmlfile+"?bustcache="+new Date().getTime();
		this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
		this.ajaxobj.open('GET', url, true);
		this.ajaxobj.send(null);
	}
}
// -------------------------------------------------------------------
// initialize()- Initialize ticker method.
// -Gets contents of xml file and parse it using JavaScript DOM methods 
// -------------------------------------------------------------------
scr_ajax_ticker.prototype.initialize=function()
{
	if (this.ajaxobj.readyState == 4)
	{ //if request of file completed
	
		if (this.ajaxobj.status==200 || window.location.href.indexOf("http")==-1)
		{ //if request was successful
			this.contentdiv=document.getElementById(this.tickerid).firstChild ;//div of inner content that holds the messages
			var xmldata=this.ajaxobj.responseText;
			this.contentdiv.style.display="none";
			this.contentdiv.innerHTML=xmldata;
			if (this.contentdiv.getElementsByTagName("span").length==0)
			{ //if no messages were found
				this.contentdiv.innerHTML="<b>Error</b> fetching remote content file!";
				return;
			}
			
			var instanceOfTicker=this;
			document.getElementById(this.tickerid).onmouseover=function(){instanceOfTicker.mouseoverBol=1}
			document.getElementById(this.tickerid).onmouseout=function(){instanceOfTicker.mouseoverBol=0}
			
			if(window.attachEvent)
			{//Clean up loose references in IE
				window.attachEvent("onunload", function(){instanceOfTicker.contentdiv=instanceOfTicker.ajaxobj=null;} );
			}
			
			//Cycle through XML object and store each message inside array
			for (var i=0; i<this.contentdiv.getElementsByTagName("span").length; i++)
			{
				if(this.contentdiv.getElementsByTagName("span")[i].className=="mod_ajaxnfscroller") // css class here
					this.messages[this.messages.length]=this.contentdiv.getElementsByTagName("span")[i].innerHTML;
			}
			
			this.contentdiv.innerHTML="";
			this.contentdiv.style.display="block";

			new scr_pausescroller(this.messages, "mod_ajaxnfscroller", "mod_ajaxnfscroller", 3000);
			
		}
	}
}