// -------------------------------------------------------------------
// Ajax XML Ticker (txt file source)
// Author: Dynamic Drive (http://www.dynamicdrive.com)
// -------------------------------------------------------------------

// -------------------------------------------------------------------
// Main Ajax Ticker Object function
// ajax_ticker(xmlfile, divId, divClass, delay, optionalfadeornot)
// -------------------------------------------------------------------

function ajax_ticker(xmlfile, divId, divClass, delay, fadeornot, maxrows){               //***SLK***
	this.xmlfile=xmlfile //Variable pointing to the local ticker xml file (txt)
	this.tickerid=divId //ID of ticker div to display information
	this.divclass=divClass                                                                     //***SLK***
	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.message="" //Arrays to hold lat message of full ticker
	this.messages=[] //Arrays to hold all messages of mini ticker
	this.counter=0
	this.timeout=0
	this.maxrows=maxrows                                                       //***SLK***
	if (this.maxrows == null) this.maxrows = 7     // Default if not set       //***SLK***
	this.ajaxobj=createAjaxObj()
	document.write('<div id="'+divId+'" class="'+divClass+'"><div style="'+this.opacitystring+'"></div>')
	this.getXMLfile()
	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})
	return this
}

// -------------------------------------------------------------------
// initialize()- Initialize ticker method.
// -Gets contents of xml file and parse it using JavaScript DOM methods
// -------------------------------------------------------------------

ajax_ticker.prototype.initialize=function(){
var instanceOfTicker=this

if (this.timeout>100) {
	alert("If you are still watching the Real Time Hit Feed, please click 'OK' below to continue...")
	this.timeout=0
}


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
		//this.contentdiv.style.display="none"
		//this.contentdiv.innerHTML=this.ajaxobj.responseText
		if (this.message != this.ajaxobj.responseText) {
			this.timeout++
			this.contentdiv.style.display="block"
			//this.fadetransition("reset") //FADE EFFECT- RESET OPACITY                 //***SLK***

           //***SLK***
           // Add new items at the bottom
			if (this.counter>=this.maxrows) {
				var line = document.getElementById("slot"+(this.maxrows-1)).firstChild
				this.fadetransition("reset", "", line)

				var prevSlot = document.getElementById("slot"+(this.maxrows-1)).firstChild.innerHTML
				line.innerHTML = this.ajaxobj.responseText
				var temp = ""

				this.linefadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'linefadetimer1', line)}, 100) //FADE EFFECT- PLAY IT

				for (var x=this.maxrows-2; x >= 0; x--)
				{
			        temp = document.getElementById("slot"+x).firstChild.innerHTML
			        document.getElementById("slot"+x).firstChild.innerHTML = prevSlot
			        prevSlot = temp;
				}
			}
			else {
				this.contentdiv.innerHTML=this.contentdiv.innerHTML+"<div id='slot"+this.counter+"' class='"+this.divclass+"'><div style='"+this.opacitystring+"'>"+this.ajaxobj.responseText+"</div></div><hr>"

				var newline = document.getElementById("slot"+this.counter).firstChild
				this.fadetransition("reset", "", newline)
				this.linefadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'linefadetimer1', newline)}, 100) //FADE EFFECT- PLAY IT

				this.counter=this.counter+1
			}
               //***SLK End***

			//this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
			this.message = this.ajaxobj.responseText
		}
		setTimeout(function(){instanceOfTicker.getXMLfile()}, this.delay) // check for updated file
		}
	}
}

ajax_ticker.prototype.initialize_mini=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("div").length==0){ //if no messages were found
				this.contentdiv.innerHTML="<b>Error</b> fetching remote ticker file!"
				return
			}
			var instanceOfTicker=this
			//Cycle through XML object and store each message inside array
			for (var i=0; i<this.contentdiv.getElementsByTagName("div").length; i++)  {
				if (this.contentdiv.getElementsByTagName("div")[i].className=="message")
				this.messages[this.messages.length]=this.contentdiv.getElementsByTagName("div")[i].innerHTML
				}
			this.contentdiv.innerHTML=""
			this.contentdiv.style.display="block"
			this.rotatemsg()
		}
	}
}

