var FLY={dom:{'balance':$('#balance'),'current_coins':$('#current-coins')},isDebug:false,setWindowTitle:function(title){if(!title){title="Friend.ly";}else{title="Friend.ly - "+title;}
document.title=title;},updateTimeOffset:function(){try{if(FLY_CONTEXT.fbUserID!="0"){var minutes=-(new Date()).getTimezoneOffset();if(minutes!=FLY_CONTEXT.timeOffset){new AsyncNotification('/ajax/autoTimeZoneUpdate.php',{'minutes':minutes}).send();FLY.debug("Updated timeOffset to "+minutes+" from "+FLY_CONTEXT.timeOffset);FLY_CONTEXT.timeOffset=minutes;}}}catch(e){}},debug:function(){return false;},setCoins:function(count){if(count||count===0){this.dom['current_coins'].text(number_format(count,0));}
this.dom['balance'].show();},reattemptLogin:function(){try{FB.login(function(){setTimeout(function(){window.location.reload(true);},200);});}catch(e){window.location="/logout";}},handleUserLoggedOutExternally:function(){if(this.once!==undefined){return;}
this.once=true;if($.fancybox){var dialog=$(''+'<div class="fancybox">'+'<div class="popup" style="width:350px;text-align:left;">'+'<h3 class="left">Please log in to continue.</h3>&nbsp;'+'<div id="control" class="clearfix">'+'<button class="xs-white right" onclick="$.fancybox.close();"><span>Cancel</span></button>'+'<button class="xs-blue right" style="margin-right:7px;" onclick="try{FLY.reattemptLogin();}catch(e){window.location=\'/logout\';}"><span>Login</span></button>'+'</div>'+'</div>'+'</div>');$.fancybox(dialog,{'showCloseButton':false});}else{this.resetSessionCookies();}},resetSessionCookies:function(){var redirect=escape(window.location.pathname+window.location.search);window.location='/logout?r='+redirect;},htmlReady:function(str){return $('<div>').text(str).html();},ajax:{listen:[],observers:[],lastResponse:FLY_CONTEXT.serverTime,registerObserver:function(observer,channelToken){this.observers.push(observer);if(channelToken&&jQuery.inArray(channelToken,this.listen)==-1){this.listen.push(channelToken);}},ajax:function(settings){var self=this;var callback=settings.success;settings.success=function(data,status,request){for(var i=0;i<self.observers.length;i++){self.observers[i](data,status,request);}
if(callback){callback.call(settings.context?settings.context:this,data,status,request);}
self.lastResponse=data.responseTime;};if(this.listen.length){if(!settings.data){settings.data={};}
settings.data._listen=this.listen;}
settings.data._listenTime=self.lastResponse;return jQuery.ajax(settings);},get:function(url,data,callback,type){if(jQuery.isFunction(data)){type=type||callback;callback=data;data=null;}
return this.ajax({type:"GET",url:url,data:data,success:callback,dataType:type});},getJSON:function(url,data,callback){return this.get(url,data,callback,"json");},post:function(url,data,callback,type){if(jQuery.isFunction(data)){type=type||callback;callback=data;data={};}
return this.ajax({type:"POST",url:url,data:data,success:callback,dataType:type});}},prettyDate:function(time){var date=new Date((time||"").replace(/-/g,"/").replace(/[TZ]/g," ")),diff=(((new Date()).getTime()-date.getTime())/1000),day_diff=Math.floor(diff/86400);if(isNaN(day_diff)||day_diff<0)
return'just now';return day_diff==0&&(diff==1&&"1 second ago"||diff<60&&Math.floor(diff)+" seconds ago"||diff<120&&"1 minute ago"||diff<3600&&Math.floor(diff/60)+" minutes ago"||diff<7200&&"1 hour ago"||diff<86400&&Math.floor(diff/3600)+" hours ago")||day_diff==1&&"Yesterday"||day_diff<7&&day_diff+" days ago"||day_diff==7&&"1 week ago"||day_diff>7&&Math.ceil(day_diff/7)+" weeks ago";}};window.onerror=function(errorMsg,url,lineNumber){if(errorMsg=="Error loading script"){return;}
try{var sinceLoaded=((new Date()).getTime()-FLY_CONTEXT.pageLoadTime);$.post('/ajax/jsErrorReporting.php',{'line':lineNumber,'time':sinceLoaded,'url':url,'msg':errorMsg,'page':window.location.href});}catch(e){}
try{FLY.debug(errorMsg);FLY.debug(url);FLY.debug(lineNumber);}catch(e){}};FLY.ajax.registerObserver(function(data){if(data.error&&data.error.code==401){FLY.handleUserLoggedOutExternally();}else if(data.coins){coins=data.coins.amount;FLY.setCoins(data.coins.amount);}},"coins");function fixProfilePicTitleText(){$('fb\\:profile-pic.fb_profile_pic_rendered[title]').each(function(){var t=this.title;$(this).find('img').attr('title',t).attr('alt',t);});}
function fixProfilePicErrors(){var imgs=$('img[fbmlswap]');imgs.each(function(){var container=this.parentNode;var curEl=$(this);var xfbml='<fb:profile-pic linked="false"';var importAttr=["uid","width","title","alt","size"];for(var i in importAttr){if(curEl.attr(importAttr[i])){xfbml+=' '+importAttr[i]+'="'+curEl.attr(importAttr[i])+'"';}}
xfbml+='></fb:profile-pic>';curEl.replaceWith(xfbml);try{FB.XFBML.parse(container);}catch(err){}});if(imgs.length){setTimeout(fixProfilePicTitleText,3000);}}
$(function(){setTimeout(fixProfilePicErrors,3000);setTimeout(fixProfilePicTitleText,3000);});var preloadImageURLs=[];var ImagePreloader={errorDelay:999,simultaneousConnections:2,imgURLs:[],numLoaded:0,errorTimer:null,preloadRemaining:function(){if(ImagePreloader.imgURLs&&ImagePreloader.imgURLs.length&&ImagePreloader.imgURLs[ImagePreloader.numLoaded]){var img=new Image();img.src=ImagePreloader.imgURLs[ImagePreloader.numLoaded];if(img.complete){ImagePreloader.imageLoaded();}else{$(img).bind('error load onreadystatechange',ImagePreloader.imageLoaded);}}},preload:function(url){var numImg=ImagePreloader.imgURLs.length;ImagePreloader.imgURLs[numImg]=url;if(numImg==ImagePreloader.numLoaded){ImagePreloader.preloadRemaining();}},imageLoaded:function(){if(ImagePreloader.imgURLs&&ImagePreloader.imgURLs.length&&ImagePreloader.imgURLs[ImagePreloader.numLoaded]){ImagePreloader.numLoaded++;}
ImagePreloader.preloadRemaining();}};function activatePlaceholders(el){if(jQuery.browser.safari)return false;el=el||document;var inputs=$(el).find("input[type=text][placeholder]");inputs.focus(function(){var t=$(this);t.removeClass("showingplaceholder");if(t.val()==t.attr("placeholder"))t.val("");});var showPlaceholderFunc=function(){var t=$(this);if(t.val()==''){t.addClass("showingplaceholder");t.val(t.attr("placeholder"));}};inputs.blur(showPlaceholderFunc);inputs.each(showPlaceholderFunc);}
function temporarilyDisable(el){el=$(el);el.attr("disabled",true);setTimeout(function(){el.attr("disabled",false);},5000);}
function addEvent(obj,evType,fn,useCapture){if(obj.addEventListener){obj.addEventListener(evType,fn,useCapture);return true;}else if(obj.attachEvent){var r=obj.attachEvent("on"+evType,fn);return r;}else{FLY.debug("Handler could not be attached");return false;}}
var pageTracker=null;function gaEvent(cat,act,o_lbl,o_val){var bits={'cat':cat,'act':act};if(o_lbl){bits['lbl']=o_lbl;}
if(o_val){bits['val']=o_val;}
$.get('/ajax/logEvent.php',bits);try{if(pageTracker){pageTracker._trackEvent(cat,act,o_lbl,o_val);}else{FLY.debug("GA event: "+cat+"::"+act+" ("+o_lbl+", "+o_val+")");}}catch(err){}}
function gaPage(page){try{if(pageTracker){pageTracker._trackPageview(page);}}catch(err){}}
function AsyncNotification(url,params){this.url=url;this.params=params||{};}
AsyncNotification.prototype.send=function(cached){var target=this.url;if(target.indexOf('?')==-1)
target+='?';var data=[];for(var k in this.params)
data.push(encodeURIComponent(k)+'='+encodeURIComponent(this.params[k]));if(!cached){var d=new Date();data.push('time='+d.getTime());}
var img=new Image();img.src=(target+data.join('&'));return this;};var poppedWindows={};function popUp(url,options,name,crosswinjs){options=options||"width=890,height=525,resizable=yes,scrollbars=yes";if(!name){d=new Date();name="info"+d.getTime();}
if(!poppedWindows[name]||poppedWindows[name].closed||!poppedWindows[name].location){poppedWindows[name]=window.open(url,name,options);}
poppedWindows[name].location.href=url;if(crosswinjs){self.name="opener";if(!poppedWindows[name].opener)poppedWindows[name].opener=self;}
if(window.focus)poppedWindows[name].focus();return false;}
function closePopup(name){if(poppedWindows[name])poppedWindows[name].close();}
function openWindow(path,name,width,height,format){popUp(path,name,"width="+width+",height="+height+format);}
function print_r(arr,level){var dumped_text="";if(!level)level=0;var level_padding="";for(var j=0;j<level+1;j++)level_padding+="    ";if(typeof(arr)=='object'){for(var item in arr){var value=arr[item];if(typeof(value)=='object'){dumped_text+=level_padding+"'"+item+"' ...\n";dumped_text+=print_r(value,level+1);}else{dumped_text+=level_padding+"'"+item+"' => \""+value+"\"\n";}}}else{dumped_text="===>"+arr+"<===("+typeof(arr)+")";}
return dumped_text;}
function number_format(number,decimals,dec_point,thousands_sep){var n=number,prec=decimals;var toFixedFix=function(n,prec){var k=Math.pow(10,prec);return(Math.round(n*k)/k).toString();};n=!isFinite(+n)?0:+n;prec=!isFinite(+prec)?0:Math.abs(prec);var sep=(typeof thousands_sep==='undefined')?',':thousands_sep;var dec=(typeof dec_point==='undefined')?'.':dec_point;var s=(prec>0)?toFixedFix(n,prec):toFixedFix(Math.round(n),prec);var abs=toFixedFix(Math.abs(n),prec);var _,i;if(abs>=1000){_=abs.split(/\D/);i=_[0].length%3||3;_[0]=s.slice(0,i+(n<0))+
_[0].slice(i).replace(/(\d{3})/g,sep+'$1');s=_.join(dec);}else{s=s.replace('.',dec);}
var decPos=s.indexOf(dec);if(prec>=1&&decPos!==-1&&(s.length-decPos-1)<prec){s+=new Array(prec-(s.length-decPos-1)).join(0)+'0';}
else if(prec>=1&&decPos===-1){s+=dec+new Array(prec).join(0)+'0';}
return s;}
function shuffleArray(arr){var i=arr.length;if(i==0){return false;}
while(--i){var j=Math.floor(Math.random()*(i+1));var tempi=arr[i];var tempj=arr[j];arr[i]=tempj;arr[j]=tempi;}}
$(function(){if($.browser.msie&&$.browser.version.substr(0,1)==7){$(window).resize(function(){$('body').hide().show();$('#header').hide().show();});}});$.fn.exists=function(){return $(this).length!==0;};var LIKES_TRACKING={messageQueue:null,actionTypes:{UNKNOWN:0,LIKED:1,UNLIKED:2},likedURL:function(url){this.messageQueue.queueServerMessage('fb_like',{"url":url,"action":this.actionTypes.LIKED});},clickedLikeBox:function(profileID){this.messageQueue.queueServerMessage('fb_like_box',{"profile_id":profileID,"action":this.actionTypes.UNKNOWN});},init:function(){var self=this;this.messageQueue=ServerMessageQueue.create('/inbox/like/add/json',{ajax:{data:{'form_token':FLY_CONTEXT.formToken,_listen:['coins']}}});FLY_FB.detectLikeBoxClicks(function(clickedBox){clickedBox=$(clickedBox);self.clickedLikeBox(clickedBox.attr('profile_id'));});onFBReady(function(){try{FB.Event.subscribe('edge.create',function(url){LIKES_TRACKING.likedURL(url);});}catch(e){}});}};onFLYReady(function(){LIKES_TRACKING.init();});onFLYReady(function(){$('#search').submit(function(){return false;});$('#search input').keyup(function(){var box=$('#search-results');var list=$('#search-results ul');var query=$.trim($(this).val());if(query.length){onFBReady(function(){FB.api('/search?type=page&q='+query,function(response){var objects=response.data||[];var top5=objects.slice(0,5);list.children('li:visible').remove();if(top5.length){var tpl=list.find('li.tpl');for(var i in top5){var el=tpl.clone().removeClass('tpl');el.find('.link').attr('href','/page?id='+top5[i].id);el.find('.thumb').attr('src','http://graph.facebook.com/'+top5[i].id+'/picture');el.find('.name').text(top5[i].name);el.find('.cat').text(top5[i].category.replace(/_/g,' ').replace(/(^|\s)([a-z])/g,function(m,p1,p2){return p1+p2.toUpperCase();}));list.append(el.show());}
list.children().last('li').addClass('last');box.show();}});});}else{box.hide();}}).click(function(event){var v=$.trim($(this).val());if(v.length){$('#search-results').show();event.stopPropagation();}});$('#search-results').click(function(event){event.stopPropagation();});$(document).click(function(){$('#search-results').hide();});});;var FLY_FB={streamPublish:function(feedItem,source,callback,usePreloadedDialog){var self=this;usePreloadedDialog=usePreloadedDialog||false;callback=callback||jQuery.noop;feedItem.method='stream.publish';if(usePreloadedDialog){FLY.debug("TODO: preloaded feeds are currently not supported. Using normal feed instead.");}
try{FB.ui(feedItem,function(response){var success=self.trackPublishEvent(response,source);callback(success);});gaEvent('FBConnect','stream_publish_prompted','feed_item_'+source);}catch(err){callback(false);FLY.debug("stream.publish failed: ");FLY.debug(err);}},trackPublishEvent:function(response,source){if(response&&response.post_id&&response.post_id!=='null'){gaEvent("FBConnect","stream_publish_allowed","feed_item_"+source);return true;}else{gaEvent("FBConnect","stream_publish_denied","feed_item_"+source);return false;}},likeBoxDetectorState:-1,currentLikeBox:null,likeBoxDetectorCallbacks:[],autoReclaimPageFocus:false,detectLikeBoxClicks:function(callback,config){this.initializeLikeBoxDetector(config);this.likeBoxDetectorCallbacks.push(callback);},prepareLikeBoxes:function(){$('fb\\:like-box').addClass("detect-like-clicks");},initializeLikeBoxDetector:function(config){if(this.likeBoxDetectorState!=-1){return;}
var self=this;if(config!==undefined){for(var prop in config){if(self[prop]!=undefined){self[prop]=config[prop];}}}
this.likeBoxDetectorState=0;this.prepareLikeBoxes();onFBReady(function(){try{FB.Event.subscribe('xfbml.render',function(){self.prepareLikeBoxes();});}catch(e){}});$('.detect-like-clicks').live('mouseenter',function(){self.currentLikeBox=this;}).live('mouseout',function(){self.currentLikeBox=null;});$(document).mouseover(function(evt){if(self.likeBoxDetectorState==1){self.likeBoxDetectorState=0;self.reclaimPageFocus(evt);}});$(window).blur(function(evt){if(self.currentLikeBox){self.likeBoxDetectorState=1;self.handleLikeBoxClicked(self.currentLikeBox,evt);}});},handleLikeBoxClicked:function(likeBox,evt){var self=this;for(var i=0,len=this.likeBoxDetectorCallbacks.length;i<len;++i){if(jQuery.isFunction(this.likeBoxDetectorCallbacks[i])){try{this.likeBoxDetectorCallbacks[i](likeBox);}catch(e){}}}
if(self.autoReclaimPageFocus){self.reclaimPageFocus(evt);}},reclaimPageFocus:function(evt){if(!jQuery.browser.mozilla){setTimeout(function(){$(window).focus();},50);}else{var dummyTextBox=$('<input style="width:1px;height:1px;position:absolute" width="1"></input>');dummyTextBox.css({left:evt.pageX,top:evt.pageY});setTimeout(function(){$('body').prepend(dummyTextBox);dummyTextBox.focus().remove();},50);}}};function do_fb_login(o_btn_label,o_callback){onFBReady(function(){try{FB.login(jQuery.noop,{perms:'user_likes,user_location,user_birthday,user_education_history,user_relationships,user_photos,email'});gaEvent("FBConnect","login",o_btn_label);gaPage("/sim/FBConnect_login");}catch(e){}});}
function facebook_logout(){gaEvent("FBConnect","logout");var justInCase=setTimeout(function(){window.location='/logout';},4000);try{var logoutCallback=function(){clearTimeout(justInCase);setTimeout(function(){window.location='/logout';},10);};FB.logout(logoutCallback);}catch(e){return true;}
return false;}
function facebook_onlogin_ready(){}
var FBPopupIsHidden=false;function hidePreloadedPopup(){FBPopupIsHidden=true;$('.fb_popupContainer').css("margin-left","-50000px");FB.Connect.get_status().waitUntilReady(function(){if(FBPopupIsHidden){var container=$('.fb_popupContainer');var numModified=container.find('.fb_popup').filter(function(index){return $(this).width()>575;}).css("margin-left","-50000px").length;if(numModified>0){$('.fb_popupContainer').css("margin-left","0");}}});}
function showPreloadedPopup(){FBPopupIsHidden=false;$('.fb_popupContainer').css("margin-left","0").find('.fb_popup').css("margin-left","0");}
function swizzleJSONParse(){if(FB_RequireFeatures){FB_RequireFeatures(["Api","Connect","XFBML","Base","Common"],function(){FB.JSON.parse=function(text,reviver){var j;function walk(a,c){var b,d,e=a[c];if(e&&typeof e==='object'){for(b in e){if(Object.hasOwnProperty.call(e,b)){d=walk(e,b);if(d!==undefined){e[b]=d;}else{delete e[b];}}}
return reviver.call(a,c,e);}}
var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
var replacedText=text.replace(/\\\'/g,'\'');replacedText=replacedText.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(replacedText)){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
throw new SyntaxError('JSON.parse');};});}}