var Site=new Class({exf:null,old_size:null,cf_arr:null,snap_score:null,snap_votes:null,snap_id:null,score_tim:null,msg_box:null,initialize:function(){this.old_size=[];this.cf_arr=[];this.msg_box=new MessageBox()},send_feedback:function(){var B=$("user_feedback").value;if(B==""){site.msg_box.show("Please type your opinion.",false,null);return }site.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/send-feedback/",onSuccess:function(C,D){if(C.errno!=0){this.msg_box.show(C.error,false,null)}else{this.msg_box.show(C.out,false,null)}}.bind(this)}).send("msg="+B)},add_snap:function(){var G=$("title").value;var A=$("cat").value;var F=$("desc").value;var E=$("usage").value;var B=$("tags").value;var D=code.getCode();if(G==""||A==0||F==""||E==""||B==""||code==""){site.msg_box.show("Please fill all fields",false,null);return }site.msg_box.show(null,true,null);var C=new Request.JSON({url:"/async/add-snap/",onSuccess:function(H,I){if(H.errno!=0){this.msg_box.show(H.error,false,null)}else{this.msg_box.show(H.out,false,null)}}.bind(this)}).send("title="+this.encode_post_string(G)+"&cat="+A+"&desc="+this.encode_post_string(F)+"&usage="+this.encode_post_string(E)+"&tags="+this.encode_post_string(B)+"&code="+this.encode_post_string(D))},update_snap:function(H){if(H==0){this.msg_box.show("Unknown snap, operation cancelled",false,null);return }var G=$("title").value;var A=$("cat").value;var F=$("desc").value;var E=$("usage").value;var B=$("tags").value;var D=code.getCode();if(G==""||A==0||F==""||E==""||B==""||code==""){site.msg_box.show("Please fill all fields",false,null);return }site.msg_box.show(null,true,null);var C=new Request.JSON({url:"/async/update-snap/",onSuccess:function(I,J){if(I.errno!=0){this.msg_box.show(I.error,false,null)}else{this.msg_box.show(I.out,false,null)}}.bind(this)}).send("id="+H+"&title="+this.encode_post_string(G)+"&cat="+A+"&desc="+this.encode_post_string(F)+"&usage="+this.encode_post_string(E)+"&tags="+this.encode_post_string(B)+"&code="+this.encode_post_string(D))},get_site_ip:function(){var C=$("domain").value;var A=$("hip");if(C==""){this.msg_box.show("Enter your site's domain name so we can retrieve server's IP!",false,null);return }site.msg_box.show(null,true,null);var B=new Request.JSON({url:"/async/get-site-ip/",onSuccess:function(D,E){if(D.errno!=0){this.msg_box.show(D.error,false,null)}else{this.msg_box.hide(true);$("ip").value=D.out}}.bind(this)}).send("domain="+this.encode_post_string(C))},uc_ap_disap_comment:function(D,B,C){this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/ap-disap-comment/",onSuccess:function(E,F){if(E.errno!=0){this.msg_box.show(E.error,false,null)}else{this.msg_box.show(E.out,false,'<a href="">Close and refresh this page</a>')}}.bind(this)}).send("id="+D+"&act="+B)},uc_remove_comment:function(B){if(!confirm("Deleting a comment will permanently delete it from the system.\nAre you sure you want to delete this comment?")){return }this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/delete-comment/",onSuccess:function(C,D){if(C.errno!=0){this.msg_box.show(C.error,false,null)}else{$("uc_"+B).setStyle("display","none");this.msg_box.show(C.out,false,null)}}.bind(this)}).send("id="+B)},uc_show_more:function(C,B){var A=$("ucsm_"+C);if(A.style.display=="none"){A.style.display="inline";B.innerHTML="Less";B.blur()}else{A.style.display="none";B.innerHTML="More";B.blur()}},go_fullscreen:function(){this.exf=$("exf");this.old_size=[code.style.width.toInt(),code.style.height.toInt()];var A=window.getSize();code.style.position="absolute";code.style.top="40px";code.style.left="0";code.style.width=(A.x-2)+"px";code.style.height=(A.y-40)+"px";window.scrollTo(0,0);this.exf.setStyle("display","block")},exit_fullscreen:function(){code.style.position="static";code.style.width=this.old_size[0]+"px";code.style.height=this.old_size[1]+"px";window.scrollTo(0,0);this.exf.setStyle("display","none")},get_class_file:function(){if(this.cf_arr.length!=0){window.location="/async/get-class-file/"}},add_to_class:function(C){var B=C+"|"+$("t_"+C).get("html");if(this.is_in_array(B,this.cf_arr)!=-1){this.msg_box.show("This snap is already included in your custom class file.",false,null);return }this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/add-to-class-list/",onSuccess:function(D,E){if(D.errno!=0){this.msg_box.show(D.error,false,null)}else{this.msg_box.show(D.out,false,null);this.cf_arr.push(B);this.rebuild_sscf_data()}}.bind(this)}).send("func="+this.encode_post_string(B))},clear_class_list:function(){this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/clear-class-list/",onSuccess:function(B,C){if(B.errno!=0){this.msg_box.show(B.error,false,null)}else{this.msg_box.show(B.out,false,null);this.cf_arr=[];$("ssfc").set("html","<i>None selected yet.</i>");$("ssfc_btns").setStyle("display","none")}}.bind(this)}).send(null)},rebuild_sscf_data:function(){if(this.cf_arr.length!=0){var C='<ul style="margin-top: 10px">';for(var B=0;B<this.cf_arr.length;B++){var A=this.cf_arr[B].split("|");C+="<li><b>"+A[1]+"</b></li>"}C+="</ul>";$("ssfc").set("html",C);$("ssfc_btns").setStyle("display","block")}},download_snap:function(A){window.location="/async/download-snap/"+A+"/"},set_rating_value:function(){var B=parseInt(this.snap_score);for(var A=0;A<B;A++){$("s"+(A+1)).setStyle("background","url(/images/rating-stars.gif) #fff 0 0  no-repeat")}$("sc").set("html",this.snap_score);$("sv").set("html",this.snap_votes)},rate_astar:function(A){for(var B=0;B<5;B++){$("s"+(B+1)).setStyle("background","url(/images/rating-stars.gif) #fff -31px 0  no-repeat")}for(var B=0;B<A;B++){$("s"+(B+1)).setStyle("background","url(/images/rating-stars.gif) #fff -62px 0  no-repeat")}if(this.score_tim!=null){clearTimeout(this.score_tim);this.score_tim=null}},rate_istar:function(A){for(var B=0;B<A;B++){$("s"+(B+1)).setStyle("background","url(/images/rating-stars.gif) #fff -31px 0  no-repeat")}this.score_tim=setTimeout(function(){this.set_rating_value()}.bind(this),500)},rate:function(B){if(this.snap_id<=0){return }this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/do-rating/",onSuccess:function(C,D){if(C.errno!=0){this.msg_box.show(C.error,false,null)}else{this.msg_box.show(C.out,false,null)}}.bind(this)}).send("id="+this.snap_id+"&val="+B)},add_comment:function(C){var B=$("comment");if(B.value==""){this.msg_box.show("Nothing to save...",false,null);return }this.msg_box.show(null,true,null);var A=new Request.JSON({url:"/async/add-comment/",onSuccess:function(E,F){if(E.errno!=0){this.msg_box.show(E.error,false,null)}else{this.msg_box.hide(true);var D=$("currc");var G="<div><span>Posted 1 second by <b>me</b></span><p>"+B.value.replace(/\n/g,"<br />")+"</p></div>";if(E.out==0){D.set("html",G+'<p style="text-align: center;color: #ab0179;font-weight: bold;font-style: italic;">This comment has been queued for approval</p>')}else{D.set("html",G+D.get("html"))}B.value=""}}.bind(this)}).send("id="+C+"&comm="+this.encode_post_string(B.value))},is_in_array:function(D,B){var A=B.length;for(var C=0;C<B.length;C++){if(B[C]===D){return C}}return -1},encode_post_string:function(A){return(A=="")?"":encodeURIComponent(A)},html_entity_decode:function(B){var A=new Element("textarea",{html:B});B=A.value;A.dispose();return B}});var MessageBox=new Class({el:null,el_dat:null,el_img:null,el_links:null,visible:null,fade_fx:null,initialize:function(){this.el=$("msg_box");this.el_msg=$("mb_msg");this.el_img=$("mb_img");this.el_links=$("mb_links");this.visible=false;this.fade_fx=new Fx.Tween(this.el,{property:"opacity",duration:500})},set_content:function(A){if(A==null){this.el_msg.set("html","Please wait, processing your request...")}else{if(A!="NOCONTENT"){this.el_msg.set("html",A)}}},attach_content:function(A){this.el_msg.grab(A)},show:function(D,B,C,A){this.set_content(D);if(B){this.el_img.setStyle("display","inline")}else{this.el_img.setStyle("display","none")}if(C==null){this.el_links.set("html",'<a href="#mb-close" onclick="site.msg_box.hide();">Close</a>')}else{this.el_links.set("html",C)}if(typeof (A)=="undefined"){this.set_position()}if(!this.visible){this.el.setStyle("display","block");this.visible=true}},hide:function(A){this.fade_fx.start(1,0).chain(function(){if(this.visible){this.el.setStyle("display","none");this.visible=false}this.fade_fx.set(1);if(A){this.el_msg.set("html","")}}.bind(this))},set_position:function(){this.el.position({position:"center"})}});var site=null;window.addEvent("domready",function(){site=new Site();_load()});