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
}

// -------------------------------------------------------------------
// Main RSS Ticker Object function
// rssticker_ajax(RSS_id, cachetime, divId, divClass, delay, optionallogicswitch)
// -------------------------------------------------------------------

function rssticker_ajax(RSS_id, cachetime, divId, divClass, delay, logicswitch){
this.RSS_id=RSS_id //Array key indicating which RSS feed to display
this.cachetime=cachetime //Time to cache feed, in minutes. 0=no cache.
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.logicswitch=(typeof logicswitch!="undefined")? logicswitch : ""
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over ticker (and pause it if it is)
this.pointer=0
this.opacitysetting=0.2 //Opacity value when reset. Internal use.
this.title=[], this.link=[], this.pubdate=[], this.picture=[] //Arrays to hold each component of an RSS item
this.ajaxobj=createAjaxObj()
document.write('<div id="'+divId+'" class="'+divClass+'" >Initializing ticker...</div>')
if (window.getComputedStyle) //detect if moz-opacity is defined in external CSS for specified class
this.mozopacityisdefined=(window.getComputedStyle(document.getElementById(this.tickerid), "").getPropertyValue("-moz-opacity")==1)? 0 : 1
this.getAjaxcontent()
}

// -------------------------------------------------------------------
// getAjaxcontent()- Makes asynchronous GET request// important
// -------------------------------------------------------------------

rssticker_ajax.prototype.getAjaxcontent=function(){
if (this.ajaxobj){
var instanceOfTicker=this
this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
this.ajaxobj.open('GET', 'includes/stiri-rssticker.php?r='+Math.random(), true)
this.ajaxobj.send(null)
}
}

// -------------------------------------------------------------------
// initialize()- Initialize ticker method.
// -Gets contents of RSS content and parse it using JavaScript DOM methods 
// -------------------------------------------------------------------

rssticker_ajax.prototype.initialize=function(){ 
if (this.ajaxobj.readyState == 4){ //if request of file completed
if (this.ajaxobj.status==200){ //if request was successful
var xmldata=this.ajaxobj.responseXML
if(xmldata.getElementsByTagName("item").length==0){ //if no <item> elements found in returned content
document.getElementById(this.tickerid).innerHTML="<b>Error</b> fetching remote RSS feed!<br />"+this.ajaxobj.responseText
return
}
var instanceOfTicker=this
this.feeditems=xmldata.getElementsByTagName("item")
//Cycle through RSS XML object and store each peice of an item inside a corresponding array
for (var i=0; i<this.feeditems.length; i++){
this.title[i]=this.feeditems[i].getElementsByTagName("title")[0].firstChild.nodeValue
this.picture[i]=this.feeditems[i].getElementsByTagName("picture")[0].firstChild.nodeValue
this.link[i]=this.feeditems[i].getElementsByTagName("link")[0].firstChild.nodeValue
this.pubdate[i]=this.feeditems[i].getElementsByTagName("pubDate")[0].firstChild.nodeValue
}
//document.getElementById(this.tickerid).onmouseover=function(){instanceOfTicker.mouseoverBol=1}
//document.getElementById(this.tickerid).onmouseout=function(){instanceOfTicker.mouseoverBol=0}
this.rotatemsg()
}
}
}

// -------------------------------------------------------------------
// rotatemsg()- Rotate through RSS messages and displays them /IMPORTANT
// -------------------------------------------------------------------

rssticker_ajax.prototype.rotatemsg=function(){
var instanceOfTicker=this
if (this.mouseoverBol==1) //if mouse is currently over ticker, do nothing (pause it)
setTimeout(function(){instanceOfTicker.rotatemsg()}, 100)
else{ //else, construct item, show and rotate it!
var tickerDiv=document.getElementById(this.tickerid)
var picture=this.picture[this.pointer];
var linktitle=this.title[this.pointer];
var linkurl=this.link[this.pointer];
var feeddate=''
if (this.logicswitch.indexOf("date")==-1) feeddate=""

var tds='';
for (i=0;i<this.feeditems.length; i=i+1)
{
	sel=''; if(i==this.pointer) sel='sel';
	tds=tds+'<td class="ajaxtdpag'+sel+'" align="center"><a href="#" onclick="slideob.rotateto('+i+');">'+(i+1)+'</a></td>';
}


tickercontent='<table width="100%" style="" cellspacing="0" cellpadding="0">\
	<tr>\
		<td height="350" background="'+picture+'" style="background-repeat:no-repeat">\
			<table width="100%" border="0" cellpadding="0" cellspacing="0" height="350">\
				<tr>\
					<td width="660">&nbsp;</td>\
					<td>\
						<div style="position:relative;"><div style="z-index:1; position:absolute;  width:320px; height:350px;">\
							<table width="360" height="350" cellpadding="0" cellspacing="0" border="0">\
								<tr><td  height="300" valign="top">\
									<div style="margin:40px 30px 0 30px;">\
									<a href="'+linkurl+'" class="maintitle">'+linktitle+'</a>\
									</div>\
								</td></tr>\
								<tr><td align="right" valign="top" height="50" style="padding-right:5px;">\
									<table border=0 cellpading=0 cellspacing="10"><tr>\
										'+tds+'\
										<tr>\
									</table>\
								</td></tr>\
							</table>\
							</div>\
							<div style="width:360px; height:350px;background-color:#4D4D4D; opacity:0.7;filter:alpha(opacity=70)"></div>\
						</div>\
					</td>\
				</tr>\
			</table>\
		</td>\
	</tr>\
</table>';
this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
tickerDiv.innerHTML=tickercontent
this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
this.pointer=(this.pointer<this.feeditems.length-1)? this.pointer+1 : 0
this.ctimer = setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container every second
}
}


rssticker_ajax.prototype.rotateto=function(id){
this.pointer=id;
clearTimeout(this.ctimer);
this.rotatemsg();
}




// -------------------------------------------------------------------
// fadetransition()- cross browser fade method for IE5.5+ and Mozilla/Firefox
// -------------------------------------------------------------------

rssticker_ajax.prototype.fadetransition=function(fadetype, timerid){
var tickerDiv=document.getElementById(this.tickerid)
if (fadetype=="reset")
this.opacitysetting=0.2
if (tickerDiv.filters && tickerDiv.filters[0]){
if (typeof tickerDiv.filters[0].opacity=="number") //IE6+
tickerDiv.filters[0].opacity=this.opacitysetting*100
else //IE 5.5
tickerDiv.style.filter="alpha(opacity="+this.opacitysetting*100+")"
}
else if (typeof tickerDiv.style.MozOpacity!="undefined" && this.mozopacityisdefined){
tickerDiv.style.MozOpacity=this.opacitysetting
}
if (fadetype=="up")
this.opacitysetting+=0.19
if (fadetype=="up" && this.opacitysetting>=1)
clearInterval(this[timerid])
}
