/**
 * Main Atmosphir JS
 * Copyright Minor Studios 2010
 */

$(document).ready(function(){$(".avatar").mouseover(function(){$(this).find(".avatar-tooltip").show()}).mouseout(function(){$(this).find(".avatar-tooltip").hide()}).mousemove(function(a){mX=a.pageX;mY=a.pageY;$(this).find(".avatar-tooltip").css("left",mX+10);$(this).find(".avatar-tooltip").css("top",mY+15)});$(".levelScreenshot").mouseover(function(){$(this).find(".screenshot-tooltip").show()}).mouseout(function(){$(this).find(".screenshot-tooltip").hide()}).mousemove(function(a){mX=a.pageX;mY=a.pageY;
$(this).find(".screenshot-tooltip").css("left",mX+10);$(this).find(".screenshot-tooltip").css("top",mY+15)});$("#navigation-bar-profile-info").mouseover(function(){$(this).find("ul").show()}).mouseout(function(){$(this).find("ul").hide()});$("#overlay").click(function(){Atmosphir.hideOverlay()})});var Atmosphir;Atmosphir||(Atmosphir={});Atmosphir.showOverlay=function(){$("#overlay").fadeIn("medium");$("#overlay").css("height",$(document).height()+"px")};Atmosphir.hideOverlay=function(){$("#overlay").fadeOut("medium")};
Atmosphir.deletePrivateMessage=function(a){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"messageId="+a,url:"/atmosphir/me/mailbox/deleteMessage"})}catch(b){alert("Error: Unable to delete message")}};Atmosphir.markPrivateMessageAsRead=function(a){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"messageId="+a,url:"/atmosphir/me/mailbox/readMessage"})}catch(b){alert("Error: Unable to mark message as read")}};
Atmosphir.deleteForumPost=function(a){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"postId="+a,url:"/atmosphir/forum/delete"})}catch(b){alert("Error: Unable to delete post")}};Atmosphir.deleteLevelComment=function(a){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"commentId="+a,url:"/atmosphir/level/deleteComment"})}catch(b){alert("Error: Unable to delete comment")}};
Atmosphir.deleteProfileComment=function(a,b){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"commentId="+a,url:"/atmosphir/profile/"+b+"/deleteComment"})}catch(c){alert("Error: Unable to delete comment")}};Atmosphir.restoreForumPost=function(a){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"postId="+a,url:"/atmosphir/forum/restore"})}catch(b){alert("Error: Unable to restore post")}};
Atmosphir.lockForumThread=function(a){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"postId="+a,url:"/atmosphir/forum/lock"})}catch(b){alert("Error: Unable to lock/unlock thread")}};Atmosphir.stickForumMessage=function(a){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"postId="+a,url:"/atmosphir/forum/stick"})}catch(b){alert("Error: Unable to stick this message")}};
Atmosphir.changeSignature=function(a,b){try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"signatureText="+b,url:"/atmosphir/profile/"+a+"/signature"})}catch(c){alert("Error: Unable to change signature")}};Atmosphir.sendFeedback=function(a){if(a.length>0)try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"feedbackMsg="+a,url:"/atmosphir/feedback"})}catch(b){alert("Error: Unable to send feedback")}else alert("Please, type a valid message!")};
Atmosphir.SendTag=function(a,b){if(b.length>0){var c=b.split(",");if(c.length>0&&c.length<=20){b="";for(i=0;i<c.length;i++)if(c[i].length<2||c[i].length>32){$("#dlgTagedit .errorMsg").text('Sorry, but "'+c[i]+'" has an invalid length. Make sure that your tags have between 2 and 32 characters');$("#dlgTagedit .errorMsg").css("display","");return false}else b+=i<c.length-1?c[i]+",":c[i];try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"tagString="+b+"&levelId="+a,url:"/atmosphir/level/addTags"})}catch(d){$("#dlgTagedit .errorMsg").text("Sorry, but we were unable to add the tags that you specified");
$("#dlgTagedit .errorMsg").css("display","")}}else{$("#dlgTagedit .errorMsg").text("Sorry, but you have specified more than 20 tags");$("#dlgTagedit .errorMsg").css("display","");return false}}else{$("#dlgTagedit .errorMsg").text("Please type a valid tag");$("#dlgTagedit .errorMsg").css("display","");return false}return true};
Atmosphir.DeleteTag=function(a,b){if(confirm("Are you sure you want to delete this tag?"))try{req=$.ajax({success:function(){$("#tag-"+b).parent().fadeOut("slow");return true},processData:false,type:"POST",data:"tagId="+b+"&levelId="+a,url:"/atmosphir/level/deleteTag"})}catch(c){alert("Sorry, but we were unable to delete the tag that you specified");return false}};
Atmosphir.GetTags=function(a,b,c,d){$("#"+b).html("");req=$.ajax({success:function(e){e=eval("("+e+")");for(var f=0;f<e.length;f++){var g=$("#"+b).html();g+='<span><a href="'+c+"?queryString="+e[f].name+'&type=TAGS" style="color: white; font-weight: normal">'+e[f].name+"</a>";if(d)g+=' <a href="#deleteTag" id="tag-'+e[f].id+'" onclick="Atmosphir.DeleteTag('+a+","+e[f].id+');">X</a>';g+="</span> ";$("#"+b).html(g)}},beforeSend:function(){},processData:false,type:"POST",data:"&levelId="+a,url:"/atmosphir/level/getTags"})};
Atmosphir.SetLevelRating=function(a,b){if(a>0&&b<=5)try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"levelId="+a+"&score="+b,url:"/atmosphir/level/rateLevel"})}catch(c){alert("Error: Unable to rate level")}};Atmosphir.SendEmailVerification=function(){try{req=$.ajax({success:function(){},processData:false,type:"POST",url:"/atmosphir/me/sendVerify"})}catch(a){alert("Error: Unable to send email verification")}};
Atmosphir.SetDifficultyRating=function(a,b){if(a>0&&b<=5)try{req=$.ajax({success:function(){},processData:false,type:"POST",data:"levelId="+a+"&score="+b,url:"/atmosphir/level/rateDifficulty"})}catch(c){alert("Error: Unable to rate level")}};Atmosphir.GetUnity=function(){var a=navigator.appVersion,b=document.getElementById("UnityObject"),c=document.getElementById("UnityEmbed");return a.indexOf("MSIE")!=-1&&a.toLowerCase().indexOf("win")!=-1?b:a.toLowerCase().indexOf("safari")!=-1?b:c};
Atmosphir.DetectUnityWebPlayer=function(){var a=false,b=navigator.appVersion,c=navigator.mimeTypes,d=navigator.plugins;if(b.indexOf("MSIE")!=-1&&b.toLowerCase().indexOf("win")!=-1)a=DetectUnityWebPlayerActiveX();else if(c&&c["application/vnd.unity"])if(c["application/vnd.unity"].enabledPlugin&&d&&d["Unity Player"])a=true;return a};
Atmosphir.GetInstallerPath=function(){var a=navigator.platform,b="";navigator.userAgent.toLowerCase().indexOf("firefox");if(a=="MacIntel")b="http://webplayer.unity3d.com/download_webplayer-2.x/webplayer-i386.dmg";else if(a=="MacPPC")b="http://webplayer.unity3d.com/download_webplayer-2.x/webplayer-ppc.dmg";else if(a.toLowerCase().indexOf("win")!=-1)b="http://webplayer.unity3d.com/download_webplayer-2.x/UnityWebPlayer.exe";return b};
Atmosphir.AutomaticReload=function(){navigator.plugins.refresh();if(Atmosphir.DetectUnityWebPlayer()){Atmosphir.setBeforeUnload(false);window.location.reload()}setTimeout("Atmosphir.AutomaticReload()",500)};Atmosphir.PrintUnityObject=function(a,b,c,d){Atmosphir.createUnity3DObject(d,a,b,c,"",Math.floor(Math.random()*11),"atmounity","unity3d")};
Atmosphir.createUnity3DObject=function(a,b,c,d,e,f,g,h){b='<object id="UnityObject" classid="clsid:444785F1-DE89-4295-863A-D46C3A781394" width="1024" height="768"> \n<param name="src" value="'+d+g+e+"."+h+"?"+f+'" /> \n<param name="backgroundcolor" value="0165A1" />\n<param name="bordercolor" value="0165A1" />\n<param name="textcolor" value="FFFFFF" />\n<param name="logoimage" value="'+d+'AtmoLogo.png" /><param name="disableContextMenu" value="true" /> \n<embed id="UnityEmbed" src="'+d+g+e+"."+h+
"?"+f+'" width="'+b+'" height="'+c+'" type="application/vnd.unity" pluginspage="http://www.unity3d.com/unity-web-player-2.x" disableContextMenu="true" backgroundcolor="0165A1" bordercolor="0165A1" textcolor="FFFFFF" logoimage="'+d+'AtmoLogo.png" /> \n</object>';$("#"+a).html(b)};Atmosphir.openWindow=function(a){window.open(a)};
Atmosphir.createUnityInstallButton=function(a,b){var c="";c="";c=a!=""?"<a href= "+a+'><img src="http://webplayer.unity3d.com/installation/getunity.png" border="0" /></a>':'<a href="javascript: window.open("http://www.unity3d.com/unity-web-player-2.x"); "><img src="http://webplayer.unity3d.com/installation/getunity.png" border="0" /></a>';c='<div style="width: 100%; height: 600px; background-color: #EBEBEB; background-image: url(/atmosphir/r/i/bg-unity-install.jpg); background-repeat: no-repeat; background-position: bottom left">\t<div class="tal flr" style="width: 300px; padding-top: 50px; margin-right: 60px">\t\t<img src="/atmosphir/r/i/caption-unity-install.jpg" alt="Atmosphir runs on imagination. And Unity." />\t\t<p>\t\t\tAtmosphir requires a small, free plugin called Unity to run directly in your browser window. Please click the button below to begin your download.\t\t</p>\t\t'+
c+"\t\t<p>\t\t\tOnce you finish to install, this page will be refreshed automatically.\t\t</p>\t</div></div>";$("#"+b).html(c)};Atmosphir.unloadMess=function(){return mess="If you leave now, all unsaved changes to your levels or matches will be lost. Do you want to continue?"};Atmosphir.setBeforeUnload=function(){};Atmosphir.getURLParameter=function(a){a=a.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");a=RegExp("[\\?&]"+a+"=([^&#]*)").exec(window.location.href);return a==null?"0":a[1]};
Atmosphir.filterValue=function(a){return a=a.replace(sHashSepar,"").replace(/<\/?[^>]+(>|$)/g,"")};Atmosphir.createCookie=function(a,b,c){if(c){var d=new Date;d.setTime(d.getTime()+c*1E3);c="; expires="+d.toGMTString()}else c="";document.cookie=a+"="+b+c+"; path=/"};Atmosphir.readCookie=function(a){a=a+"=";for(var b=document.cookie.split(";"),c=0;c<b.length;c++){for(var d=b[c];d.charAt(0)==" ";)d=d.substring(1,d.length);if(d.indexOf(a)==0)return d.substring(a.length,d.length)}return null};
Atmosphir.eraseCookie=function(a){Atmosphir.createCookie(a,"",-1)};Atmosphir.shareOnFacebook=function(a){window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(a),"sharerFB","")};
Atmosphir.shareOnTwitter=function(a,b){var c="",d=b.length>60?b.substring(0,60)+"...":b+" ";$.ajax({type:"GET",url:"http://api.bit.ly/shorten",data:{version:"2.0.1",longUrl:a,apiKey:"R_2f9cb38b10369c139d13edede2083f4a",login:"swineflufollower"},dataType:"jsonp",success:function(e){eval(e);c=e.results[a].shortUrl;window.open("http://twitter.com/home?status="+encodeURIComponent("Atmosphir: "+d)+"("+encodeURIComponent(c)+")","sharerTW","")}})};