LFM.set("Radio",{ActivityTimer:Class.create({counter:0,timer:null,pollLength:0,timeoutPeriod:0,timeoutCallback:null,initialize:function(_1,_2,_3){
this.timeoutCallback=_1;
this.timeoutPeriod=_2;
this.pollLength=_3||_2;
},start:function(){
log("Started ActivityTimer");
this.setTimeout();
},stop:function(){
log("Stopped ActivityTimer");
this.clearTimeout();
this.reset();
},reset:function(){
log("Reset ActivityTimer");
this.setTimeout();
this.counter=0;
},update:function(){
this.counter+=this.pollLength;
if(this.counter>=this.timeoutPeriod){
return this.timeout();
}
this.setTimeout();
},timeout:function(){
this.stop();
this.timeoutCallback();
},clearTimeout:function(){
clearTimeout(this.timer);
},setTimeout:function(){
this.clearTimeout();
this.timer=setTimeout(this.update.bind(this),this.pollLength);
}})});
LFM.set("Radio",{Metadata:Class.create({currentTrack:null,currentTrackNum:null,newTrack:null,playing:false,artistInfoBlinding:false,waitingShowResponseArg:false,shoutSuccess:"0",originalTitle:document.title,isLovedTrack:false,statusTimer:null,scrobbling:true,slideshow:true,stopOnTrackComplete:false,initialize:function(_4,_5){
LFM.info("initialize Radio MetaData");
document.observe("click",this.clickSniffer.bind(this));
setTimeout(function(){
Event.observe(window,"focus",this.focusCallback.bind(this));
}.bind(this),10000);
setInterval(this.scrollSniffer.bind(this),10000);
window.onbeforeunload=this.unloadPage.bind(this);
$("playerControlLove").observe("click",function(e){
e.element().blur();
LFM.Flash.Player.love();
this.addClassName("highlight");
LFM.Page.Metadata.logInteraction(e,true);
});
$("playerControlBan").observe("click",function(e){
e.element().blur();
LFM.Flash.Player.ban();
LFM.Page.Metadata.logInteraction(e,true);
});
$("playerControlPlay").observe("click",function(e){
e.element().blur();
LFM.Flash.Player.play();
LFM.Page.Metadata.logInteraction(e,true);
});
$("playerControlStop").observe("click",function(e){
e.element().blur();
LFM.Flash.Player.stop();
LFM.Page.Metadata.logInteraction(e,true);
});
$("playerControlSkip").observe("click",function(e){
e.element().blur();
LFM.Flash.Player.skip();
if($("lfmSlideshow")&&$("lfmSlideshow").stopPlayback){
$("slideshowPhotoCredits").hide();
try{
$("lfmSlideshow").stopPlayback();
}
catch(e){
LFM.error("Error calling Slideshow.stopPlayback()");
LFM.log(e);
}
}else{
LFM.warn("slideshow unavailable stopPlayback()");
}
LFM.Page.Metadata.logInteraction(e,true);
});
$("userMetadata").observe("click",function(e){
if(e.element().up().match("h2")){
e.element().up().up().toggleClassName("closed");
}
});
if($("scrobbleToggle")){
$("scrobbleToggle").observe("click",this.scrobbleToggle.bind(this));
}
if($("slideshowToggle")){
$("slideshowToggle").observe("click",this.slideshowToggle.bind(this));
}
var _c=$("playerControlVolSlider");
var _d=(LFM.getCookie("lfmVol"))?LFM.getCookie("lfmVol"):80;
var _e=new Control.Slider(_c.down(".handle"),_c,{range:$R(0,100),sliderValue:_d,onSlide:function(_f){
LFM.Flash.Player.setVolume(Math.round(_f));
LFM.setCookie("lfmVol",Math.round(_f));
LFM.Page.Metadata.logInteraction();
},onChange:function(_10){
LFM.Flash.Player.setVolume(Math.round(_10));
LFM.setCookie("lfmVol",Math.round(_10));
LFM.Page.Metadata.logInteraction();
}});
$("playerControlVolMute").observe("click",function(e){
LFM.Page.Metadata.logInteraction(e,true);
LFM.Flash.Player.setVolume(Math.round(0));
LFM.setCookie("lfmVol",Math.round(0));
_e.setValue(0);
});
$("playerControlVolFull").observe("click",function(e){
LFM.Page.Metadata.logInteraction(e,true);
LFM.Flash.Player.setVolume(Math.round(100));
LFM.setCookie("lfmVol",Math.round(100));
_e.setValue(100);
});
},onLoad:function(){
LFM.info("Flash player loaded");
LFM.logGroup("Flash player listeners");
LFM.Flash.Player.addEventListener("playback",this.onPlayback);
LFM.Flash.Player.addEventListener("nextTrack",this.onNextTrack.bind(this));
LFM.Flash.Player.addEventListener("completeTrack",this.onCompleteTrack.bind(this));
LFM.Flash.Player.addEventListener("stopTrack",this.onStopTrack.bind(this));
LFM.Flash.Player.addEventListener("error",this.onError.bind(this));
LFM.Flash.Player.addEventListener("bufferingStart",this.onBufferingStart.bind(this));
LFM.Flash.Player.addEventListener("loveTrack",this.onLoveTrack.bind(this));
LFM.Flash.Player.addEventListener("tune",this.onTune.bind(this));
LFM.Flash.Player.addEventListener("unsupportedPlayerVersion",this.onUnsupportedPlayerVersion.bind(this));
LFM.Flash.Player.addEventListener("getSession",this.onGetSession.bind(this));
LFM.logGroupEnd();
this.setScrobblingPref();
},onGetSession:function(){
LFM.info("getSession is in");
LFM.Flash.Player.readyToTune=true;
LFM.Flash.PreRoll.onGetSession();
},setScrobblingPref:function(){
if(!LFM.Page.Metadata.scrobbling){
LFM.Flash.Player.switchOffScrobbling();
}
},onError:function(_13){
log("Flash Player event: onError: "+_13.code+" : "+_13.message);
if(_13.code==1){
$("stationPlaybackContentError").show();
this.setStatus({type:"error",message:"Not enough content"});
this.onStopTrack(LFM.Page.RadioState.hasCurrentStation());
}else{
if(_13.code==2){
$("stationPlaybackConnectionError").show();
this.setStatus({type:"error",message:"Connection error"});
this.onStopTrack(LFM.Page.RadioState.hasCurrentStation());
}else{
if(_13.code==3){
this.setStatus({type:"error",message:_13.message});
this.onStopTrack(true);
this.inactivityDialog();
}
}
}
if(!LFM.Page.RadioState.hasCurrentStation()){
LFM.Page.RadioState.newStationError();
}
LFM.Page.RadioState.fixPaneHeight();
},onBufferingStart:function(_14){
log("Flash Player event: onBufferingStart: "+_14.message);
this.setStatus({type:"loading",message:LFM.String.buffering});
},onLoveTrack:function(_15){
log("Flash Player Event: onLoveTrack: "+_15.message);
if(!_15.error){
this.setStatus({type:"info",message:LFM.String.trackLoved,duration:4000});
$("playerControlLove").addClassName("highlight");
LFM.Flash.Player.logLove();
LFM.Adserver.refreshAds(true);
}
},onUnsupportedPlayerVersion:function(_16){
log("unsupported player version");
this.setStatus({type:"error",message:LFM.String.unsupportedPlayerVersion});
},onTune:function(_17){
$$("#stationPlaybackErrors div").invoke("hide");
LFM.Page.RadioState.onTune(_17.error);
},onPlayback:function(_18){
var _19=function(_1a){
var _1b=Math.floor(_1a/60);
_1b=(""+_1b).length==1?"0"+_1b:_1b;
_1a=_1a%60;
_1a=(""+_1a).length==1?"0"+_1a:_1a;
return _1b+":"+_1a;
};
_18.position=Math.min(_18.duration,_18.position);
var _1c=Math.round(_18.position/_18.duration*10000)/100;
if(_1c<100){
$$("#progressBar span")[0].setStyle({width:_1c+"%"});
$("trackPlayed").update(_19(Math.round(_18.position/1000)));
$("trackRemaining").update("-"+_19(Math.round((_18.position-_18.duration)*-1/1000)));
}
},onCompleteTrack:function(){
if(this.stopOnTrackComplete){
LFM.log("Soft Stopping player");
this.inactivityDialog();
LFM.Flash.Player.stop();
}
},onNextTrack:function(_1d,_1e){
LFM.log("flash player onNextTrack event: "+_1d.albumImage);
if(_1d.manual){
this.logSkip();
}
if(!_1e){
_1e=0;
}
this.currentTrack=_1d;
this.playing=true;
document.title=_1d.creator+" - "+_1d.name+" - Last.fm";
if(_1d.manual){
setTimeout(function(){
LFM.Adserver.refreshAds();
},1000);
}
if(this.hasShout()){
log("has shout");
functionArguments=[_1d];
this.finishShout(LFM.Flash.Player.context.onNextTrack.bind(this),functionArguments);
}else{
this.hideContent();
setTimeout(function(){
LFM.Flash.Player.context.getMetadata(_1d.creator,_1d.name,_1e);
},100);
}
$("webRadioPlayer-visualisation").setStyle({backgroundImage:"none"});
this.toggleStopPlayButton();
this.setNowPlaying(this.currentTrack);
LFM.Page.RadioState.onNextTrack(function(){
this.loadArtist(_1d.creator);
}.bind(this));
},loadArtist:function(_1f){
if($("lfmSlideshow")&&$("lfmSlideshow").loadArtist){
$("slideshowPhotoCredits").hide();
log("loading artist image: "+encodeURIComponent(_1f));
try{
$("lfmSlideshow").loadArtist(encodeURIComponent(_1f));
}
catch(e){
LFM.error("Error calling Slideshow.loadArtist()");
LFM.log(e);
}
}else{
LFM.warn("slideshow unavailable loadArtist()");
}
},logInteraction:function(e,_21){
log("Logged interaction. Reset timer");
if(LFM.Page.InteractionTimer){
LFM.Page.InteractionTimer.reset();
}
if(e&&_21){
e.stop();
}
},interactionTimeout:function(){
LFM.log("Stop after this track");
this.stopOnTrackComplete=true;
LFM.Flash.Player.stopOnNextTrack();
},onStopTrack:function(_22){
if(this.stopOnTrackComplete){
this.stopOnTrackComplete=false;
_22=true;
}
this.playing=false;
this.toggleStopPlayButton();
document.title=this.originalTitle;
if(this.hasShout()){
this.finishShout("onFlashPlayerStopTrack");
}else{
this.removeContent();
if($("calltoaction")){
new Effect.Appear("calltoaction",{duration:0.5,delay:1});
}
}
$("listenContent").stopObserving();
this.setNowPlaying(false);
this.onPlayback({position:0,duration:1});
LFM.Page.RadioState.onStopTrack(_22);
if($("lfmSlideshow")&&$("lfmSlideshow").stopPlayback){
try{
$("lfmSlideshow").stopPlayback();
}
catch(e){
LFM.error("Error calling Slideshow.stopPlayback()");
LFM.log(e);
}
}else{
LFM.warn("slideshow unavailable stopPlayback()");
}
},logSkip:function(){
log("log skip");
LFM.Omniture.trackEvents("SkipTrack");
},logScroll:function(){
log("Scroll position: "+position);
LFM.Omniture.trackEvents("PageScroll");
},logFocus:function(){
LFM.Omniture.trackEvents("WindowFocus");
},clickSniffer:function(_23){
this.logInteraction(_23);
if(!(Prototype.Browser.IE)&&!_23.isLeftClick()){
return;
}
if(!this.playing){
return;
}
var _24=_23.findElement("a");
if(!_24){
return;
}
if(_24.hasClassName("stationbutton")||_24.hasClassName("scrobbleToggle")||_24.hasClassName("playCombo")){
return;
}
var _25=_24.pathname.replace(/^\//,"");
var _26=window.location.pathname.replace(/^\//,"");
if(_25==_26){
return;
}
if(_24.hasClassName("lfmSendButton")){
return;
}
if(_24.up("#listenContent")||_24.up("#sampleContent")||_24.up("#recentTracks")){
var _27="unknownLink";
if(_24.hasClassName("ontour")){
_27="onTourLink";
}else{
if(_24.up("#similarArtists")&&_24.up(".tags")){
_27="similarArtistsTagLink";
}else{
if(_24.up("#similarArtists")){
_27="similarArtistsLink";
}else{
if(_24.up("#shoutbox")){
_27="shoutboxLink";
}else{
if(_24.up("#sampleContent")){
_27="sampleContentLink";
}else{
if(_24.up("#topInfoBox")&&_24.hasClassName("artist")){
_27="artistNameInfoBoxLink";
}else{
if(_24.up("#topInfoBox")&&_24.up(".tags")){
_27="tagsInfoBoxLink";
}else{
if(_24.up("#topInfoBox")){
_27="InfoBoxLink";
}else{
if(_24.up("#events")){
_27="eventLink";
}
}
}
}
}
}
}
}
}
LFM.Omniture.prepareEvar("ClickSource",_27);
LFM.Omniture.trackEvents("Click");
log(_27);
}
_23.stop();
window.open(_24.href);
},focusCallback:function(){
log("focus callback");
if(this.playing){
this.logFocus();
}
},scrollSniffer:function(){
position=document.viewport.getScrollOffsets().top;
if(this.lastYPos!=undefined&&position!=this.lastYPos){
this.logScroll();
}
this.lastYPos=position;
},finishShout:function(_28,_29){
if(!$("shoutOutOutOutOut").visible){
new Effect.BlindDown("shoutOutOutOutOut",{duration:0.3});
}
if(LFM.Page.Shoutboxen){
actsAsAspect(LFM.Page.Shoutboxen.shoutbox);
LFM.Page.Shoutboxen.shoutbox.after("addShout",function(){
$("shoutmsg").value="";
_29.push(1);
log("function arguments:");
_29.each(function(arg){
log(arg);
});
_28.apply(this,_29);
});
$$("#shoutOutOutOutOut a")[0].observe("click",function(e){
$("shoutmsg").value="";
_28.apply(this,_29);
e.stop();
}.bind(this));
}
},getMetadata:function(_2c,_2d,_2e){
log("get meta data");
this.getArtistInfo(_2c,_2d,_2e,true);
},getArtistInfo:function(_2f,_30,_31){
var url="/listen/listeningNow";
log("get artist info: "+_2f+", "+_30+", "+_31);
if(isset(_2f)&&isset(_30)){
this.setStatus({type:"loading",message:LFM.String.loadingTrackInfo});
new Ajax.Request(url,{method:"get",parameters:{"artist":_2f,"track":_30,"shoutsuccess":_31,"ajax":1,"zone":LFM.Adserver.zone,"geo":LFM.Session.location,"res":LFM.Adserver.res},onSuccess:this.handleMetadataResponse.bind(this)});
}
},waitedShowResponse:function(){
this.handleMetadataResponse(this.waitingShowResponseArg);
},handleMetadataResponse:function(_33){
if(this.artistInfoBlinding){
this.waitingShowResponseArg=_33;
setTimeout(this.waitedShowResponse(),1000);
}
if(this.playing){
var _34=new LFM.Ajax.Response(_33);
if(_34.isError()){
log("Metadata Error: Invalid response, status: "+_33.status);
this.setStatus({type:"error",message:LFM.String.errorLoadingTrackInfo});
this.removeContent();
this.showContent();
return;
}
this.updateFreeTrialMessage(_34);
setTimeout(function(){
$("nowPlayingMeta").update(_34.get("html"));
if($("recentTracks")&&$("recentTracksSource")){
$("recentTracks").update($("recentTracksSource").remove().innerHTML);
}
if($("recentStations")&&$("recentStationsSource")){
$("recentStations").update($("recentStationsSource").remove().innerHTML);
}
LFM.Page.RadioState.fixPaneHeight();
setTimeout(function(){
new Effect.Appear("nowPlayingMeta",{duration:0.5,afterFinish:function(){
this.artistInfoBlinding=false;
setTimeout(LFM.Page.RadioState.fixPaneHeight.bind(LFM.Page.RadioState),20);
}.bind(this)});
$("button1").down().observe("click",this.logInteraction);
$("button2").down().observe("click",this.logInteraction);
}.bind(this),1);
}.bind(this),1);
this.setStatus(null);
this.isLovedTrack=_34.get("hasLovedTrack");
if($("playerControlLove").hasClassName("highlight")!=this.isLovedTrack){
$("playerControlLove").toggleClassName("highlight");
}
$("playerControlBan").removeClassName("highlight");
LFM.Adserver.setTandemID(_34.get("lfmtandem"));
}
this.setNewWindowTooltips();
this.showContent();
},onFreeTrialExpiry:function(){
log("Free trial expire");
if($("trialStart")){
$("trialStart").hide();
}
$("midTrial").hide();
$("trialExpired").show();
this.onStopTrack();
LFM.Page.RadioState.newStationError(LFM.Session.ERROR_TRIAL_EXPIRED);
},updateFreeTrialMessage:function(_35){
if(!_35.get("freeTrial")){
return;
}
if($("trialStart")){
$("trialStart").hide();
}
var _36=_35.get("freeTrialLeft");
log("Free trial left: "+_36);
if(_36==0){
log("Trial ended");
$("midTrial").hide();
$("trialExpired").show();
return;
}else{
if(_36<=5){
color=LFM.get("Page","trialRemainColourFinal");
}else{
color=LFM.get("Page","trialRemainColour");
}
}
var _37=$("trialLeftProgressBar");
if(_37){
var _38=_35.get("freeTrialPercentLeft")+"%";
log("Update progress: "+color+" / "+_38);
_37.setStyle({width:_38,background:"#"+color});
var _39={"trialLastPlay":(_36==1),"trialFewPlaysLeft":(_36<=5&&_36!=1),"trialPlaysLeft":(_36>5)};
for(trialMessageID in _39){
var _3a=$(trialMessageID);
if(_3a){
if(_39[trialMessageID]){
log("Show: "+trialMessageID);
var _3b=_3a.down("span.trialPlaysCount");
if(_3b){
_3b.update(_36);
}
_3a.show();
}else{
log("Hide: "+trialMessageID);
_3a.hide();
}
}
}
$("midTrial").show();
}
},hasShout:function(){
if($("shoutmsg")){
return shout=$F("shoutmsg").strip()!="";
}else{
return false;
}
},removeContent:function(){
if($("nowPlayingMeta")){
this.artistInfoBlinding=true;
new Effect.Fade("nowPlayingMeta",{duration:0.3,afterFinish:function(_3c){
this.artistInfoBlinding=false;
_3c.element.innerHTML="";
}.bind(this)});
}
log("removed all content");
},hideContent:function(){
$("trackMetadataOverlay").appear();
},showContent:function(){
$("trackMetadataOverlay").fade();
},unloadPage:function(_3d){
if($("dontTouchDialEnabled")&&$F("dontTouchDialEnabled")&&this.playing){
return LFM.String.unloadWarningMessage;
}
},toggleStopPlayButton:function(){
if(this.playing){
$("playerControlPlay").hide();
$("playerControlStop").show();
}else{
$("playerControlPlay").show();
$("playerControlStop").hide();
}
},setNowPlaying:function(_3e){
var _3f=$("playerTrackMeta");
var _40=function(_41,_42){
return new Element("a",{href:_41}).update(_42);
};
if(!_3e&&_3f.visible()){
_3f.hide();
}else{
if(_3e){
if(!_3f.visible()){
_3f.show();
}
_3e.creatorURL=_3e.trackURL.split("/").slice(0,-2).join("/");
_3f.down("p .artist").update(_40(_3e.creatorURL,_3e.creator));
_3f.down("p .track").update(_40(_3e.trackURL,_3e.name));
if(_3e.albumName){
_3f.down("p.album span.title").update(_40(_3e.albumURL,_3e.albumName));
}else{
_3f.down("p.album span.title").update(LFM.String.unknownAlbum);
}
}
}
},setNewWindowTooltips:function(){
$$("#nowPlayingMeta a").each(function(e){
if(!(e.up(".buttons")||e.hasClassName("toggle")||e.hash=="#toggle")){
e.setAttribute("title",LFM.String.newWindowTooltip);
}
});
},setStatus:function(_44){
var _45=$("listenStatus");
if(this.statusTimer){
log("Cancelling status timer");
clearTimeout(this.statusTimer);
}
_44=_44||{type:"empty",message:""};
log("Status Update Event: "+_44.message);
if(_45){
_45.className=_44.type;
_45.update(_44.message);
}
if(_44.duration){
log("Statu Update Event: Will fade in "+_44.duration);
this.statusTimer=setTimeout(this.setStatus.bind(this),_44.duration);
}
},disablePlayerControls:function(){
$("webRadioPlayer-content").addClassName("disabled");
},enablePlayerControls:function(){
$("webRadioPlayer-content").removeClassName("disabled");
},scrobbleToggle:function(e){
LFM.Page.Metadata.logInteraction(e,true);
this.scrobbling=!this.scrobbling;
LFM.Flash.Player.scrobble(this.scrobbling);
$("nowPlayingMeta").toggleClassName("scrobbling-enabled");
var _47=this.scrobbling?LFM.String.scrobblingEnabled:LFM.String.scrobblingDisabled;
_47=_47+" "+LFM.String.scrobblingHelp;
this.setStatus({type:"info",message:_47,duration:5000});
$("scrobbleToggle").toggleClassName("enabled");
LFM.Ajax.setUserPref("webRadioScrobbling",this.scrobbling?1:0);
},slideshowToggle:function(e){
LFM.Page.Metadata.logInteraction(e,true);
log("slideshowtoggle called");
this.slideshow=!this.slideshow;
$("slideshowToggle").toggleClassName("enabled");
var _49=this.slideshow?LFM.String.slideshowEnabled:LFM.String.slideshowDisabled;
this.setStatus({type:"info",message:_49,duration:5000});
if(LFM.Session.loggedIn){
LFM.Ajax.setUserPref("webRadioSlideshow",this.slideshow?1:0);
}
if($("lfmSlideshow")&&$("lfmSlideshow").toggleAnimation){
try{
$("lfmSlideshow").toggleAnimation();
}
catch(e){
LFM.error("Error calling Slideshow.toggleAnimation()");
LFM.log(e);
}
}else{
LFM.warn("slideshow unavailable toggleAnimation()");
}
},updateSlideshowPhoto:function(_4a){
if(_4a.image.owner){
var _4b=_4a.image.owner.name;
var _4c=_4a.image.url;
if(_4b){
$("slideshowPhotoCredits").update(LFM.String.slideshowPhotoCaption);
$$("#slideshowPhotoCredits span.author")[0].update(_4b);
$("slideshowPhotoCredits").setAttribute("href",_4c);
$("slideshowPhotoCredits").show();
return true;
}
}
$("slideshowPhotoCredits").hide();
return false;
},inactivityDialog:function(){
var _4d=LFM.AJAXDialogWrapper("/ajax/dialog/stilllistening",{title:LFM.String.stillListening,fadeDone:true,modal:true,parameters:{width:"500px"},onConfirm:function(e){
e.stop();
LFM.refreshPage();
this.hide();
},onCancel:function(){
LFM.Page.Metadata.onStopTrack();
this.hide();
}});
_4d({id:LFM.Page.RadioState.currentStation.id,type:LFM.Page.RadioState.currentStation.type,url:LFM.Page.RadioState.currentStation.url},{});
},problemDialog:function(_4f){
var _50=LFM.AJAXDialogWrapper("/ajax/dialog/radioproblem",{title:LFM.String.radioProblems,fadeDone:true,modal:true,parameters:{width:"500px",isAdBlocking:_4f},onConfirm:function(e){
e.stop();
LFM.refreshPage();
this.hide();
}});
_50();
}})});
LFM.set("Radio",{MixedContentPane:{expanded:false,MIN_HEIGHT:320,MAX_HEIGHT:426,expand:function(_52,_53){
if(_52<this.getHeight()){
log("cant resize content pane to a size smaller than the current height");
return;
}
log("expanding MixedContentPane to "+_52);
var _52=Math.min(_52,this.MAX_HEIGHT);
if(!this.expanded){
this.expanded=true;
var _54=_52-$("webRadioPlayer-content").getHeight();
log("expander height "+_54);
$("mixedContentPaneExpander").setStyle({height:_54+"px"});
LFM.info("mixedContentPaneExpander getStyle(height): "+$("mixedContentPaneExpander").getStyle("height"));
LFM.info("mixedContentPaneExpander style.height: "+$("mixedContentPaneExpander").style.height);
LFM.info("mixedContentPaneExpander getHeight: "+$("mixedContentPaneExpander").getHeight());
new Effect.BlindDown("mixedContentPaneExpander",{afterFinish:_53.afterFinish.bind(_53.target),duration:0.5,delay:2});
}else{
_53.afterFinish.bind(_53.target);
}
},collapse:function(_55){
if(this.expanded){
$("mixedContentPaneExpander").setStyle({display:"block"});
this.expanded=false;
Effect.BlindUp("mixedContentPaneExpander",{restoreAfterFinish:false,scaleContent:false,afterFinish:_55.afterFinish.bind(_55.target),duration:0.5});
}else{
_55.afterFinish.apply(_55.target);
}
},getHeight:function(){
return $("webRadioPlayer-content").getHeight();
},isExpanded:function(){
return this.expanded;
}}});
(function(){
var _56=window.location.hash.substr(1).toQueryParams();
if(_56&&_56.station){
document.loaded=true;
window.location=decodeURIComponent(_56.station);
}
})();
LFM.set("Radio",{State:Class.create({currentPane:"webRadioPlayer",tuningStation:null,currentStation:null,tuning:false,retuning:false,updating_hash:false,switching_panes:false,adsLoaded:false,initialize:function(_57,_58){
LFM.log("initialize Radio State");
if(_57){
this.setTuneState(_57);
}
if(_58){
this.currentPane=_58;
}
this.setupListeners();
this.setupIntervals();
this.prefersClient=LFM.get("Session","prefersClient");
},hasStation:function(){
if(this.currentStation||this.tuningStation){
return true;
}
return false;
},hasCurrentStation:function(){
return this.currentStation!=null;
},getStationURL:function(){
if(this.hasCurrentStation()){
return this.currentStation.url;
}else{
if(this.tuningStation){
return this.tuningStation.url;
}
}
},getDecodedCurrentStationURL:function(){
if(this.hasCurrentStation()){
return decodeURIComponent(decodeURIComponent(this.currentStation.url));
}
return "";
},setupIntervals:function(){
setInterval(this.checkCurrentPane.bind(this),1000);
},findElementLocation:function(_59){
var _5a=_59.up("#userStations,"+"#recentStations,"+"#recentTracks,"+"#recentStationsTab,"+"#playlistsTab,"+"#tagStationsTab,"+"#recommendedStations,"+"#simpleStarter,"+"#multiTagTab,"+"#multiArtistTab,"+"#listenContent,"+"#webRadioPlayer,");
if(_5a){
var _5b=_5a.id;
$w("stationTable webRadioHeader multiTunerContainer stationSection").each(function(_5c){
if(_59.up("."+_5c)){
_5b+="."+_5c;
throw $break;
}
});
return _5b;
}
return false;
},setupListeners:function(){
document.observe("click",function(e){
var _5e;
_5e=e.findElement("a.switchPane");
if(_5e){
e.stop();
var _5f=_5e.hash.substr(1);
var _60=this.findElementLocation(_5e);
if(_60){
var _61=_5f+"["+_60+"]";
LFM.Omniture.prepareEvar("ClickSource",_61);
}else{
LFM.Omniture.prepareEvar("ClickSource","unknownLocation");
}
LFM.Omniture.trackEvents("RadioPaneSwitch");
this.switchPanes(_5f);
}
_5e=e.findElement("img.dismiss_trans_icon");
if(_5e){
$$(".starterError").invoke("hide");
this.fixPaneHeight();
}
_5e=e.findElement("#shareStation");
if(_5e){
e.stop();
if(this.currentStation){
LFM.Send(this.currentStation);
}
}
_5e=e.findElement("a.playCombo");
if(_5e){
e.stop();
var _60=this.findElementLocation(_5e);
if(_60){
var _61="comboStation["+_60+"]";
LFM.Omniture.prepareEvar("ClickSource",_61);
}else{
LFM.Omniture.prepareEvar("ClickSource","unknownLocation");
}
this.fetchStationFromForm(_5e.up("form"));
}
_5e=e.findElement("a.stationbutton");
if(_5e){
if(!_5e.protocol.include("lastfm")){
e.stop();
var _60=this.findElementLocation(_5e);
if(_60){
var _61="stationBtn["+_60+"]";
LFM.Omniture.prepareEvar("ClickSource",_61);
}else{
LFM.Omniture.prepareEvar("ClickSource","unknownLocation");
}
this.fetchStationFromURL(_5e.pathname);
}
}
}.bindAsEventListener(this));
$$("form.starterForm").each(function(_62){
_62.observe("submit",function(e){
e.stop();
var _64=this.findElementLocation(_62);
if(_64){
var _65="starterForm["+_64+"]";
LFM.Omniture.prepareEvar("ClickSource",_65);
}else{
LFM.Omniture.prepareEvar("ClickSource","unknownLocation");
}
this.fetchStationFromForm(_62);
}.bind(this));
}.bind(this));
},checkCurrentPane:function(){
if(this.updating_hash||this.retuning||this.tuning||this.switching_panes){
return false;
}
var _66=this.getLocationHash();
if(!_66.station&&this.hasCurrentStation()){
log("set hash params to getDecodedCurrentStationURL");
_66.station=this.getDecodedCurrentStationURL();
}
if(!_66.pane){
if(this.currentStation){
_66.pane="webRadioPlayer";
}else{
_66.pane="simpleStarter";
}
}
if(!this.prefersClient&&_66.station){
var _67=this.getDecodedCurrentStationURL();
if(_67!=_66.station){
log("hash out of sync with tuned station");
log(" - current url: "+_67);
log(" - hash url: "+_66.station);
LFM.Omniture.prepareEvar("ClickSource","hashSync");
this.fetchStationFromURL(_66.station);
return true;
}
}
if(_66.pane&&_66.pane!=this.currentPane){
this.switchPanes(_66.pane);
return true;
}
},switchPanes:function(_68,_69){
if($(_68)&&$(_68).hasClassName("webRadioPane")){
if(this.currentPane==_68){
this.updateLocationHash();
if(_69){
_69();
}
}else{
log("switch to: "+_68);
this.switching_panes=true;
from_element=$(this.currentPane);
if(this.currentPane!="webRadioPlayer"){
$$(".starterError").invoke("hide");
}
this.currentPane=_68;
var _6a=$(this.currentPane);
$$("div.starterPane").invoke("hide");
from_element.show();
$("webRadio").setStyle({left:from_element.positionedOffset().left*-1+"px"});
this.fixPaneHeight();
if(_6a){
_6a.show();
new Effect.Move("webRadio",{x:_6a.positionedOffset().left*-1,y:0,mode:"absolute",duration:0.2,transition:Effect.Transitions.sinoidal,afterFinish:function(el){
new Effect.ScrollTo(document.body,{duration:0.2});
this.updateLocationHash();
this.switching_panes=false;
if(_69){
_69();
}
}.bind(this)});
}
}
}
},fixPaneHeight:function(){
if(!LFM.Adserver.hasPreRoll()){
$("webRadioWrapper").setStyle({height:$(this.currentPane).getHeight()+"px"});
}
},fetchStationFromURL:function(url){
if(!url.startsWith("/")){
url="/"+url;
}
if(this.hasCurrentStation()){
log("current station: "+this.getDecodedCurrentStationURL());
}
log("fetching new station from url: "+url);
this.newStationLoading();
LFM.Omniture.trackEvents("RadioLaunch");
new Ajax.Request("/listen/tune",{method:"get",parameters:{"ajax":1,"url":url,"zone":LFM.Adserver.zone,"geo":LFM.Session.location},onComplete:this.newStationHandler.bind(this)});
},fetchStationFromForm:function(_6d){
var _6e=_6d.down("input[type=submit]");
if(_6e){
_6e.blur();
}
var _6f=_6d.serialize(true);
var _70=!_6f.name||_6f.placeholder;
log("isBlankSearch: "+_70);
var _71=$$("#recentStationsList ul li a")[0];
if(_70&&_6f.type=="artisttag"){
if(_71){
log("fetching last station: "+_71.pathname);
LFM.Omniture.prepareEvar("ClickSource","restartLastStation");
this.fetchStationFromURL(_71.pathname);
}else{
return false;
}
}else{
LFM.Omniture.trackEvents("RadioLaunch");
if(this.prefersClient){
_6d.submit();
return;
}
if(this.hasCurrentStation()){
log("current station: "+this.getDecodedCurrentStationURL());
}
log("fetching new station from form: "+Object.toQueryString(_6f));
this.newStationLoading();
_6d.request({method:"get",parameters:{"ajax":1,"zone":LFM.Adserver.zone,"geo":LFM.Session.location},onComplete:this.newStationHandler.bind(this)});
}
},setTuneState:function(_72){
log("new station: "+_72.url);
this.tuning=true;
this.tuningStation=_72;
if(LFM.Adserver.hasPreRoll()){
setTimeout(this.checkAdBlocking.bind(this),3000);
}
},newStationLoading:function(){
this.retuning=true;
$$(".nowPlaying").invoke("hide");
$$(".tuneLoading").invoke("show");
new Effect.ScrollTo(document.body,{duration:0.2});
this.fixPaneHeight();
},newStationLoaded:function(){
this.retuning=false;
this.resuming=false;
$$(".tuneLoading").invoke("hide");
$$(".nowPlaying").invoke("show");
$$(".starterError").invoke("hide");
this.fixPaneHeight();
},newStationHandler:function(_73){
var _74=new LFM.Ajax.Response(_73);
if(_74.isError()){
log("New station error");
log(_74);
this.newStationError(_74.getErrorCode());
}else{
var _75=_74.getResource();
if(_75.parent){
LFM.Adserver.setResource(_75.parent);
LFM.Adserver.setZone(LFM.Adserver.stationZone);
LFM.Adserver.setStation(_75.url);
}
LFM.Adserver.setTandemID(_74.get("lfmtandem"));
if($("webRadioPlayer-title")){
log("Update player content");
$("webRadioPlayer-title").update(new Element("span",{title:_75.name}).update(_75.name.truncate(30,"\u2026")));
if($("shareStation")){
$("shareStation").href=_75.url;
}
var _76=_74.get("sampleContent");
if(_76&&_76.items&&_76.items.length){
var _77=_76.items.inGroupsOf(3)[0].collect(function(_78){
if(!_78){
throw $break;
}
return _78.res.name;
}).join(", ");
$("sampleContent").update(_77);
$("sampleContent").show();
}else{
$("sampleContent").update("");
$("sampleContent").hide();
}
this.setTuneState(_75);
LFM.Flash.Player.stop();
if(LFM.Adserver.hasPreRoll()){
LFM.info("Radio State: serve Preroll");
this.switchPanes("webRadioPlayer");
LFM.Adserver.servePreRoll();
}else{
if(LFM.Flash.PreRoll.isDART()){
LFM.Flash.PreRoll.hide();
}
LFM.info("Radio State: Tune flash player");
LFM.Flash.Player.tune(_75.url);
}
}
}
},onTune:function(_79){
LFM.info("Radio State onTune");
LFM.Flash.PreRoll.onTune();
this.fixPaneHeight();
if(_79){
LFM.dir(_79);
LFM.warn("Tuning error: "+_79.code+": "+_79.message);
this.clearCurrentStation();
this.newStationError(_79.code);
}else{
this.currentStation=this.tuningStation;
LFM.Flash.Player.stationURL=this.currentStation.url;
LFM.info("tuned station: "+this.currentStation.url);
if(LFM.Page.InteractionTimer){
LFM.Page.InteractionTimer.start();
}
this.hideAdBlockingError();
}
this.tuning=false;
this.tuningStation=null;
this.updateLocationHash();
},newStationError:function(_7a){
this.retuning=false;
$$(".tuneLoading").invoke("hide");
$$(".starterError").invoke("hide");
if($$(".starterError"+_7a).length){
$$(".starterError"+_7a).invoke("show");
}else{
$$(".starterErrorDefault").invoke("show");
}
LFM.Omniture.prepareEvar("ErrorCode",_7a);
LFM.Omniture.trackEvents("RadioError");
if(this.currentPane=="webRadioPlayer"){
this.switchPanes("simpleStarter");
}
this.fixPaneHeight();
},onNextTrack:function(_7b){
LFM.info("onNextTrack");
if(this.tuning){
LFM.warn("Calling onTune for buggy Flash player");
this.onTune();
}
if(this.retuning||this.resuming){
this.switchPanes("webRadioPlayer",_7b);
LFM.Adserver.refreshAds();
LFM.log("New station started");
this.newStationLoaded();
}else{
this.hideAdBlockingError();
if(_7b){
_7b();
}
}
},onStopTrack:function(_7c){
if(LFM.Page.InteractionTimer){
LFM.Page.InteractionTimer.stop();
}
if(!_7c&&!this.retuning){
LFM.Omniture.prepareEvar("ClickSource","stopBtn");
LFM.Omniture.trackEvents("StopPlayer");
this.switchPanes("simpleStarter");
this.clearCurrentStation();
}
},clearCurrentStation:function(){
$$(".nowPlaying").invoke("hide");
this.currentStation=null;
LFM.Adserver.setZone(LFM.Adserver.landingZone);
this.updateLocationHash();
},getLocationHash:function(){
var _7d=window.location.hash.substr(1).toQueryParams();
if(_7d.station){
_7d.station=decodeURIComponent(_7d.station);
}
return _7d;
},updateLocationHash:function(){
var _7e=this.getLocationHash();
var _7f={pane:this.currentPane};
if(this.hasCurrentStation()){
_7f.station=this.getDecodedCurrentStationURL();
}
if((_7f.pane!=_7e.pane)||(_7f.station!=_7e.station)){
this.updating_hash=true;
setTimeout(function(){
if(_7f.station){
_7f.station=encodeURIComponent(_7f.station);
}
var _80=Object.toQueryString(_7f);
window.location.hash=_80;
this.updating_hash=false;
}.bind(this),100);
}
},checkAdBlocking:function(){
if((LFM.isAdBlocking()&&$("adBlockError"))&&!this.adsLoaded){
Effect.SlideDown($("adBlockError"));
}
},hideAdBlockingError:function(){
this.adsLoaded=true;
if($("adBlockError")){
$("adBlockError").hide();
}
}})});

