(function(jQuery){jQuery.extend({tmpl:function(tmpl,vals){var rgxp,repr;tmpl=tmpl||'';vals=vals||{};rgxp=/\#\;([^\;]*)\;/g;repr=function(str,match){return typeof vals[match]==='string'||typeof vals[match]==='number'?vals[match]:str;};return tmpl.replace(rgxp,repr).replace(/_src/g,'src');}});})(jQuery);function cc(){return;if(typeof(console)!='undefined'&&typeof(console.log)!='undefined'){console.log(arguments);}else{return;alert(arguments[0]);}}
jQuery.extend({toggleEls:function(a1,a2,i){if(i){jQuery(a1).css('display','block');jQuery(a2).hide();}else{jQuery(a1).hide();jQuery(a2).css('display','block');}},timeFormat:function(time_str){return;},arr:{remove:function(arr,from,to){var rest=arr.slice((to||from)+1||arr.length);arr.length=from<0?arr.length+from:from;return arr.push.apply(arr,rest);},adopt:function(arr,newbie,oldguy){arr.splice((oldguy&&jQuery.inArray(oldguy,arr)>-1)?jQuery.inArray(oldguy,arr)+1:arr.length,0,newbie);return arr;},removeValue:function(arr,a){jQuery.arr.remove(arr,jQuery.inArray(a,arr));return arr;}}});jQuery.fn.extend({fc:function(){this.click(function(){return false;}).focus(function(){this.blur();});},co:function(fn){this.bind('mousedown',fn).fc();return this;},ce:function(fn){this.unbind('mousedown').bind('mousedown',fn).fc();return this;},cc:function(){if(m.debug)cc(this);return this;},ds:function(){this.attr('disabled',!this.attr('disabled'));},switchClass:function(class1,class2){this.removeClass(class1).addClass(class2);}});var m=m||{};jQuery.extend(m,{stack:{carol_swf:null},carol:null,cache:{persists:{}},persist_active:true});jQuery.extend(m,{initAjaxAuthFilter:function(trigger_it){jQuery('#fixed_width').unbind('ajaxComplete.mLogin').bind('ajaxComplete.mLogin',function(r,s){if(s&&s.responseText=='403')m.showLoginForm();});},loginRequiredFilter:function(){if(!theUser){m.showLoginForm(1);return true;}},showLoginForm:function(just_login){deep_login();},loginPlzEl:function(el_id){if(!theUser){jQuery(el_id).ce(function(){deep_login();});return true;}
return false;}});jQuery.extend(m,{swfById:function(swf_id){if(navigator.appName.indexOf("Microsoft")!=-1){return window[swf_id];}else{return document[swf_id];}},initPersist:function(name,options){m.stack.carol_swf=m.swfById('persist_flash');if(!m.stack.carol_swf)return;var carol=jQuery.extend({},{get:function(key,opts){var val=m.stack.carol_swf.getFromPersist(key);return typeof(val)=='undefined'?null:val;},set:function(key,val,opts){m.stack.carol_swf.saveToPersist(key,val);return 1;}});m.carol=carol;var ensureSwfActive=function(){if(m.stack.carol_swf&&m.stack.carol_swf.saveToPersist){var nn=1;setTimeout(function(){m.loadPersist('friend')},500*nn);setTimeout(function(){m.loadPersist('ilike_playlist')},1000*nn);setTimeout(function(){m.loadPersist('favor')},1500*nn);setTimeout(function(){m.loadPersist('ilike_artist')},2000*nn);setTimeout(function(){m.loadPersist('ilike_album')},2500*nn);setTimeout(function(){m.loadPersist('ilike_track')},3000*nn);}else{if((m.ensureSwfActiveTimes?m.ensureSwfActiveTimes++:m.ensureSwfActiveTimes=1)<10){setTimeout(ensureSwfActive,1000);}}}
ensureSwfActive();m.initFavorable();},freshPersist:function(key,fn){if(!theUser)return;if(!(m.cache.persists['user_matched']||(m.carol.get('user_id')&&m.carol.get('user_id')==theUser.userId))){m.carol.set('ts_l',null);m.carol.set('user_id',theUser.userId);m.cache.persists['user_matched']=1;}
if(m.cache.persists[key]){if(jQuery.isFunction(fn))fn.call(fn,m.cache.persists[key]);return m.cache.persists[key];}
else{if(!m.cache.persists['ts_l']){var ts_l_a=m.carol.get('ts_l')?m.carol.get('ts_l').split(','):[]
m.cache.persists['ts_l_alias']={ilike_artist:0,ilike_album:1,ilike_track:2,friend:3,favor:4,ilike_playlist:5}
m.cache.persists['ts_l']=ts_l_a;}
if(!m.cache.persists['ts_r']){if(null&&EasyCookie.get('persist_ts')){m.cache.persists['ts_c']=EasyCookie.get('persist_ts').split('|');function tsBy(key){return m.cache.persists['ts_c'][m.cache.persists['ts_l_alias'][key]];}
m.cache.persists['ts_r']={ilike_artist:tsBy('ilike_artist'),ilike_album:tsBy('ilike_album'),ilike_track:tsBy('ilike_track'),friend:tsBy('friend'),favor:tsBy('favor'),ilike_playlist:tsBy('ilike_playlist')}}
else{if(!m.cache.persists['fetched']){m.cache.persists['fetched']=1;jQuery.getJSON('/persist',{user_id:theUser.userId},function(data){jQuery.extend((m.cache.persists['ts_r']={}),data);return m.syncPersist(key,fn);});}}}
else{return m.syncPersist(key,fn);}}},syncPersist:function(key,fn){if(m.cache.persists['ts_r'][key]!=m.cache.persists['ts_l'][m.cache.persists['ts_l_alias'][key]]){jQuery.getJSON('/persist/'+key,{user_id:theUser.userId},function(data){var ds=jQuery.makeArray(data).slice(0,1000);m.carol.set(key,ds.join(','));m.cache.persists['ts_l'][m.cache.persists['ts_l_alias'][key]]=m.cache.persists['ts_r'][key];m.carol.set('ts_l',m.cache.persists['ts_l'].join(','));m.cache.persists[key]=ds.map(function(d){return d+'';});if(jQuery.isFunction(fn))fn.call(fn,data);return m.cache.persists[key];});}
else{m.cache.persists[key]=m.carol.get(key)?m.carol.get(key).split(','):[];if(jQuery.isFunction(fn))fn.call(fn,m.cache.persists[key]);return m.cache.persists[key];}},loadPersist:function(key){switch(key){case'ilike_artist':if(m.loginPlzEl('#artist_add'))return;m.freshPersist('ilike_artist',function(arr){return;m.artists=jQuery('.artist_anchor').map(function(){if(jQuery.inArray(jQuery(this).attr('rel'),arr)>-1){jQuery(this).css('color','red');}
if(m.persist_active&&page_data.tile_ilike_check){jQuery(this).css('background-color','pink');}});});break;case'ilike_album':if(m.loginPlzEl('#album_add'))return;m.freshPersist('ilike_album',function(arr){return;m.albums=jQuery('a[href*="/albums/"]').map(function(index){var id=jQuery(this).attr('href').match(/albums\/(\d+)/)[1];if(jQuery.inArray(id,arr)>-1){jQuery(this).css('color','red').find('img').css('border','2px solid blue');}});});break;case'ilike_playlist':if(m.loginPlzEl('#playlist_add'))return;m.freshPersist('ilike_playlist',function(arr){return;});break;case'ilike_track':m.freshPersist('ilike_track',function(arr){return;jQuery.each(jQuery('.song, .song_noborder'),function(){if(jQuery.inArray(jQuery(this).attr('rel'),arr)>-1){jQuery(this).find('.ilike-icon').removeClass('ilike-icon').addClass('ilike-icon-active').attr('title','我推荐过这个歌曲!');}});});break;case'favor':m.freshPersist('favor',function(arr){jQuery.each(jQuery('.favor-star'),function(){if(jQuery.inArray(jQuery(this).attr('rel'),arr)>-1){jQuery(this).removeClass('favor-star').addClass('favor-star-active').attr('title','我已经收藏这个歌曲了!');}});});break;case'friend':if(m.loginPlzEl('#fr_addremove_rbar'))return;m.freshPersist('friend',function(arr){if(m.persist_active&&jQuery('#fr_addremove_rbar').length){m.loadFriendship();}});if(m.persist_active)m.initiLikeBtn();break;default:break;}},initFavorable:function(){jQuery('.favor-star, .favor-star-active').ce(function(){if(!theUser){deep_login();return false;}
var mt=jQuery(this);var t_id=mt.attr('rel');jQuery.ajax({url:'/monitorships/favor_async',type:'POST',data:{track_id:t_id,playlist_id:'-1',shortcut:1},dataType:'json',beforeSend:function(){mt.addClass('favor-star-working');},success:function(data){var a,b;if(data.r){a='favor-star';b='favor-star-active';c='收藏成功!'}else{b='favor-star';a='favor-star-active';c='不再收藏这首歌.'}
mt.removeClass(a).removeClass('favor-star-working').addClass(b).attr('title',c);if(m.persist_active)m.freshPersist('favor',function(d){var key='favor';m.cache.persists[key]=(function(d){if(data.r){d.push(t_id);return d;}else{return jQuery.arr.removeValue(d,t_id+'');}})(jQuery.makeArray(d));m.carol.set(key,m.cache.persists[key].join(','));m.cache.persists['ts_l'][m.cache.persists['ts_l_alias'][key]]=data.t;m.carol.set('ts_l',m.cache.persists['ts_l'].join(','));});}});});},loadFriendship:function(){function onDetectShip(ship){switch(parseInt(ship)){case 7:return jQuery('#friend_waiting');break;case 1:return jQuery('#friend_remove');break;default:return jQuery('#friend_add');break;}}
function activeBtn(btn,v){jQuery('#friend_add').hide();btn.css('display','block').ce(function(){if(!v||v!=7){jQuery.getJSON(btn.attr('_href'),function(data){btn.hide();onDetectShip(data).css('display','block').ce(function(){});});}});}
var p={hid:page_data.host.id,htp:page_data.host.type,gid:theUser.userId};jQuery('#fr_addremove_rbar').html(jQuery.tmpl(jQuery('#fr_addremove_rbar').html(),p));if(jQuery('#send_user_message').length)m.buildUserMessageForm();if(m.persist_active&&m.cache.persists['friend']){if(jQuery.inArray(page_data.host.id+'',m.cache.persists['friend'])>-1){activeBtn(jQuery('#friend_remove'));}else{activeBtn(jQuery('#friend_add'));}
jQuery('#fr_addremove_rbar').show();}else{jQuery.getJSON('/playground/friends_check',p,function(data){activeBtn(onDetectShip(data.fr),data.fr);jQuery('#fr_addremove_rbar').show();});}
if(jQuery.isFunction(initClip))initClip('shareurl');},buildUserMessageForm:function(){jQuery('#send_user_message').ce(function(){jQuery('#submit_user_form').toggle();});jQuery('#cancel_user_message').ce(function(){jQuery('#submit_user_form').hide();});jQuery('#submit_user_message').ce(function(){jQuery.ajax({url:jQuery('#submit_user_form').attr('action'),data:{send_user_message_body:jQuery('#send_user_message_body').val()},type:'POST',success:function(){jQuery('#submit_user_form').hide();jQuery('#send_user_message_status').html('发送成功!').show();jQuery('#send_user_message').html('再发送一条?');},error:function(){jQuery('#submit_user_form').hide();jQuery('#send_user_message_status').html('发送失败!').show();jQuery('#send_user_message').html('再试一遍?');}});});},initiLikeBtn:function(){if(page_data.host.type=='album'){if(jQuery('#album_remove').length)m.loadiLikeship('album',page_data.host);if(jQuery('#artist_remove').length)m.loadiLikeship('artist',page_data.host.artist);}else{if(jQuery('#artist_remove').length)m.loadiLikeship('artist',page_data.host);if(jQuery('#playlist_remove').length)m.loadiLikeship('playlist',page_data.host);}},loadiLikeship:function(key,md){md=md||page_data.host;key=key||md.type;if(m.persist_active&&m.cache.persists['ilike_'+key]){m.buildiLikeBtn(key,jQuery.inArray(md.id+'',m.cache.persists['ilike_'+key])>-1,md);}else{if(theUser){jQuery.getJSON('/ilike/check',{hid:md.id,htp:key,gid:theUser.userId},function(data){m.buildiLikeBtn(key,data&&data.ilike,md);});}else{m.buildiLikeBtn(key,false,md);}}},buildTileiLikeBtn:function(btn,ilike_or_not,key){function onSubmit(ilike_or_not,params){if(m.loginRequiredFilter())return;jQuery.ajax({url:'/ilike',data:jQuery.extend({y:!ilike_or_not,user_id:theUser.userId},params),dataType:'json',type:'POST',success:function(data){btn.one('click',function(){onSubmit(!ilike_or_not,params);return false;}).attr('class',!ilike_or_not?'artist_tile_ilike_btn_quiz_clicked':'artist_tile_ilike_btn');if(m.persist_active)m.freshPersist('ilike_'+key,function(d){m.cache.persists['ilike_'+key]=data.r?(function(d){d.push(params.id);return d;})(d):jQuery.grep(d,function(v){return v!=params.id});m.carol.set('ilike_'+key,m.cache.persists['ilike_'+key].join(','));m.cache.persists['ts_l'][m.cache.persists['ts_l_alias']['ilike_'+key]]=data.t;m.carol.set('ts_l',m.cache.persists['ts_l'].join(','));});}});}
key=key||'artist';var md_id=btn.attr('rel');var params={id:md_id,type:key};btn.attr('class',ilike_or_not?'artist_tile_ilike_btn_quiz_clicked':'artist_tile_ilike_btn').one('click',function(){onSubmit(ilike_or_not,params);return false;});},buildiLikeBtn:function(key,ilike_or_not,md){var btns=ilike_or_not?['_remove','_add']:['_add','_remove'];var a=btns[0],b=btns[1];var onSuccess=function(data){jQuery.toggleEls(jQuery('#'+key+b),jQuery('#'+key+a),1);if(m.persist_active)m.freshPersist('ilike_'+key,function(d){m.cache.persists['ilike_'+key]=data.r?(function(d){d.push(md.id);return d;})(d):jQuery.grep(d,function(v){return v!=md.id+''});m.carol.set('ilike_'+key,m.cache.persists['ilike_'+key].join(','));m.cache.persists['ts_l'][m.cache.persists['ts_l_alias']['ilike_'+key]]=data.t;m.carol.set('ts_l',m.cache.persists['ts_l'].join(','));});};jQuery('#'+key+b).hide().ce(function(){return false;});jQuery('#'+key+a).ce(function(){if(m.loginRequiredFilter())return;jQuery.ajax({url:'/ilike',data:jQuery.extend({y:!ilike_or_not,user_id:theUser.userId},md),dataType:'json',type:'POST',success:onSuccess});}).show();}});function auto_playlist_go(){open_the_pop();}
function open_the_pop(){var qp=jQuery('#player_launcher_q').val();if(jQuery.trim(qp).length<1){alert('请输入歌手名称!');return false;}
var track_url='q='+(qp);url=(track_url);pop(url);}
var popupPlayer;function pop(url){if(!theUser){deep_login();return;}
popupPlayer=window.open('/player?'+url,'m_player','width=347,height=510');if(window.focus){popupPlayer.focus();}
return false;}
jQuery(function(){jQuery('.song_noborder:not(:first)','.song_list:not(.song_list_noborder)').removeClass('song_noborder').addClass('song');jQuery('#play_all').click(function(){m.cache.trackIds=m.cache.trackIds||jQuery.unique(jQuery.map(g_data.songs,function(md){return md.tag.id})).join(',');pop('t=track&ids='+m.cache.trackIds);});});