// -------------------------------------------------------------------
// Advanced RSS Ticker (Ajax invocation) core file
// Author: Dynamic Drive (http://www.dynamicdrive.com)
// -------------------------------------------------------------------

//Relative URL syntax:
var lastrssbridgeurl="rsstickerajax/lastrss/bridge.php"

//Absolute URL syntax. Uncomment below line if you wish to use an absolute reference:
//var lastrssbridgeurl="http://"+window.location.hostname+"/lastrss/bridge.php"

var listen=[];
listen[1]="('pop','siriushits1')";
listen[2]="('pop','starlite')";
listen[3]="('pop','siriuslove')";
listen[4]="('pop','movineasy')";
listen[5]="('pop','siriusgold')";
listen[6]="('pop','60svibrations')";
listen[7]="('pop','totally70s')";
listen[8]="('pop','big80s')";
listen[9]="('pop','thepulse')";
listen[10]="('pop','thebridge')";
listen[11]="('pop','bbcradio1')";
listen[12]="('pop','supershuffle')";
listen[13]="('pop','elvisradio')";
listen[14]="('rock','classicvinyl')";
listen[15]="('rock','classicrewind')";
listen[16]="('rock','thevault')";
listen[17]="('rock','jamon')";
listen[18]="('rock','thespectrum')";
listen[19]="('rock','buzzsaw')";
listen[20]="('rock','octane')";
listen[21]="('rock','altnation')";
listen[22]="('rock','firstwave')";
listen[23]="('rock','hairnation')";
listen[24]="('rock','90salternative')";
listen[25]="('rock','undergroundgarage')";
listen[26]="('rock','leftofcenter')";
listen[27]="('rock','hardattack')";
listen[28]="('rock','faction')";
listen[29]="('rock','punk')";
listen[30]="('rock','coffeehouse')";
listen[31]="('rock','radiomargaritaville')";
listen[32]="('rock','siriusdisorder')";
listen[33]="('electronicdance','area33')";
listen[34]="('electronicdance','boombox')";
listen[35]="('electronicdance','chill')";
listen[36]="('electronicdance','thebeat')";
listen[37]="('electronicdance','thestrobe')";
listen[40]="('hiphopranb','hiphopnation')";
listen[43]="('hiphopranb','backspin')";
listen[45]="('hiphopranb','shade45')";
listen[50]="('hiphopranb','hotjamz')";
listen[51]="('hiphopranb','heartandsoul')";
listen[53]="('hiphopranb','soultown')";
listen[60]="('country','newcountry')";
listen[61]="('country','primecountry')";
listen[62]="('country','theroadhouse')";
listen[63]="('country','outlawcountry')";
listen[65]="('country','bluegrass')";
listen[66]="('christian','spirit')";
listen[68]="('christian','praise')";
listen[70]="('jazzandblues','planetjazz')";
listen[71]="('jazzandblues','jazzcafe')";
listen[72]="('jazzandblues','purejazz')";
listen[73]="('jazzandblues','spa73')";
listen[74]="('jazzandblues','siriusblues')";
listen[75]="('standards','siriuslysinatra')";
listen[77]="('standards','broadwaysbest')";
listen[80]="('classical','symphonyhall')";
listen[85]="('classical','metropolitanopera')";
listen[86]="('classical','siriuspops')";
listen[90]="('latinworld','universolatino')";
listen[92]="('latinworld','rumbon')";
listen[97]="('rock','reggaerhythms')";
listen[100]="('howardgenre','howardstern100')";
listen[101]="('howardgenre','howardstern101')";
listen[102]="('entertainment','siriusstars')";
listen[103]="('comedy','bluecollarcomedy')";
listen[104]="('comedy','rawdog')";
listen[105]="('comedy','laughbreak')";
listen[108]="('entertainment','maximradio')";
listen[109]="('entertainment','siriusoutq')";
listen[111]="('entertainment','cosmopolitanradio')";
listen[112]="('marthagenre','marthastewartlivingradio')";
listen[116]="('familyandkids','kidsstuff')";
listen[124]="('siriusfootballradio','siriusnflradio')";
listen[132]="('usnews','cnn')";
listen[144]="('talk','siriuspatriot')";
listen[146]="('talk','siriusleft')";
listen[159]="('religion','thecatholicchannel')";
listen[160]="('religion','ewtnglobal')";
listen[198]="('entertainment','playboyradio')";