// -------------------------------------------------------------------
// rotatemsg()- Rotate through ticker messages and displays them
// -------------------------------------------------------------------

ajax_ticker.prototype.rotatemsg=function(){
	var instanceOfTicker=this
	if (this.mouseoverBol==1) {
		//if mouse is currently over ticker, do nothing (pause it)
		if (this.contentdiv.innerHTML.lastIndexOf('paused')==-1) this.contentdiv.innerHTML=this.contentdiv.innerHTML+"...paused"
		setTimeout(function(){instanceOfTicker.rotatemsg()}, 100)
		}
	else { //else, construct item, show and rotate it!
		this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
		this.contentdiv.innerHTML=this.messages[this.pointer] // +'('+this.pointer+')'
		this.contentdiv.innerHTML=  // +'('+(this.delay/1000)+')'+
		'<a href="" OnClick="javascript:aticker.faster(); return false;"><img border=0 src=images/plus.gif alt="Increase Speed of Hit Feed"></a>&nbsp;&nbsp;   '+
		'<a href="" OnClick="javascript:aticker.slower(); return false;"><img border=0 src=images/minus.gif alt="Decrease Speed of Hit Feed"></a><br>'+this.contentdiv.innerHTML
		this.contentdiv.style.height="100px"
		this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
		this.pointer=(this.pointer<this.messages.length-1)? this.pointer+1 : 0
		if (this.pointer==0)
			setTimeout(function(){instanceOfTicker.getXMLfile()}, this.delay)
		else
			setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container periodically
	}
}

ajax_ticker.prototype.faster=function(){
	this.delay-=1000
	if (this.delay<1000) {
		this.delay=1000
		this.contentdiv.innerHTML="fastest..."+this.contentdiv.innerHTML
		}
	else this.contentdiv.innerHTML="faster..."+this.contentdiv.innerHTML
	this.mouseoverBol=0
	}

ajax_ticker.prototype.slower=function(){
	this.delay+=1000
	this.contentdiv.innerHTML="slower..."+this.contentdiv.innerHTML
	this.mouseoverBol=0
	}

// -------------------------------------------------------------------
// getXMLfile()- Use Ajax to fetch xml file (txt)
// -------------------------------------------------------------------

ajax_ticker.prototype.getXMLfile=function(){
if (this.ajaxobj){
	var instanceOfTicker=this
	var url=this.xmlfile+"?bustcache="+new Date().getTime()
	this.messages=[] //Arrays to hold each message of mini ticker
	this.ajaxobj.open('GET', url, true)
	if (this.maxrows==0) this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize_mini()}
	else  this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
	this.ajaxobj.send(null)
	}
}

// -------------------------------------------------------------------
// fadetransition()- cross browser fade method for IE5.5+ and Mozilla/Firefox
// -------------------------------------------------------------------

ajax_ticker.prototype.fadetransition=function(fadetype, timerid, fadeobj){          //***SLK***
    //***SLK***
    var fadediv
    if (fadeobj == null) {
	   fadediv=this.contentdiv
	} else {
	   fadediv=fadeobj
	}
	if (fadetype=="reset")	this.opacitysetting=0.2
	if (fadediv.filters && fadediv.filters[0]) {
		if (typeof fadediv.filters[0].opacity=="number") //IE6+
			fadediv.filters[0].opacity=this.opacitysetting*100
		else //IE 5.5
			fadediv.style.filter="alpha(opacity="+this.opacitysetting*100+")"
	}
	else if (typeof fadediv.style.MozOpacity!="undefined" && this.opacitystring!="") {
		fadediv.style.MozOpacity=this.opacitysetting
	}
	else this.opacitysetting=1
    //***SLK End***

	if (fadetype=="up") this.opacitysetting+=0.1
	if (fadetype=="up" && this.opacitysetting>=1)
	   clearInterval(this[timerid])
}
////////////No need to edit beyond here//////////////

function 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
}