var comment_data=new Array();function comments_init(b){var a='	<div id="comment-box" class="center">    	<div id="comment-0">        	<div class="reply-form-container"></div>        </div>        <div id="pagination" class="comment-pagination"></div>        <div id="comment-data-container">            <div id="comment-data"></div>        </div><!-- end comment-data-container -->    </div><!-- end comment-box -->';$("#"+b).html(a);comments_get_data(0);if(globalCanComment){comment_show_reply_form(0)}}function comments_get_data(a){$.getJSON(globalCommentsURL+"?start="+a+"&t="+new Date().getTime(),function(b){if(b.has_comments){comment_data=[];$.each(b.comments,function(c,d){comment_data.push(d)});comments_update_pagination(b.page_start,b.total)}else{comments_update_pagination(0,0,0)}comments_update()})}function comments_update_pagination(c,e){var b="";var d=c-globalCommentsPerPage;b+=(c>0)?'<a onclick="comments_prev_page('+((d<0)?0:d)+');this.onclick=null;" class="link">&laquo; prev</a>':"&laquo; prev";b+=" | ";var a=c+globalCommentsPerPage;b+=(a<e)?'<a onclick="comments_next_page('+a+');this.onclick=null;" class="link">next &raquo;</a>':"next &raquo;";$("#comment-box > #pagination").html(b)}function comments_update(){if(!comment_data.length){$("#comment-data").html('<div class="no-comments">No comments.</div>');return}var b={};var a="";$.each(comment_data,function(c,d){if(d.parent_comment_id){if(!isset(b["c"+d.parent_comment_id])){b["c"+d.parent_comment_id]=""}d.replies_html="";b["c"+d.parent_comment_id]=comment_container_html(d)+b["c"+d.parent_comment_id]}});$.each(comment_data,function(c,d){if(d.parent_comment_id){return}d.replies_html=b["c"+d.comment_id]||"";a+=comment_container_html(d)});$("#comment-data").html(a)}function comment_show_reply_form(a){var b=new Object();b.comment_id=a;$("#comment-"+a+" .reply-form-container").html(comment_reply_form_html(b))}function comment_submit(b){var a=$("#comment-reply-form-"+b+" textarea").val();$.post(globalCommentsURL,{comment_text:a,parent_comment_id:b},function(c){$.each(c.comments,function(d,e){comment_data.unshift(e);comments_update()})},"json");$("#comment-"+b+" .reply-form-container").hide(1000)}function comment_delete(a){$.post(globalCommentsURL,{delete_comment_id:a});$("#comment-"+a).hide(1000)}function comments_next_page(a){comments_get_data(a)}function comments_prev_page(a){comments_get_data(a)}function comment_avatar_height_match(a){var b=$("#comment-"+a+" .avatar:first").height();if($("#comment-"+a+" .comment-text:first").height()<b-20){$("#comment-"+a+" .comment-text:first").height(b-20)}}function comments_fade_out(){$("#comment-data").attr("id","comment-data-old").fadeOut(1600,function(){$(this).remove()})}function comment_container_html(b){var a='	<div id="comment-'+b.comment_id+'" class="comment-container">			<a href="'+b.user_link+'">				<img src="/avatar/'+b.userid+'?w=50&h=80" alt="" class="avatar" onload="comment_avatar_height_match('+b.comment_id+')" />			</a>			<div class="comment-info">				<div class="posted-by">Posted by <a href="'+b.user_link+'">'+b.username+"</a> "+b.formatted_time+"</div>";if(b.can_delete){a+='<div class="delete-link">[<a onclick="comment_delete('+b.comment_id+');$(this).parent(\'div\').remove();" class="link">x</a>]</div>'}if(globalCanComment&&!b.parent_comment_id){a+='<div class="reply-link">[<a onclick="comment_show_reply_form('+b.comment_id+');$(this).parent(\'div\').remove();" class="link">reply</a>]</div>'}a+='<div style="float:right;">&nbsp;</div>';a+='				<div class="comment-text">'+b.comment_text+"</div>			</div>";if(!b.parent_comment_id){a+='				<div class="comment-replies">'+b.replies_html+'</div>				<div class="reply-form-container"></div>'}a+="</div>";return a}function comment_reply_form_html(b){var a='	<div class="comment-reply-form">			<form id="comment-reply-form-'+b.comment_id+'">				<textarea class="submitform" name="comment"></textarea>				<input class="submitform" type="button" value="Post Comment" onclick="comment_submit('+b.comment_id+');" />			</form>			<div class="clear"></div>		</div>';return a}function num_pad(b,a){var c=b.toString();while(c.length<a){c="0"+c}return c}function isset(a){var b=typeof(a);return(b!="undefined"&&b!="function")}function simfile_rate_submit(a){$.post(simfile_rate_url,{rating:a},function(b){if(b.new_rating){b.rating;b.num_ratings;$("#simfile-rating").html("<b>"+b.rating+"</b>/10 ("+((b.num_ratings==1)?"rating":"ratings")+') <span class="faded">You have rated this simfile.</span>')}},"json");$("#simfile-rate-box").hide(1000)}function init_interactive_ratebox(){hoverBoxNum=0;rateBoxWidth=$("#rateBox").width();rateBoxIncriments=rateBoxWidth/5;$("#rateBox").mousemove(function(c){var a=c.pageX-$(this).offset().left;if(a>=rateBoxIncriments*hoverBoxNum&&a<=rateBoxIncriments*(hoverBoxNum+1)){return}for(var b=0;b<5;b++){if(a>=rateBoxIncriments*b){hoverBoxNum=b}}setRateBox(hoverBoxNum+1)});$("#rateBox").one("click",function(){addRating(hoverBoxNum+1)});$("#rateBox").bind("mouseleave",function(){setRateBox(initialRating)})}function addRating(a){$.post(globalRateURL,{rating:a},function(b){if(b.newRating){initialRating=b.rating;setRateBox(initialRating);setRateStatus(b.numRatings,true);$("#rateBox").unbind()}},"json")}function setRateBox(b){var c="";var d=String(b).split(".");hoverBoxNum=parseInt(d[0])-1;for(var a=0;a<parseInt(d[0]);a++){c+='<img src="/images/rate/arrow_full.png" alt="" />'}if(isset(d[1])&&parseInt(d[1].substring(0,1))>=5){c+='<img src="/images/rate/arrow_half.png" alt="" />'}$("#rateBox").html(c)}function setRateStatus(b,a){$("#rateStatus").html(b+" "+((b==1)?"rating.":"ratings.")+((a==true)?" You have rated this video.":""))}function onYouTubePlayerReady(a){ytplayer=document.getElementById("myytplayer");seeker=true;setInterval(updateytplayerInfo,200);updateytplayerInfo();ytplayer.addEventListener("onStateChange","onytplayerStateChange");setVolume(100);loadNewVideo(ytVideoID+"&fmt=18",0);$("#ytseeker > .handle").draggable({axis:"x",containment:$("#ytseeker"),start:seekHandleDragStart,stop:seekHandleDragStop});$("#ytseeker").click(function(c){var b=c.pageX-$(this).offset().left;seekTo(Math.floor(b/seekerWidth*getDuration()))})}function seekHandleDragStart(b,a){seekHandleIsDragging=true}function seekHandleDragStop(b,a){seekHandleIsDragging=false;var c=a.position;seekTo(Math.floor(c.left/seekerWidth*getDuration()))}function onytplayerStateChange(a){updatePlaybtnState()}function updateytplayerInfo(){if(getDuration()>0){updateTimeInfo(getCurrentTime(),getDuration())}if(getBytesLoaded()>0){updateSeeker(getCurrentTime(),getDuration(),getStartBytes(),getBytesLoaded(),getBytesTotal())}}function updateSeeker(g,b,c,i,d){if(seeker){var h=getPlayerState();var a=Math.floor(g/b*seekerWidth);var f=Math.floor(c/d*seekerWidth);var e=Math.floor(((c+i)-c)/d*seekerWidth);if(e<0){e=0}if(Math.ceil(c+i)>=d||(f+e)>=(seekerWidth-1)){$("#ytseeker > .progress").css({left:f+"px",width:(seekerWidth-f)+"px"})}else{if(a>(f+e)&&h==2){$("#ytseeker > .progress").css({left:f+"px",width:(a-f+1)+"px"})}else{$("#ytseeker > .progress").css({left:f+"px",width:e+"px"})}}if(!seekHandleIsDragging){if(a>0){$("#ytseeker > .handle").css({left:a+"px"})}if(h==0){$("#ytseeker > .handle").css({left:"0px"})}}}}function updateTimeInfo(h,d){var g=Math.floor(d);var c=num_pad(Math.floor(g%60),2);var e=Math.floor((g/60)%60);var b=e+":"+c;var f=Math.floor(h);var c=num_pad(Math.floor(f%60),2);var e=Math.floor((f/60)%60);var a=e+":"+c;if(g>0){$("#timeInfo").html(a+"/"+b)}}function loadNewVideo(b,a){if(ytplayer){ytplayer.loadVideoById(b,parseInt(a))}}function play(){if(ytplayer){ytplayer.playVideo()}}function pause(){if(ytplayer){ytplayer.pauseVideo()}}function getPlayerState(){if(ytplayer){return ytplayer.getPlayerState()}}function seekTo(a){if(ytplayer){ytplayer.seekTo(a,true)}}function getBytesLoaded(){if(ytplayer){return ytplayer.getVideoBytesLoaded()}}function getBytesTotal(){if(ytplayer){return ytplayer.getVideoBytesTotal()}}function getCurrentTime(){if(ytplayer){return ytplayer.getCurrentTime()}}function getDuration(){if(ytplayer){return ytplayer.getDuration()}}function getStartBytes(){if(ytplayer){return ytplayer.getVideoStartBytes()}}function mute(){if(ytplayer){ytplayer.mute()}}function unMute(){if(ytplayer){ytplayer.unMute()}}function setVolume(a){if(ytplayer){ytplayer.setVolume(a)}}function getVolume(){if(ytplayer){return ytplayer.getVolume()}}function clearVideo(){if(ytplayer){ytplayer.clearVideo()}}function playbtn_click(){if(getPlayerState()==1){pause()}else{play()}updatePlaybtnState()}function updatePlaybtnState(){$("#ytplaybtn").removeClass();if(getPlayerState()==1){$("#ytplaybtn").addClass("pausestate")}else{$("#ytplaybtn").addClass("playstate")}};