var loadFb=true;var localPlayerFirstname="";var permissions={};var fbLikes=null;var accessToken;var accessTokenExpires;var uid;var himHer="them";function getFB(){try{if(typeof FB==="undefined"){return parent.FB}else{return FB}}catch(a){return null}}function getFBDisplay(){if(isDesktop){return"iframe"}else{return"iframe"}}function myUi(b,c){if(isDesktop){getFB().ui(b,c)}else{var a=getGraphUrl(b);openChildBrowser(a,true)}}function getGraphUrl(b){var d="http://www.facebook.com/dialog/"+b.method+"?app_id="+appId+"&";for(var a in b){if(a!="method"){d+=a+"="+b[a]+"&"}}var c=window.location.protocol+"//"+window.location.hostname+"/"+ctx+"/games/JoyplayCasino/fbRedirect.jsp";d+="redirect_uri="+document.location;return d}function loadFBScript(d,c){try{if(getFB()!=null){loadFb=false}}catch(a){}if(loadFb){var b;if(document.location.protocol=="file:"){b="http://connect.facebook.net/en_US/all.js"}else{b=document.location.protocol+"//connect.facebook.net/en_US/all.js"}loadFb=false;$("body").prepend("
");debug("loading FB script "+b);dynamicallyLoadJSFile(b,function(){debug("FB file is loaded")})}else{debug("FB script is already loaded")}window.fbAsyncInit=function(){debug("window.fbAsyncInit called");if(FB!=null){var e=document.location.protocol+"//"+document.location.host+ctx+"/channel.jsp";FB.init({appId:d,status:true,cookie:true,xfbml:true,channelUrl:e})}debug("callback in window.fbAsyncInit is "+c);if(c!=null){c()}}}function JadeFB(){this.promptLogin=function(b,d){if(isDesktop){FB.login(d,{scope:b})}else{var c=document.location;var a="https://www.facebook.com/dialog/oauth?display=touch&client_id="+appId+"&scope="+b+"&redirect_uri="+c;openChildBrowser(a)}};this.getPermissions=function(a){if(permissions!=null&&permissions.length>0){return a(permissions)}else{getFB().api({method:"fql.query",query:"SELECT read_stream,offline_access,publish_stream,email,publish_actions FROM permissions WHERE uid=me()"},function(b){permissions=b[0];a(permissions)})}};this.resizeFrame=function(a,c){if(a!=null&&c!=null){var b=new Object;b.width=a;b.height=c;getFB().Canvas.setSize(b)}else{getFB().Canvas.setSize()}};this.getLoginStatus=function(b){debug("getLoginStatus called");try{getFB().getLoginStatus(function(c){if(c.status==="connected"){uid=c.authResponse.userID;accessToken=c.authResponse.accessToken;accessTokenExpires=c.authResponse.expiresIn;debug("getLoginStatus logged in");b(true)}else{if(c.status==="not_authorized"){b(false);debug("getLoginStatus not logged in as not_authorized")}else{b(false);debug("getLoginStatus not logged in")}}})}catch(a){debug("ERROR# "+a)}};this.inviteFriends=function(e,d,c){var b={method:"apprequests",display:getFBDisplay(),message:"You can invite up to 5 friends a day",data:""};if(d!=null){b.message=d}if(c!=null){b.data=c}var a=function(f){if(e!=null){if(f&&f.request_ids){e(f.request_ids.length)}else{e(0)}}};myUi(b,a)};this.getFriends=function(a){getFB().api("/me/friends",function(b){if(!b||b.error){log("Error occured "+b.error.type+": "+b.error.message)}else{a(b.data)}})};this.getFriendsAppUser=function(a){getFB().api({method:"fql.query",query:"SELECT uid,name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1"},function(b){a(b)})};this.getFriends2=function(a){getFB().api({method:"fql.query",query:"SELECT uid,first_name,name,sex,pic_big,is_app_user FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY is_app_user"},function(b){a(b)})};this.review=function(){var a="http://www.facebook.com/apps/application.php?id="+appId+"&sk=app_6261817190";window.open(a)};this.autoPostToFeed=function(a,c,b){if(permissions.publish_stream=="1"){getFB().api("/me/feed","post",a,function(d){if(!d||d.error){if(d.error.type="OAuthException"){log("OAuthException so prompting.");JadeFB.postToFeed(a,c)}else{error("Unknown Facebook Error occured "+d.error.type+": "+d.error.message)}}else{log("Post ID: "+d);if(c){c(true)}}})}else{this.postToFeed(a,c)}};this.postToFeed=function(a,b){a.method="feed";a.display=getFBDisplay();getFB().ui(a,function(c){if(c&&c.post_id){if(b){b(true)}}else{if(b){b(false)}}})};this.setStatus=function(a){var b={media:[{type:"status",message:a}]};getFB().api(b,function(c){if(c==0){log("status not updated. Give Status Update Permission")}else{log("status updated")}})};this.sendToMany=function(a){getFB().ui({method:"apprequests",display:getFBDisplay(),message:a,data:""})};this.sendRequest=function(a,b){getFB().ui({method:"apprequests",display:getFBDisplay(),to:a,message:b,data:"tracking information for the user"})};this.postToUsersWall=function(c,a,b){b.to=a;b.method="stream.publish";b.display=getFBDisplay();getFB().ui(b,function(d){if(!d||d.error){if(c){c(false)}}else{if(c){c(true)}}})};this.postScore=function(a){};this.autoPostToUsersWall=function(d,a,b){var c="/"+a+"/feed/";if(permissions.publish_stream=="1"){getFB().api(c,"post",b,function(e){if(!e||e.error){if(e.error.type="OAuthException"){log("We do not have permission to auto post to the users feed");JadeFB.postToUsersWall(a,b)}else{log("Error occured "+e.error.type+": "+e.error.message);showWarning("An error occured, not posted")}}else{log("Post ID: "+e);showWarning("post successful",400);if(d){d(true)}}})}else{JadeFB.postToUsersWall(d,a,b)}};this.getLocalUsersFirstName=function(a){debug("Calling JadeFB.getLocalUsersFirstName");getFB().api({method:"fql.query",query:"select first_name,sex from user where uid=me()"},function(b){a(b)})};this.doFBLoginPanel=function(){FB.login(function(a){if(a){location.reload(true)}else{alert("You need to accept the app to play the game")}})};this.showFBLoginPanel=function(b){var a=$('
Log in now to play

Connect with Facebook
")');$("body").append(a);$("#myFbLogin").bind(tapEventName,function(){var c="";JadeFB.promptLogin(c,b)})};this.placeOrder=function(a,c){var b={method:"pay",order_info:a,purchase_type:"item",display:getFBDisplay()};getFB().ui(b,c)};this.writeback=function(a){alert("writeback "+a)};this.logout=function(){getFB().logout(function(){top.location.href="/action?method=logout"})};this.likes=function(d,e){if(fbLikes!=null){if(e){e(fbLikes)}return fbLikes}else{getFB().api("/me/likes",function(f){if(f.data!=null){for(var g=0;g