var ajax;var prettyPhotoLoaded;$(document).ready(function(){$("#tabs").tabs();$("#friendKeyword").val("");$(".tipsy").tipsy({gravity:$.fn.tipsy.autoNS,live:true,opacity:1,gravity:"n"});$(".scroll-animation").cycle({fx:"scrollHorz",cleartype:!$.support.opacity,cleartypeNoBg:false,speed:"fast",timeout:5000,pause:true,pauseOnPagerHover:true,});$("#getSimilarGames").click(function(){var obj=$(this);$(obj).html("<span>Please Wait</span>");$(obj).parent().parent().children(".loader").show();$.post("/action.php?do=get_similar_games&gameid="+$(this).attr("rel"),function(data){var data_arr=data.split("||");switch(data_arr[0]){case"1":$("#similar_games").html(data_arr[1]);break;case"0":alert(data_arr[1]);break;default:alert(data);break}$(obj).html("<span>Show More<em>Similar Games</em></span>");$(obj).parent().parent().children(".loader").hide();return false});return false});$(".share-btn").click(function(){$("#shareto").slideToggle("slow");return false});$(".embed-btn").click(function(){$("#embed").slideToggle("slow");return false});$("#contactForm").validate({rules:{sender_name:{required:true},sender_email:{required:true,email:true},mail_comments:{required:true}},messages:{sender_name:{required:"Enter your name."},sender_email:{required:"Enter e-mail.",email:"Invalid e-mail format."},mail_comments:{required:"Enter your message."}},submitHandler:function(){$("#contactForm").ajaxSubmit({url:$("#contactForm").attr("action"),type:$("#contactForm").attr("method"),timeout:20000,beforeSubmit:function(){$("#contactForm .submitBtn").hide();$("#contactForm .loader").show();$("#contactForm .textbox").attr("disabled",true)},error:function(xhr,desc,e){var msg=(desc=="timeout")?"Connection 20 sec Time Out, Please try again Later.":desc;alert("Failed to login: "+msg)},success:function(msg){msg=jQuery.trim(msg);var msg_arr=msg.split("||");switch(msg_arr[0]){case"1":$("#contactForm .successMsg").html(msg_arr[1]);$("#contactForm").clearForm();$("#contactForm .textbox").attr("disabled",false);$("#contactForm .successMsg").fadeIn(300);break;case"0":$("#contactForm .errorMsg").html(msg_arr[1]);$("#contactForm .textbox").attr("disabled",false);$("#contactForm #newusername").select();$("#contactForm .errorMsg").fadeIn().delay(300).fadeOut(4000);break;default:alert(msg);break}},complete:function(){$("#contactForm .submitBtn").show();$("#contactForm .loader").hide()}})}});$("a[alt]").overlay({mask:"#000",effect:"apple",onBeforeLoad:function(){$(".swfFile").css({"margin-left":"2000px"})},onLoad:function(){$(".swfFile").css({"margin-left":"2000px"})},onClose:function(){$(".swfFile").css({"margin-left":"0"})}});$("a[rel^='prettyPhoto']").prettyPhoto();$("#birthday").datepicker({changeMonth:true,changeYear:true,yearRange:"-100:-13",dateFormat:"yy-mm-dd",maxDate:"-13y",onSelect:function(dateText,inst){}});$(".tab-cat .menu li a.tab-link").click(function(){var href=$(this).attr("href").replace("#","");$(".tab-cat .menu li a").removeClass("active");$(this).addClass("active");$(".tab-cat .content ul").hide();$("#"+href).show();return false});$("#clearFriendSearch").click(function(){$("#friendKeyword").val("");$("#friendKeyword").select();$("#friendResult").html("&nbsp;");$(this).hide();return false});$("#friendKeyword").keyup(function(){var obj=$(this);$("#friendKeyword").next().hide();$("#friendKeyword").next().next().hide();if(ajax){ajax.abort()}delay(function(){var keyword=$("#friendKeyword").val();if(keyword.length>0){$("#friendKeyword").next().show();ajax=$.ajax({type:"POST",url:"/index.php?action=ajaxFriendSearch&keyword="+keyword,success:function(msg){var msg_arr=msg.split("||");switch(msg_arr[0]){case"2":$("#friendResult").html(msg_arr[1]);$("#friendKeyword").next().hide();$("#friendKeyword").next().next().show();break;case"1":$("#friendResult").html(msg_arr[1]);$("#friendKeyword").next().hide();$("#friendKeyword").next().next().show();break;case"0":$("#friendKeyword").next().hide();$("#friendKeyword").next().next().hide();alert(msg_arr[1]);break;default:$("#friendKeyword").next().hide();$("#friendKeyword").next().next().hide();alert(msg)}},error:function(msg){alert(msg)}})}},1000)});$("#overlay_loginForm").clearForm();$("#overlay_signupForm").clearForm();$(".addFavGame").click(function(){var link="/index.php?action=addFavGame&gameid="+$(this).attr("alt");$.ajax({type:"POST",url:link,success:function(msg){var msg_arr=msg.split("||");switch(msg_arr[0]){case"1":break;case"0":alert(msg_arr[1]);break;default:alert(msg)}},error:function(msg){alert(msg)}});return false});$("a[rel]").overlay({mask:"#000",effect:"apple",onBeforeLoad:function(){$(".swfFile").css({"margin-left":"2000px"})},onLoad:function(){$(".swfFile").css({"margin-left":"2000px"})},onClose:function(){$(".swfFile").css({"margin-left":"0"})}});$(".eachComment .likeBtn").live("click",function(){liking($(this),"like")});$(".eachComment .dislikeBtn").live("click",function(){liking($(this),"dislike")});$(".eachComment .textbox").live("focusin",function(){$(this).css({width:"337px",height:"42px"});$(this).prev().show();$(this).next().show();if($(this).val()!="write a comment"&&$(this).val()){$(this).css({color:"black"});$(this).val("")}else{$(this).css({color:"#777777"});$(this).val("write a comment...")}});$(".eachComment .textbox").live("focusout",function(){if($(this).val()!="write a comment"&&$(this).val()){}else{$(this).css({width:"379px",height:"17px"});$(this).prev().hide();$(this).next().hide();$(this).css({color:"#777777"});$(this).val("write a comment...")}});$(".eachComment .commentBtn").live("click",function(){var replyObj=$(this).parent().parent().parent().parent().prev();var obj=$(this).parent().parent().prev();var id=$(obj).attr("rel");var val=$(obj).val();var url="/index.php?action=replycomment&parent="+id+"&reply="+val+"&gameid="+$("#gameid").val();$.ajax({type:"POST",url:url,success:function(msg){var msg_arr=msg.split("||");switch(msg_arr[0]){case"1":$(replyObj).children(".eachReply:last").after(msg_arr[1]);$(obj).css({width:"385px",height:"22px"});$(obj).prev().hide();$(obj).next().hide();$(obj).css({color:"#777777"});$(obj).val("write a comment...");break;case"0":alert(msg_arr[1]);break;default:alert(msg)}},error:function(msg){alert(msg)}})});$("#commentForm #submitBtn").click(function(){$("#commentForm").ajaxSubmit({url:$("#commentForm").attr("action"),type:"POST",timeout:20000,beforeSubmit:function(){$("#commentForm #submitBtn").hide()},error:function(xhr,desc,e){var msg=(desc=="timeout")?"Connection 20 sec Time Out, Please try again Later.":desc;alert("Failed to comment: "+msg)},success:function(msg){var msg_arr=msg.split("||");if(msg_arr[0].indexOf("1||")){$("#allComments .eachComment:first").before(msg_arr[1]);$(".commentnotfound").remove()}else{if(msg_arr[0].indexOf("0||")){}else{alert(msg)}}},complete:function(){$("#commentForm #submitBtn").show();$("#commentForm").clearForm()}})});$("#mailform").validate({rules:{sender_name:{required:true,maxlength:100},sender_email:{required:true,email:true},mail_comments:{required:true}},messages:{sender_name:{required:"Please fill in your name.",maxlength:"Your name seems to be too long."},sender_email:{required:"Please fill in your email address.",email:"This is not a correct email address format."},mail_comments:{required:"Please type your mssage."}},submitHandler:function(){$("#mailform").ajaxSubmit({url:$("#mailform").attr("action"),type:"POST",timeout:20000,beforeSubmit:function(){$("#mailform #submitBtn").hide();$("#mailform #loader").show()},error:function(xhr,desc,e){var msg=(desc=="timeout")?"Connection 20 sec Time Out, Please try again Later.":desc;alert("Failed to save: "+msg)},success:function(msg){var msg_arr=msg.split("||");if(msg_arr[0].indexOf("1||")){$("#mailSent").text(msg_arr[1]);$("#mailSent").fadeIn().delay(300).fadeOut(4000)}else{if(msg_arr[0].indexOf("0||")){$("#mailNotSent").text(msg_arr[1]);$("#mailNotSent").fadeIn().delay(300).fadeOut(4000)}else{alert(msg)}}},complete:function(){$("#mailform #submitBtn").show();$("#mailform #loader").hide();$("#mailform").clearForm()}})}});$("#overlay_loginForm").validate({rules:{overlay_username:{required:true},overlay_password:{required:true}},messages:{overlay_username:{required:"Enter username."},loginpassword:{required:"Enter password."}},submitHandler:function(){$("#overlay_loginForm").ajaxSubmit({url:$("#overlay_loginForm").attr("action"),type:"POST",timeout:20000,beforeSubmit:function(){$("#overlay_loginForm .ajaxSubmit").hide();$("#overlay_loginForm .loader").show()},error:function(xhr,desc,e){var msg=(desc=="timeout")?"Connection 20 sec Time Out, Please try again Later.":desc;alert("Failed to login: "+msg)},success:function(msg){var msg_arr=msg.split("||");switch(msg_arr[0]){case"1":$("#overlay_loginForm .suc").html(msg_arr[1]);$("#overlay_loginForm .suc").fadeIn(300,function(){$(location).attr("href",msg_arr[2])});break;case"0":$("#overlay_loginForm .err").html(msg_arr[1]);$("#overlay_loginForm .err").fadeIn().delay(300).fadeOut(4000);break;default:alert(msg)}},complete:function(){$("#overlay_loginForm .ajaxSubmit").show();$("#overlay_loginForm .loader").hide();$("#overlay_loginForm").clearForm()}})}});$("#overlay_signupForm").validate({rules:{reg_username:{required:true},reg_password:{required:true},reg_cpassword:{required:true,equalTo:"#reg_password"},reg_email:{required:true,email:true}},messages:{reg_username:{required:"Required"},reg_password:{required:"Required"},reg_cpassword:{required:"Required",equalTo:"Please enter the same password"},reg_email:{required:"Required",email:"Wrong format"}},submitHandler:function(){$("#overlay_signupForm").ajaxSubmit({url:$("#overlay_signupForm").attr("action"),type:$("#overlay_signupForm").attr("method"),timeout:600000,beforeSubmit:function(){$("#overlay_signupForm .ajaxSubmit").hide();$("#overlay_signupForm .loader").show()},error:function(xhr,desc,e){var msg=(desc=="timeout")?"Connection Time Out, Please try again Later.":desc;alert("Failed to signup: "+msg)},success:function(msg){msg=msg.replace("<head></head><body>","");msg=msg.replace("</body>","");var msg_arr=msg.split("||");switch(msg_arr[0]){case"1":$("#overlay_signupForm .suc").html(msg_arr[1]);$("#overlay_signupForm").clearForm();$("#overlay_signupForm .suc").fadeIn().delay(300).fadeOut(4000,function(){$(".close").click()});$("#overlay_signupForm").clearForm();break;case"0":$("#overlay_signupForm .err").html(msg_arr[1]);$("#overlay_signupForm .err").fadeIn().delay(300).fadeOut(4000);break;default:alert(msg)}},complete:function(){$("#overlay_signupForm .ajaxSubmit").show();$("#overlay_signupForm .loader").hide()}})}});$("#editProfileForm").validate({rules:{email:{required:true}},messages:{email:{required:"Required"}},submitHandler:function(){$("#editProfileForm").ajaxSubmit({url:$("#editProfileForm").attr("action"),type:$("#editProfileForm").attr("method"),timeout:600000,beforeSubmit:function(){$("#editProfileForm #save").hide();$("#editProfileForm .loader").show()},error:function(xhr,desc,e){var msg=(desc=="timeout")?"Connection Time Out, Please try again Later.":desc;alert("Failed to signup: "+msg)},success:function(msg){msg=msg.replace("<head></head><body>","");msg=msg.replace("</body>","");var msg_arr=msg.split("||");switch(msg_arr[0]){case"1":$("#editProfileForm").clearForm();$("#editProfileForm .suc").html(msg_arr[1]);$("#editProfileForm .suc").fadeIn(300).delay(2000,function(){$(location).attr("href",msg_arr[2])});break;case"0":$("#editProfileForm .err").html(msg_arr[1]);$("#editProfileForm .err").fadeIn().delay(300).fadeOut(4000);break;default:alert(msg)}},complete:function(){$("#editProfileForm #save").show();$("#editProfileForm .loader").hide()}})}})});liking=function(obj,liking){var id=$(obj).attr("rel");if(liking=="like"){var what="like"}else{var what="dislike"}$.ajax({type:"POST",url:"/index.php?action=liking&what="+what+"&commentid="+id+"&gameid="+$("#gameid").val(),success:function(msg){var msg_arr=msg.split("||");switch(msg_arr[0]){case"1":if(liking=="like"){var likeCurrNumStr=$(obj).children(".like").children(".num").html();likeCurrNumStr=likeCurrNumStr.replace("(","");likeCurrNumStr=likeCurrNumStr.replace(")","");likeCurrNumStr++;$(obj).children(".like").children(".num").html(" ("+likeCurrNumStr+")")}else{var dislikeCurrNumStr=$(obj).children(".dislike").children(".num").html();dislikeCurrNumStr=dislikeCurrNumStr.replace("(","");dislikeCurrNumStr=dislikeCurrNumStr.replace(")","");dislikeCurrNumStr++;$(obj).children(".dislike").children(".num").html(" ("+dislikeCurrNumStr+")")}break;case"0":alert(msg_arr[1]);break;default:alert(msg)}},error:function(msg){alert(msg)}})};var delay=(function(){var timer=0;return function(callback,ms){clearTimeout(timer);timer=setTimeout(callback,ms)}})();jq_rate=function(gameid,myrating){$.post("/action.php?do=rate_game&gameid="+gameid+"&myrating="+myrating,function(data){var data_arr=data.split("||");switch(data_arr[0]){case"1":$("#votenow").html(data_arr[1]);break;case"0":alert(data_arr[1]);break;default:alert(data);break}$(obj).html("<span>Show More<em>Similar Games</em></span>");$(obj).parent().parent().children(".loader").hide();return false})};
