var Masthead=Class.create({initialize:function(){this.message=$('body_massage');this.copy_wrap=$('body_massage_copy');this.message_copy=Translation["guest_copy"];this.image_path=_jm.image_path||'http://cd09.s3.static.jango.com/images/';},series3:function(){this.stop_it();_jm.stop_gxp=false;if(_jango.gxp){_jm["guest_xp_state_"+_jango.gxp.series]=_jango.gxp.place;}
_jango.fire_guest_xp(3);},thumbs:function(){this.show_message('thumbs');},artist_settings_xp:function(){this.finetune_artist_modal();this.highlight_artist_settings();},variety_settings_xp:function(){this.finetune_variety_modal();this.highlight_variety_settings();},highlight_and_jiggle:function(id,ec,wait){var ec=ec||'#BEC2C5';var wait=wait||0;$(id).highlight({duration:2,startcolor:'#CFFF11',endcolor:ec,delay:wait});$(id).pulsate({pulses:2,duration:2,delay:wait});},highlight_thumbs_up:function(){this.highlight_and_jiggle('player_love');},highlight_thumbs_down:function(){this.highlight_and_jiggle('player_hate');},highlight_skip:function(){this.highlight_and_jiggle('btn-ff');},highlight_settings:function(){this.highlight_artist_settings(0);this.highlight_variety_settings(0);this.highlight_artist_settings(2);this.highlight_variety_settings(2);},highlight_variety_settings:function(delay){this.highlight_and_jiggle('now_station_variety','#D6EBFE',delay);},highlight_artist_settings:function(delay){this.highlight_and_jiggle('now_station_artist','#D6EBFE',delay);},highlight_new_station:function(){this.highlight_and_jiggle('masthead-search');},message_close:function(){if(this.message&&this.message.visible()){this.message.fade({duration:0.5});}},stop_it:function(){if(this.message&&this.message.visible()){this.message.fade({duration:0.5});}
_jm.stop_gxp=true;try{if(_jango&&_jango.gxp){_jango.gxp.stop();}
this.pause();}catch(err){}},build_crumbs:function(length){$('body_massage_crumbs').down('ul').update("");(length||_jango.gxp.series_length).times(function(){$('body_massage_crumbs').down('ul').insert(new Element('li'));});this.body_crumb_elements=$$('#body_massage_crumbs li');},crumbs:function(){if(!this.body_crumb_elements||this.body_crumb_elements.length==0){this.build_crumbs();}
this.body_crumb_elements.invoke("removeClassName","current");if(_jango.gxp&&_jango.gxp.visible_place()!=null){this.body_crumb_elements[_jango.gxp.visible_place()].addClassName('current');}},play_next:function(first_seed,next_artist){this.show_message('play_next',{copy_vars:{artist_name:first_seed||null,next_artist_name:next_artist||null}});},created_message:function(stationname,artistname){this.show_message('created_station',{copy_vars:{station_name:stationname||null,artist_name:artistname||null}});},listening_message:function(stationname,artistname){this.show_message('listening_message',{copy_vars:{station_name:stationname||null,artist_name:artistname||null}});},listening_playlist:function(stationname,artistname){this.show_message('listening_playlist',{copy_vars:{station_name:stationname||null,artist_name:artistname||null}});},finetune:function(){this.show_message('finetune');},finetune_variety_playlist:function(){modals.hide_all();modals.close_clean();modals.variety_settings();this.show_message('finetune_variety_playlist');},finetune_variety_message:function(){this.show_message('finetune_variety');},finetune_artist_message:function(){this.show_message('finetune_artists');},finetune_artist_modal:function(){modals.ass_cloud();},finetune_variety_modal:function(){modals.variety_settings(true);},skip:function(){this.show_message('skip');},settings:function(){this.show_message('settings');},or_create:function(){this.show_message('or_create');},parse_callback:function(func){if(!func){return null;}
var a=func.split(".");var obj=window;a.each(function(str){if(!obj||!obj[str]){obj=null;return;}
obj=obj[str];});return obj;},show_message:function(message_type){this.message.hide();this.message.className='';this.message.addClassName('round_message');this.message.addClassName(message_type);this.crumbs(message_type);var options=Object.extend({action:null,copy_vars:null},arguments[1]||{});var messagecopy=this.message_copy[message_type];if(options.copy_vars){if(!options.copy_vars.station_name){options.copy_vars.station_name=_jm.station_name;}
if(!options.copy_vars.artist_name){options.copy_vars.artist_name=_jm.station_first_seed_name;}
if(!options.copy_vars.next_artist_name){options.copy_vars.next_artist_name=_jm.song_info?_jm.song_info.artist:"";}
messagecopy=new Template(messagecopy).evaluate(options.copy_vars);}
this.copy_wrap.update(messagecopy);this.message.appear({duration:0.5,afterFinish:function(){if(options.action){var pc=this.parse_callback(options.action);if(typeof pc=="function"){pc();}}}.bind(this)});},signup_message:function(){this.show_message('signup_with_jango');},signup_facebook_message:function(){this.show_message('signup_with_facebook');},signup_overlay:function(){this.message.className='';this.message.hide();popme('unlimited');if(_jango&&_jango.gxp){_jango.gxp.stop();}},pause:function(){jango_player.artist_pic_out();if($('stations_list_cta')){$('stations_list_cta').up('div.masker').remove();}
this.message_close();modals.hide_all();modals.close_clean();}});var GuestXP=Class.create({initialize:function(series,station_type){this.series=series||1;this.station_type=station_type||"artist";this.series=(this.station_type=="playlist")?0:this.series;this.place=_jm["guest_xp_state_"+this.series]||0;if(this.station_type=='artist'){switch(this.series){case 1:this.visible_places=["created_message","finetune","finetune_artist_message","finetune_variety_message","signup_message"];this.series_length=this.visible_places.length;masthead.build_crumbs(this.series_length);this.duration={"pause1":3,"created_message":6,"pause2":1,"finetune":2,"highlight_settings":4,"finetune_artist_message":1,"artist_settings_xp":7,"finetune_variety_message":1,"variety_settings_xp":7,"pause4":1,"signup_message":3,"signup_overlay":1};break;case 2:this.visible_places=["play_next","thumbs","signup_facebook_message"];this.series_length=this.visible_places.length;masthead.build_crumbs(this.series_length);this.duration={"pause1":1,"play_next":6,"pause2":1,"thumbs":2,"highlight_thumbs_up":2,"highlight_thumbs_down":2,"highlight_skip":2,"pause3":1,"signup_facebook_message":3,"signup_overlay":1};break;}}else{this.visible_places=["listening_playlist","skip","settings","or_create","signup_facebook_message"];this.series_length=this.visible_places.length;masthead.build_crumbs(this.series_length);this.duration={"pause1":3,"listening_playlist":6,"pause2":1,"skip":2,"highlight_skip":3,"pause3":1,"settings":1,"highlight_variety_settings":3,"pause4":1,"or_create":2,"highlight_new_station":3,"pause7":1,"signup_facebook_message":3,"signup_overlay":1};}
this.places=$H(this.duration).keys();this.counter=0;if(_jm.stop_gxp){this.stop();return false;}else{this.start();}},increment_place:function(){this.place=++this.place||0;this.counter=0;_jm["guest_xp_state_"+this.series]=this.place;},visible_place:function(){var n=this.visible_places.indexOf(this.current_place());return(n==-1)?null:n;},stop:function(){if(this.motion){this.motion.stop();}},start:function(){if(this.motion){this.stop();}
this.motion=new PeriodicalExecuter(this.view.bind(this),1);},current_place:function(){return this.places[this.place];},next_action:function(){this.increment_place();var cp=this.current_place();if(cp&&cp.match(/^pause/)){cp="pause";}
if(cp&&window['masthead']&&masthead[cp]){return masthead[cp]();}else{this.stop();}},view:function(){if(_jm.stop_gxp){this.stop();return false;}
this.counter++;if(($('signup-window')&&$('signup-window').visible())||($('media-window')&&$('media-window').visible())||($('listen_overlay')&&$('listen_overlay').visible())){this.stop();return false;}
var cp=this.current_place();var d=cp&&this.duration[cp];if(cp&&d&&this.counter>=d){this.next_action();}}});_jango.fire_guest_xp=function(series,station_type){if(this.gxp){this.gxp.stop();}
this.gxp=new GuestXP(series,station_type);};
