ComCore.TrackManager=Class.create();ComCore.TrackManager.prototype={initialize:function(D){if(!D){D="tracks"}if(!$(D)){return false}this.trackContainer=$(D);this.previousPreviewRow=null;this.previousInfoRow=null;var C=$(this.trackContainer).select(".toggleInfo");for(var B=0;B<C.length;B++){Event.observe(C[B],"click",this.onInfoClicked.bindAsEventListener(this))}if($("previewPlaylist")){this.previewPlaylist=$("previewPlaylist").value}var E=$(this.trackContainer).select(".info");if(E.length>0){var A=E[0].id.substr(4);this.initInfo(A)}this.initMusicPlayer();this.initPreviewButtons()},onCommentPosted:function(A){$("commentForm"+A.trackID).hide();$("commentLoading"+A.trackID).hide();if(A.success){$("commentSuccess"+A.trackID).show();$("commentCount"+A.trackID).innerHTML=parseInt($("commentCount"+A.trackID).innerHTML,10)+1;$("commentCount").innerHTML=parseInt($("commentCount").innerHTML,10)+1}else{$("commentError"+A.trackID).show()}},onPostComment:function(G,A){var E=$("commentForm"+A);var D=E.getElementsByTagName("TEXTAREA")[0];if(D.value.trim()===""){alert(E.getInputs("hidden","emptyMessageText")[0].value);D.value="";D.focus();Event.stop(G);return false}var C=ComCore.Page.buildAjaxURL("music");var B=this.onCommentPosted.bind(this);$("commentLoading"+A).show();$("commentButton"+A).disabled=true;var F=new Ajax.Request(C,{method:"post",parameters:E.serialize(true),onSuccess:function(I,H){B(H)}});Event.stop(G);return false},onRatingDone:function(A){$("ratingLoading"+A.trackID).hide();if(A.success){$("ratingSuccess"+A.trackID).show();$("ratingValue"+A.trackID).innerHTML=A.rating}else{$("ratingError"+A.trackID).show()}},onRatingClicked:function(F,A,C){var D=ComCore.Page.buildAjaxURL("music","rateTrack")+"&trackID="+A+"&rating="+C;var B=this.onRatingDone.bind(this);$("rating"+A).hide();$("ratingLoading"+A).show();var E=new Ajax.Request(D,{method:"get",onSuccess:function(H,G){B(G)}});Event.stop(F);return false},onInfoClicked:function(H){var F=Event.findElement(H,"TR");if(!F){return false}var C=F.id.substr(5);var K="info"+C;if($(K)){if($(K).visible()){$(K).hide();this.previousInfoRow=null}else{if(this.previousInfoRow){this.previousInfoRow.hide()}this.previousInfoRow=$(K);$(K).show()}}else{var B=ComCore.Page.buildAjaxURL("music","getTrackInfo")+"&trackID="+C;if(F.id.indexOf("insert")>-1){var J=F.getElementsByTagName("INPUT");var D=J[1].value;var G=J[2].value;var E=J[3].value;B=ComCore.Page.buildAjaxURL("music","getTrackInfo")+"&track="+D+"&artist="+G+"&album="+E+"&id="+F.id.substr(6)}var A=this.onInfoLoaded.bind(this);$(F).addClassName("loading");var I=new Ajax.Request(B,{method:"get",onSuccess:function(M,L){A(L.trackID,M.responseText,(L.updateID?L.updateID:null))}})}Event.stop(H);return false},onInfoLoaded:function(A,D,C){if(C){$("insert"+C).id="track"+A;$("insertCommentCount"+C).id="commentCount"+A;$("insertRatingValue"+C).id="ratingValue"+A}$("track"+A).removeClassName("loading");var B=$("track"+A).hasClassName("zebra");$("track"+A).insert({after:'<tr class="info'+(B?" zebra":"")+'" id="'+("info"+A)+'"><td colspan="6">'+D+"</td></tr>"});this.initInfo(A)},initInfo:function(A){if(this.previousInfoRow){this.previousInfoRow.hide()}this.previousInfoRow=$("info"+A);Event.observe($("toggleAlbums"+A),"click",this.onInfoChanged.bindAsEventListener(this,A,"albums"));Event.observe($("toggleListeners"+A),"click",this.onInfoChanged.bindAsEventListener(this,A,"listeners"));Event.observe($("toggleComment"+A),"click",this.onInfoChanged.bindAsEventListener(this,A,"comment"));Event.observe($("toggleVideos"+A),"click",this.onInfoChanged.bindAsEventListener(this,A,"videos"));if($("rating"+A)){var D=$("rating"+A).getElementsByTagName("a");for(var C=0;C<D.length;C++){Event.observe(D[C],"click",this.onRatingClicked.bindAsEventListener(this,A,(10-C)))}}var B=new ComCore.Editor($("comment"+A));Event.observe("commentForm"+A,"submit",this.onPostComment.bindAsEventListener(this,A));$("info"+A).show()},onVideoClicked:function(C,A,B){this.playVideo(A,B);Event.stop(C);return false},playVideo:function(B,C){var D=$$("#videos"+B+" div.videoLinks a");var E=0;for(E=0;E<D.length;E++){$(D[E])[(E+1)==C?"addClassName":"removeClassName"]("selected")}var A=B+"_"+C;var I="video"+A;var H="swf"+A;if(!$(H)){var F=6/10;var G=new FlashObject($("videoSwf").value,H,336*F,270*F,"7","#fff");G.addParam("allowScriptAccess","always");G.addParam("FlashVars",$("flashVars"+A).value);G.addParam("menu","false");G.addParam("wmode","transparent");G.write(I)}for(E=1;E<11;E++){if($("video"+B+"_"+E)){$("video"+B+"_"+E).hide();$("videoOne"+B+"_"+E).hide()}}$("video"+B+"_"+C).show();$("videoOne"+B+"_"+C).show()},onInfoChanged:function(F,A,C){Element[C=="albums"?"show":"hide"]("albums"+A);Element[C=="albums"?"addClassName":"removeClassName"]($("toggleAlbums"+A).parentNode,"selected");Element[C=="listeners"?"show":"hide"]("listeners"+A);Element[C=="listeners"?"addClassName":"removeClassName"]($("toggleListeners"+A).parentNode,"selected");Element[C=="comment"?"show":"hide"]("comment"+A);Element[C=="comment"?"addClassName":"removeClassName"]($("toggleComment"+A).parentNode,"selected");Element[C=="videos"?"show":"hide"]("videos"+A);Element[C=="videos"?"addClassName":"removeClassName"]($("toggleVideos"+A).parentNode,"selected");if(C=="videos"&&$("videosLoading"+A)){var B=ComCore.Page.buildAjaxURL("music","getVideos")+"&trackID="+A;var D=this.onInitVideo.bind(this,A);var E=new Ajax.Request(B,{method:"get",onSuccess:function(H,G){D(H.responseText)}})}Event.stop(F);return false},onInitVideo:function(A,D){$("videos"+A).innerHTML=D;var B=$$("#videos"+A+" div.videoLinks a");var E=1;if(B.length>0){for(var C=0;C<B.length;C++){if($(B[C]).parentNode.tagName!="H4"){Event.observe(B[C],"click",this.onVideoClicked.bindAsEventListener(this,A,E));E++}}this.playVideo(A,1)}},onPreviewClicked:function(B){$("musicPlayerContainer").addClassName("active");var D=Event.findElement(B,"TR");var C=D.getElementsByTagName("INPUT")[0];var A=this.getMusicPlayerObject("musicPlayer");A.preview(this.urlDecode(C.value));if(this.trackContainer.id!="recentTracks"){if(this.previousPreviewRow!==null){$(this.previousPreviewRow).removeClassName("playing")}this.previousPreviewRow=D;$(D).addClassName("playing")}Event.stop(B);return false},initMusicPlayer:function(){var B=$("swf").value;var A=new FlashObject(B,"musicPlayer",$("width").value,$("height").value,"8","#fff");A.addParam("allowScriptAccess","always");A.addParam("FlashVars","volume="+ComCore.CookieManager.getCookie("musicPlayerVolume")+(this.previewPlaylist?"&amp;playlist="+this.previewPlaylist:""));A.addParam("menu","false");A.addParam("wmode","transparent");A.addParam("PLAY","false");A.addParam("LOOP","false");A.write("musicPlayerContainer");if(this.previewPlaylist){$("musicPlayerContainer").addClassName("active")}},initPreviewButtons:function(){var A=$(this.trackContainer).select(".preview");for(var B=0;B<A.length;B++){Event.observe(A[B],"click",this.onPreviewClicked.bindAsEventListener(this))}},getMusicPlayerObject:function(A){if(navigator.appName.indexOf("Microsoft")!=-1){return window[A]}else{return document[A]}},upperCaseFirst:function(A){return A.substr(0,1).toUpperCase()+A.substr(1,A.length).toLowerCase()},urlDecode:function(E){var A="0123456789ABCDEFabcdef";var C="";var B=0;while(B<E.length){var D=E.charAt(B);if(D=="+"){C+=" ";B++}else{if(D=="%"){if(B<(E.length-2)&&A.indexOf(E.charAt(B+1))!=-1&&A.indexOf(E.charAt(B+2))!=-1){C+=unescape(E.substr(B,3));B+=3}else{alert("Bad escape combination near ..."+E.substr(B));C+="%[ERROR]";B++}}else{C+=D;B++}}}return C}};