////////////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
}

// -------------------------------------------------------------------
// 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.setdelay=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.feeditems=[], this.title=[], this.link=[], this.description=[], this.pubdate=[] //Arrays to hold each component of an RSS item


this.ajaxobj=createAjaxObj()
document.write('<div id="'+divId+'" class="'+divClass+'" ><div class="tickerchannel" style="font-family:arial, helvetica,sans-serif"><br>Acquiring Signal...<br><br><br><br></div></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.updateclock()
this.getAjaxcontent()
}

// -------------------------------------------------------------------
// getAjaxcontent()- Makes asynchronous GET request to "bridge.php" with the supplied parameters
// -------------------------------------------------------------------

rssticker_ajax.prototype.getAjaxcontent=function(){
if (this.ajaxobj){
var instanceOfTicker=this
if(this.RSS_id == 'dogstar') {
  this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
  this.ajaxobj.open('GET', 'http://www.DogstarRadio.com/tracker.txt', true)
  this.ajaxobj.send(null)
}
else if(!isNaN(this.RSS_id)) {
  this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
  this.ajaxobj.open('GET', 'http://www.DogstarRadio.com/channelrss/' + this.RSS_id +'.txt', true)
  this.ajaxobj.send(null)

}
else {
  var parameters="id="+encodeURIComponent(this.RSS_id)+"&cachetime="+this.cachetime+"&bustcache="+new Date().getTime()
  this.ajaxobj.onreadystatechange=function(){instanceOfTicker.initialize()}
  this.ajaxobj.open('GET', lastrssbridgeurl+"?"+parameters, 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
if(this.RSS_id == 'dogstar' || !isNaN(this.RSS_id)) {
   var txtdata = this.ajaxobj.responseText;
   var txtarray = txtdata.split('\n');
   var filedate = txtarray.shift();
   var count = 0;
   var instanceOfTicker=this
   instanceOfTicker.rewind=0
   while(txtarray.length >0) {
      var channel = txtarray.shift();
      var station = txtarray.shift();
      var artist = txtarray.shift();
      var title = txtarray.shift();
      var genre = txtarray.shift();
      var pid = txtarray.shift();
      var aid = txtarray.shift();
      var bogus = txtarray.shift();
      
      if(listen[channel]) {
         var listenlink = " <span class=listen onclick=\"listenLaunch" + listen[channel] + ";\" title='Click to Listen!'> &nbsp; listen</span>";
      }
      else {
         var listenlink = "";
      }
      var wlink = station.replace(/ /g,'_');
      if (instanceOfTicker.tickerid == 'stiletto') {
         station = "<img border=0 src=http://www.DogstarRadio.com/channel_logos/channel-" + channel + "-small.gif>";
      }
      else if (instanceOfTicker.tickerid == 'stiletto-lg') {
         station = "<img border=0 src=http://www.DogstarRadio.com/channel_logos/channel-" + channel + ".gif>";
      }
         
      while(channel.length < 3) { channel = '0' + channel; }
      
      this.feeditems[count] = '1';
      this.title[count] = station;
      this.link[count] = "http://www.DogstarRadio.com/wiki/index.php?title=" + wlink;
      this.description[count] = "<div class='tickerchannel' id='tickerchannel'>" + channel + " " + listenlink + "</div><a target=_blank href=http://www.DogstarRadio.com/now_playing.php><div class='tickerartist' id='tickerartist'>" + artist + "</div><div class='tickertitle' id='tickertitle'>" + title + "</div></a><div class='tickergenre' id='tickergenre'>" + genre + "</div>";
      this.pubdate[count] = '1';
      count++;
   }
}
else {
  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
  instanceOfTicker.rewind=0
  this.feeditems=xmldata.getElementsByTagName("item")
  //Cycle through RSS XML object and store each piece 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.link[i]=this.feeditems[i].getElementsByTagName("link")[0].firstChild.nodeValue
    this.description[i]=this.feeditems[i].getElementsByTagName("description")[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}
document.getElementById('rewind').onmouseover=function(){
  instanceOfTicker.delay=instanceOfTicker.setdelay/10
  instanceOfTicker.rewind=1
}
document.getElementById('rewind').onmouseout=function(){
  instanceOfTicker.delay=instanceOfTicker.setdelay
  instanceOfTicker.rewind=0
}
document.getElementById('fastforward').onmouseover=function(){
  instanceOfTicker.delay=instanceOfTicker.setdelay/10
}
document.getElementById('fastforward').onmouseout=function(){
  instanceOfTicker.delay=instanceOfTicker.setdelay
}
document.getElementById('tickerfeed').onclick=function(){
  if(instanceOfTicker.RSS_id =='dogstar') {
    instanceOfTicker.RSS_id = 'dogstarnews';
    document.getElementById('tickerfeed').innerHTML = 'N';
    instanceOfTicker.pointer=999;
  }
  else {
    instanceOfTicker.RSS_id = 'dogstar';
    document.getElementById('tickerfeed').innerHTML = 'P';
    instanceOfTicker.pointer=999;
  }
}
this.rotatemsg()
}
}
}

// -------------------------------------------------------------------
// rotatemsg()- Rotate through RSS messages and displays them
// -------------------------------------------------------------------

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 linktitle='<div class="rsstitle"><a href="'+this.link[this.pointer]+'" target="_blank">'+this.title[this.pointer]+'</a></div>'
  var description='<div class="rssdescription">'+this.description[this.pointer] + '</div>'
  var feeddate='<div class="rssdate">'+this.pubdate[this.pointer]+'</div>'
  if (this.logicswitch.indexOf("description")==-1) description=""
  if (this.logicswitch.indexOf("date")==-1) feeddate=""
  var tickercontent=linktitle+feeddate+description //STRING FOR FEED CONTENTS 
  this.fadetransition("reset") //FADE EFFECT- RESET OPACITY
  tickerDiv.innerHTML=tickercontent
  this.fadetimer1=setInterval(function(){instanceOfTicker.fadetransition('up', 'fadetimer1')}, 100) //FADE EFFECT- PLAY IT
  if(this.rewind==1) {
    if(this.pointer>0) this.pointer = this.pointer-1 
    else {this.pointer=this.feeditems.length-1}
    setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container every second
  }
  else {
    if(this.pointer == 999) {
      this.pointer = 0
      this.updateclock()
      instanceOfTicker.getAjaxcontent()
    }
    else if(this.pointer<this.feeditems.length-1) {
      this.pointer= this.pointer+1
      setTimeout(function(){instanceOfTicker.rotatemsg()}, this.delay) //update container every second
    }
    else { 
      this.pointer = 0
      this.updateclock()
      setTimeout(function(){instanceOfTicker.getAjaxcontent()}, this.delay)
  
    }
  }
}
}

// -------------------------------------------------------------------
// 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.2
if (fadetype=="up" && this.opacitysetting>=1)
clearInterval(this[timerid])
}

rssticker_ajax.prototype.updateclock=function(){
   Stamp = new Date();
   var Hours;
   var Mins;
   var Time;
   Hours = Stamp.getHours();
   if (Hours >= 12) {
     Time = " PM";
   }
   else {
     Time = " AM";
   }
   if (Hours > 12) {
     Hours -= 12;
   }
   if (Hours == 0) {
     Hours = 12;
   }
   Mins = Stamp.getMinutes();
   if (Mins < 10) {
     Mins = "0" + Mins;
   }
   document.getElementById('tickerclock').innerHTML = Hours + ":" + Mins + Time;
}