function Music(){this.init()}!function(){var e=[],s=[],t=null;Music.prototype={total:70,pageSize:10,dataUrl:"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.search.common",playerUrl:"http://box.baidu.com/widget/flash/bdspacesong.swf",init:function(){var e=this;domUtils.on($G("J_searchName"),"keyup",function(s){13==(window.event||s).keyCode&&e.dosearch()}),domUtils.on($G("J_searchBtn"),"click",function(){e.dosearch()})},callback:function(e){var s=this;s.data=e.song_list,setTimeout(function(){$G("J_resultBar").innerHTML=s._renderTemplate(e.song_list)},300)},dosearch:function(){t=null;var e=$G("J_searchName").value;if(""==utils.trim(e))return!1;e=encodeURIComponent(e),this._sent(e)},doselect:function(e){"object"==typeof e?t=e:"number"==typeof e&&(t=this.data[e])},onpageclick:function(t){for(var a=0;a<e.length;a++)$G(e[a]).className="pageoff",$G(s[a]).className="paneloff";$G("page"+t).className="pageon",$G("panel"+t).className="panelon"},listenTest:function(e){var s=$G("J_preview"),t="m-try"==e.className,a=this._getTryingElem();a&&(a.className="m-try",s.innerHTML=""),t&&(e.className="m-trying",s.innerHTML=this._buildMusicHtml(this._getUrl(!0)))},_sent:function(e){$G("J_resultBar").innerHTML='<div class="loading"></div>',utils.loadFile(document,{src:this.dataUrl+"&query="+e+"&page_size="+this.total+"&callback=music.callback&.r="+Math.random(),tag:"script",type:"text/javascript",defer:"defer"})},_removeHtml:function(e){return e.replace(/<\s*\/?\s*[^>]*\s*>/gi,"")},_getUrl:function(e){var s="from=tiebasongwidget&url=&name="+encodeURIComponent(this._removeHtml(t.title))+"&artist="+encodeURIComponent(this._removeHtml(t.author))+"&extra="+encodeURIComponent(this._removeHtml(t.album_title))+"&autoPlay="+e+"&loop=true";return this.playerUrl+"?"+s},_getTryingElem:function(){for(var e=$G("J_listPanel").getElementsByTagName("span"),s=0;s<e.length;s++)if("m-trying"==e[s].className)return e[s];return null},_buildMusicHtml:function(e){var s='<embed class="BDE_try_Music" allowfullscreen="false" pluginspage="http://www.macromedia.com/go/getflashplayer"';return s+=' src="'+e+'"',s+=' width="1" height="1" style="position:absolute;left:-2000px;"',s+=' type="application/x-shockwave-flash" wmode="transparent" play="true" loop="false"',s+=' menu="false" allowscriptaccess="never" scale="noborder">'},_byteLength:function(e){return e.replace(/[^\u0000-\u007f]/g,"aa").length},_getMaxText:function(e){return e=this._removeHtml(e),this._byteLength(e)>12?e.substring(0,5)+"...":(e||(e="&nbsp;"),e)},_rebuildData:function(e){for(var s,t=[],a=this.pageSize,n=0;n<e.length;n++)(n+a)%a==0&&(s=[],t.push(s)),s.push(e[n]);return t},_renderTemplate:function(t){var a=this;if(0==t.length)return'<div class="empty">'+lang.emptyTxt+"</div>";t=a._rebuildData(t);var n=[],i=[],l=[];n.push('<div id="J_listPanel" class="listPanel">'),i.push('<div class="page">');for(var r,c=0;r=t[c++];){s.push("panel"+c),e.push("page"+c),1==c?(n.push('<div id="panel'+c+'" class="panelon">'),1!=t.length&&l.push('<div id="page'+c+'" onclick="music.onpageclick('+c+')" class="pageon">'+c+"</div>")):(n.push('<div id="panel'+c+'" class="paneloff">'),l.push('<div id="page'+c+'" onclick="music.onpageclick('+c+')" class="pageoff">'+c+"</div>")),n.push('<div class="m-box">'),n.push('<div class="m-h"><span class="m-t">'+lang.chapter+'</span><span class="m-s">'+lang.singer+'</span><span class="m-z">'+lang.special+'</span><span class="m-try-t">'+lang.listenTest+"</span></div>");for(var o,p=0;o=r[p++];)n.push('<label for="radio-'+c+"-"+p+'" class="m-m">'),n.push('<input type="radio" id="radio-'+c+"-"+p+'" name="musicId" class="m-l" onclick="music.doselect('+(a.pageSize*(c-1)+(p-1))+')"/>'),n.push('<span class="m-t">'+a._getMaxText(o.title)+"</span>"),n.push('<span class="m-s">'+a._getMaxText(o.author)+"</span>"),n.push('<span class="m-z">'+a._getMaxText(o.album_title)+"</span>"),n.push('<span class="m-try" onclick="music.doselect('+(a.pageSize*(c-1)+(p-1))+');music.listenTest(this)"></span>'),n.push("</label>");n.push("</div>"),n.push("</div>")}return l.reverse(),i.push(l.join("")),n.push("</div>"),i.push("</div>"),n.join("")+i.join("")},exec:function(){null!=t&&($G("J_preview").innerHTML="",editor.execCommand("music",{url:this._getUrl(!1),width:400,height:95}))}}}();