function blackScreen(){$("blackscreen").tween("opacity",0,0.8);$("blackscreen").setStyle("height",window.getScrollSize().y)}function clearScreen(){$("blackscreen").tween("opacity",0.8,0)}var defaultContainer=new Element("div",{styles:{background:"#444",padding:"4px",border:"6px solid #333",position:"absolute",top:"50px",width:"640px","z-index":"2",opaity:0,overflow:"auto"}});defaultContainer.setStyle("left",Math.round((document.getSize().x-640)/2));var makeHeading=function(A,B){return'<div class="'+A+'"><div class="left"></div><div class="right"></div><div class="middle"><div>'+B+"</div></div></div>"};window.addEvent("domready",function(){$("search_query").addEvent("focus",function(){if($("search_query").value=="game search"){$("search_query").value="";$("search_query").tween("width","150")}});$("search_query").addEvent("blur",function(){if($("search_query").value==""){$("search_query").value="game search";$("search_query").tween("width","75")}})});$$(".texthead").each(function(A){file="http://play.cachefly.net/images/text/"+A.get("tag").toLowerCase()+"/"+A.innerHTML.toLowerCase().replace(" ","-")+".gif";img=new Asset.image(file,{alt:A.innerHTML.toLowerCase(),onload:function(){this.heading.innerHTML="";this.inject(this.heading,"bottom")}});img.heading=A});if(!Browser.Engine.trident){window.addEvent("domready",function(){new Tips(".tooltip")})}var ApForm=new Class({Implements:[Events,Options],options:{onComplete:$empty,onRequest:$empty,onLoad:$empty,onFormReady:$empty,formUrl:null,submitUrl:null,button:$empty,getData:$empty,errorClass:"",buttonClass:"button",errorFunction:$empty,headingFunction:$empty,formContainer:$empty,successMessage:"Thank You!",ajaxLoader:"http://play.cachefly.net/images/ajax.gif",handleRequest:true},initialize:function(A){this.setOptions(A);this.options.button.addEvent("click",(function(B){B=new Event(B).stop();this.container=this.options.formContainer.clone();this.container.setOpacity(0).inject(document.body,"bottom").tween("opacity",0,1);this.container.innerHTML='<img src="'+this.options.ajaxLoader+'" />';this.container.setStyle("top",(window.getScroll().y+50)+"px");request=new Request({url:this.options.formUrl,method:"get",data:this.options.getData});request.addEvent("onComplete",(function(E){url=$pick(this.options.submitUrl,this.options.formUrl);this.container.innerHTML='<table style="width:100%">'+E+"</table>";this.options.form=new Element("form",{method:"post","class":"form",width:"100%",action:url});this.options.form.wraps(this.container,"top").setAttribute("enctype","multipart/form-data");var C=new Element("div",{styles:{"text-align":"center"}});C.inject(this.container,"bottom");var D=new Element("input",{type:"submit","class":"button",value:"save"});D.inject(C,"bottom");C.appendText(" ");new Element("input",{type:"button","class":"button",value:"cancel"}).inject(C,"bottom").addEvent("click",(function(F){F=new Event(F).stop();this.container.destroy();this.fireEvent("onCancel")}).bindWithEvent(this));this.fireEvent("onLoad");if(this.options.handleRequest){this.initForm()}}).bindWithEvent(this));request.send();this.fireEvent("onRequest")}).bindWithEvent(this))},initForm:function(){this.options.form.addEvent("submit",(function(A){A=new Event(A).stop();this.container.tween("opacity",0.5);this.options.form.getElements(".error").each(function(B){B.dispose()});request=new Request.JSON({url:this.options.form.getAttribute("action"),method:this.options.form.getAttribute("method"),data:this.options.form});request.addEvent("onSuccess",(function(B){this.container.tween("opacity",1);stat=B.status["type"];if(stat=="failure"){if($defined(B.status["message"])){error=new Element("div",{"class":"error "+this.options.errorClass,styles:{visibility:"hidden"}});error.innerHTML=this.options.errorFunction("error "+this.options.errorClass,B.status["message"]);error.inject(this.options.form,"top");error.tween("opacity",0,1)}errors=B.errors;for(i=0;i<errors.length;i++){fieldName=errors[i]["field"];if($defined(fieldName)){field=this.options.form.getElement('[name="'+fieldName+'"]')}else{field=null}message=errors[i]["message"];error=new Element("div",{"class":"error "+this.options.errorClass,styles:{visibility:"hidden"}});error.innerHTML=this.options.errorFunction("error "+this.options.errorClass,message);if($defined(field)){error.inject(field,"after")}error.tween("opacity",0,1)}}else{if(stat=="success"){toAdd="";toAdd+=this.options.successMessage;toAdd+='<div style="text-align:center; margin-top:8ox">';toAdd+='<input type="button" value="close" class="'+this.options.buttonClass+'" />';toAdd+="</div>";this.container.innerHTML=toAdd;this.container.getElement("input[type=button]").addEvent("click",(function(C){C=new Event(C).stop();this.container.destroy();this.fireEvent("onComplete")}).bindWithEvent(this))}}}).bindWithEvent(this));request.send()}).bindWithEvent(this));this.fireEvent("onFormReady")}});var PageCycle=Class({Implements:[Events,Options],options:{listUrl:"/item/?action=list",itemUrl:"/item/{{id}}/",container:$empty,cache:5,onDisplay:$empty},initialize:function(A){this.setOptions(A);this.list=[];this.items={};this.requests={};this.index=0},loadList:function(A){request=new Request.JSON({url:this.options.listUrl,method:"get"});request.addEvent("onSuccess",(function(B){this.list=B;this.displayItem(this.list[A])}).bindWithEvent(this));request.send()},loadItem:function(A){url=this.options.itemUrl.replace(/{{id}}/,A);request=new Request({url:url,method:"get",onSuccess:function(B){this.saveTo[this.fetching]=B}});request.fetching=A;request.saveTo=this.items;this.requests[A]=request;request.send()},displayItem:function(A){this.index=this.list.indexOf(A);if($defined(this.items[A])){this.options.container.innerHTML=this.items[A];this.fireEvent("onDisplay")}else{this.loadItem(A);this.requests[A].addEvent("onSuccess",(function(B){this.options.container.innerHTML=B;this.fireEvent("onDisplay")}).bindWithEvent(this))}if(this.index!=-1){for(i=this.index+1;i<this.index+this.options.cache&&i<this.list.length;i++){if(!$defined(this.items[this.list[i]])){this.loadItem(this.list[i])}}}},next:function(){this.index++;if($defined(this.list[this.index])){this.displayItem(this.list[this.index])}else{this.index--}},previous:function(){this.index--;if($defined(this.list[this.index])){this.displayItem(this.list[this.index])}else{this.index++}},updateCache:function(){if($defined(this.options.container)){this.items[this.list[this.index]]=this.options.container.innerHTML}}});function ratingSlide(){A=$("id_rating");if(A==null){return }A.setStyle("display","none");container=A.getParent();var D=new Element("div",{id:"rating_bar"});D.inject(container,"top");var B=new Element("div",{id:"rating_slide"});B.inject(D,"top");var A=new Element("div",{}).inject(container,"top");new Element("div",{"class":"largerating",styles:{"float":"right"}}).inject(D,"top").wraps(A,"top");var C=new Slider(D,B,{onChange:function(E){this.rating.innerHTML=E/10;this.rating.setStyle("color",new Color("#80FF00").mix("#FF0",100-E));$("id_rating").value=E}});C.rating=A;if($("id_rating").value!=""){C.set($("id_rating").value)}else{C.set(50)}}if($defined($("writereview"))){new ApForm({formUrl:"/review/",button:$("writereview"),getData:{game:$$(".thegame")[0].getAttribute("id")},onRequest:function(){blackScreen()},onComplete:function(){clearScreen()},onCancel:function(){clearScreen()},onFormReady:function(){ratingSlide()},formContainer:defaultContainer,errorClass:"redbar bar",errorFunction:makeHeading,successMessage:makeHeading("greenbar bar","Thank You!")+"Your review has been added to Acid-Play."})}if($defined($("screenshot_link"))){$("screenshot_link").addEvent("click",function(A){A=new Event(A).stop();container=defaultContainer.clone();container.inject(document.body,"top").setStyle("left",Math.round((document.getSize().x-640)/2)).setStyle("top",(window.getScroll().y+50)+"px").innerHTML='<img src="http://play.cachefly.net/images/ajax.gif" />';request=new Request.HTML({url:"/screen/",method:"get",data:{action:"view",game:$$(".thegame")[0].getAttribute("id")},update:container});request.container=container;request.send();blackScreen()})}if($defined($("user_profile"))){$$(".review input[type=button]").each(function(A){A.addEvent("click",(function(){id=this.getParent().getAttribute("id").split(":")[1];new Request({url:"/review/"+id+"/",method:"post",data:{action:"vote",value:this.value}}).send();this.getParent().innerHTML="Thanks for your vote!"}).bindWithEvent(A))})}else{$$(".review input[type=button]").each(function(A){A.addClass("tooltip");A.store("tip:title","Please log in");A.store("tip:text","You need to be logged in to vote on reviews.")})}$$(".review_summary a.more").each(function(B,A){object={};object.i=A;B.addEvent("click",(function(D){D=new Event(D).stop();mainContainer=defaultContainer.clone();mainContainer.setStyle("width","500px").inject(document.body,"top").setStyle("top",(window.getScroll().y+50)+"px").setStyle("left",Math.round((document.getSize().x-500)/2));mainContainer.innerHTML+=makeHeading("bluebar bar","Community Reviews");buttonContainer=new Element("div",{styles:{height:"20px"}});closeButton=new Element("input",{type:"button",value:"close","class":"darkbutton",styles:{margin:"4px","float":"right"}}).inject(buttonContainer,"top");closeButton.addEvent("click",(function(){this.getParent().getParent().dispose();delete C;clearScreen()}).bindWithEvent(closeButton));new Element("input",{type:"button","class":"darkbutton",value:"next",styles:{"float":"left",margin:"4px"},events:{click:function(){C.next()}}}).inject(buttonContainer,"top");new Element("input",{type:"button","class":"darkbutton",value:"previous",styles:{"float":"left",margin:"4px"},events:{click:function(){C.previous()}}}).inject(buttonContainer,"top");buttonContainer.inject(mainContainer,"bottom");container=new Element("div",{styles:{"margin-top":"12px"}});container.inject(mainContainer,"bottom");mainContainer.tween("opacity",0,1);var C=new PageCycle({listUrl:"/review/?action=list&game="+$$(".thegame")[0].getAttribute("id"),itemUrl:"/review/{{id}}/",container:container,onDisplay:function(){this.options.container.getElements("input[type=button]").each(function(E){E.removeEvents("click");E.addEvent("click",(function(){id=this.getParent().getAttribute("id").split(":")[1];new Request({url:"/review/"+id+"/",method:"post",data:{action:"vote",value:this.value}}).send();this.getParent().innerHTML="Thanks for your vote!";C.updateCache()}).bindWithEvent(E))});this.options.container.setStyle("height",window.getSize().y-170);window.addEvent("resize",(function(){this.options.container.setStyle("height",window.getSize().y-170);this.options.container.setStyle("left",Math.round((window.getSize().x-500)/2))}).bindWithEvent(this))}});C.loadList(this.i);blackScreen()}).bindWithEvent({i:A}))});$$(".file a.tooltip").each(function(A){if(A.hasClass("link")){A.store("tip:title","Remote Link");A.store("tip:text","A link to another download page.")}else{if(A.hasClass("remote")){A.store("tip:title","Remote Download");A.store("tip:text","A remote download on another server.")}else{if(A.hasClass("direct")){A.store("tip:title","Direct Download");A.store("tip:text","A direct download from Acid-Play's servers.")}else{if(A.hasClass("torrent")){A.store("tip:title","Torrent Download");A.store("tip:text","A P2P download. Recommended if you know what this is.")}}}}});if($defined($("addscreen"))){new ApForm({formUrl:"/screen/",button:$("addscreen"),formContainer:defaultContainer,getData:{game:$$(".thegame")[0].getAttribute("id")},handleRequest:false,onRequest:function(){blackScreen()},onCancel:function(){clearScreen()}})}if($defined($("uploadfile"))){new ApForm({formUrl:"/file/",submitUrl:"http://games.acid-play.com.s3.amazonaws.com/",button:$("uploadfile"),formContainer:defaultContainer,getData:{action:"upload",game:$$(".thegame")[0].getAttribute("id")},handleRequest:false,onRequest:function(){blackScreen()},onCancel:function(){clearScreen()}})}if($defined($("addfile"))){new ApForm({formUrl:"/file/",button:$("addfile"),getData:{action:"add",game:$$(".thegame")[0].getAttribute("id")},onRequest:function(){blackScreen()},onComplete:function(){clearScreen()},onCancel:function(){clearScreen()},formContainer:defaultContainer,errorClass:"redbar bar",errorFunction:makeHeading,successMessage:makeHeading("greenbar bar","Thank You!")+"Your file has been added."})}$$(".delete_file").each(function(A){A.addEvent("click",(function(B){B=new Event(B).stop();answer=confirm("Are you sure you wish to delete this file? This operation can only be undone by an administrator.");if(answer){id=this.getParent().getAttribute("id");this.getParent().dispose();new Request({url:"/file/"+id+"/",data:{action:"delete"}}).send()}}).bindWithEvent(A))});if($defined($("change_profile"))){$("change_profile").setOpacity(0);$("profile_image").addEvent("mouseenter",function(){$("change_profile").tween("opacity",0.75)});$("profile_image").addEvent("mouseleave",function(){$("change_profile").tween("opacity",0)});new ApForm({formUrl:"/user/image/",button:$("change_profile"),formContainer:defaultContainer,getData:{action:"form"},handleRequest:false,onRequest:function(){blackScreen()},onCancel:function(){clearScreen()}});$$(".username").each(function(A){A.addEvent("click",function(){if(this.getElements("input").length==0){this.innerHTML='<input type="text" style="width:120px; font-size:14px" value="'+this.innerHTML+'">';input=this.getElement("input");input.store("oldValue",input.value);input.focus();input.addEvent("blur",function(){if(this.retrieve("oldValue")!=this.value){var B=confirm('Are you sure you want to change your username to "'+this.value+'"');if(B){request=new Request.JSON({url:"./",data:{action:"changename",username:this.value}});request.addEvent("onSuccess",(function(C){if(C){alert("We have changed your username");document.title="Profile: "+this.value;this.getParent().innerHTML=this.value}else{alert("That username is already taken");this.getParent().innerHTML=this.retrieve("oldValue")}}).bindWithEvent(this));request.send()}else{this.getParent().innerHTML=this.retrieve("oldValue")}}else{this.getParent().innerHTML=this.retrieve("oldValue")}})}})});document.addEvent("keydown",function(A){var A=new Event(A);if(A.key=="enter"){input=document.getElement(".username input");if($defined(input)){input.blur()}}})}document.addEvent("domready",function(){$$(".pop_info").each(function(A){A.tween("opacity",0,1);(function(){A.tween("opacity",1,0)}).delay(4000,A)})});