var ticker;Effect.DefaultOptions.duration=0.3;NewsTicker=Class.create();Object.extend(NewsTicker.prototype,{tickerDiv:"ticker",tickerTitle:"news-link",tickerLink:"http://macmediainc.com/hotnews.php",scriptURL:"/scripts/remoteurl.php",feedURL:"http://images.apple.com/main/rss/hotnews/hotnews.rss",pauseLength:10000,timer:0,currentTitle:0,items:null,initialize:function(){this.items=[];new Ajax.Request(this.scriptURL,{method:"get",parameters:"url="+this.feedURL+"&type=xml",onSuccess:function(response){this.parseXML(response.responseXML);this.buildTicker();}.bind(this),onFailure:function(){console.log("Please visit http://www.apple.com/hotnews for the latest news and information on Apple.");},onException:function(req,err){throw(err);}});},buildTicker:function(){if(this.items[this.currentTitle]){$(this.tickerTitle).innerHTML=this.items[this.currentTitle]['title'];this.start();}},parseXML:function(xml){$A(xml.getElementsByTagName("item")).each(function(item){title=item.getElementsByTagName("title")[0].childNodes[0].nodeValue;desc=item.getElementsByTagName("description")[0].childNodes[0].nodeValue;var link=NewsTicker.tickerLink;this.items.push({title:title,link:link,description:desc});}.bind(this));},start:function(){this.interval=setInterval(this.showNext.bind(this),this.pauseLength);},stop:function(){clearInterval(this.interval)},showNext:function(){if(this.currentTitle<this.items.length-1){this.currentTitle=this.currentTitle+1;}else{this.currentTitle=0;}
new Effect.Fade('apple-news',{afterFinish:function(){this.switchData();new Effect.Appear('apple-news');}.bind(this)});},switchData:function(){$(this.tickerTitle).setAttribute("href",this.tickerLink+"#"+this.currentTitle);$(this.tickerTitle).setAttribute("title",this.items[this.currentTitle]['description']);if(this.items[this.currentTitle]){$(this.tickerTitle).innerHTML=this.items[this.currentTitle]['title'];}},hideTicker:function(){this.tickerDiv.hide();}});Event.observe(window,'load',function(){ticker=new NewsTicker();});