(function(c){c.widget("ui.mlayout",{_init:function(){this._items=null;this.element.data("muiResize",c.delegate(this,"resize")).addClass("mui-component mui-layout").css("position","relative");this.element.find(this.options.selector).css({position:"absolute",overflow:"hidden"});this.options.resizeOnInit&&this.resize({width:this.element.width(),width:this.element.height()})},items:function(){return this._items},sizeof:function(b){var a=null;if(typeof(b=="number")){if(b>=0&&b<this._items.length)a=this._items[b]}else c.each(this._items,
function(g,i){if(i.elmt.is(b)){a=i;return false}});if(a)return{width:a.width,height:a.height};return null},resize:function(b){var a=this.element.css({width:b.width+"px",height:b.height+"px"}).find(this.options.selector);if(this.options.columns){var g="width",i="left",e=this.options.columns.concat(),n={height:b.height},j="undefined"!==typeof b.top?b.top:0;a.css("top",0).height(b.height)}else{g="height";i="top";e=this.options.rows.concat();n={width:b.width};j="undefined"!==typeof b.left?b.left:0;a.css("left",
0).width(b.width)}for(;e.length<a.length;)e.push("auto");e=this._items=c.map(e,function(q,s){return c.extend({elmt:a.eq(s),hint:q,overridden:false,size:q,minSize:-1},n)});for(var l=this.options.space,o=b[g],f=o-(e.length-1)*l,p=[],k=[],m=0,h=0;h<e.length;h++){var d=e[h];if("number"==typeof d.size){m+=d.size;p.push(d)}else{d.size=d.hint+="";var r=/^(\d+)%$/.exec(d.size);if(r){d.size=Math.floor(f*parseInt(r[1])/100);m+=d.size;p.push(d)}else k.push(d)}}f-=m;if(f<0){do{if(l>0){l=(e.length-1)*l;if(l>-f){l=
Math.floor((l+f)/(e.length-1));f=o-(e.length-1)*l-m;break}else{l=0;f=o-m}}for(d=p.concat();f<0;){m=0;f=Math.ceil(-f/d.length);for(h=0;h<d.length;h++)if(d[h].size<f){d[h].size=0;d.splice(h,1)}else{d[h].size-=f;m+=d[h].size}f=o-m}if(f<0)f=0}while(0)}d=0;o=1/k.length;for(h=0;h<k.length;h++){k[h].size=Math.floor(f*o*(h+1))-d;d+=k[h].size}j=j;for(h=0;h<e.length;h++){d=e[h];k=pad2=0;if(this.options.pad&&this.options.pad[h]){f=this.options.pad[h];if("object"==typeof f){k=f[0];pad2=f[1]}else k=pad2=f}d[g]=
d.size-k-pad2;d[i]=j;d.elmt.css(g,d[g]+"px").css(i,j+"px");j+=d.size+l;f=c.extend({},n);f[g]=d.size-k-pad2;f[i]=k;d.elmt.muiResize(f)}this.options.onResize(b)}});c.ui.mlayout.getter="items sizeof";c.ui.mlayout.defaults={minWidth:-1,minHeight:-1,selector:"> *",columns:null,rows:null,space:0,resizeOnInit:false,onResize:function(){}}})(jQuery);var channel_path="/facebook/xd_receiver.htm",fb_session_data={};function connectFacebook(c,b,a){if("undefined"==typeof a)a=["email","publish_stream"];if("undefined"==typeof c)c=facebookComplete;c=new FBHelper(c,b);c.setPermissions(a);c.setRequiredPermissions(a);c.connect()}
(function(c){FBHelper=function(a,g){this._okcb=a;this._cancelcb=g;this._askperms=[];this._reqperms=[];this._perms=[];this._fbJason={}};var b=FBHelper.prototype;b.setRequiredPermissions=function(a){var g=this;c.each(a,function(i,e){-1==c.inArray(e,g._askperms)&&g._askperms.push(e);g._reqperms.push(e)})};b.setPermissions=function(a){this._askperms=a};b.showLoading=function(){c("#fbloadingmsg").show()};b.hideLoading=function(){c("#fbloadingmsg").hide()};b.show=function(){if(!this._layer)this._layer=
c('<div id="fboverlay" class="ui-widget-overlay"><div id="fbloadingmsg"><div id="fbloading">Contacting Facebook <img src="http://frontend.shwup.com/images/loading_16-1.1.gif"/></div><div id="FB_HiddenContainer" style="display:none; position:absolute; left:-100px; top:-100px; width:0px; height: 0px;"></div></div></div>').css({"z-index":100,top:0,left:0,width:0,height:0,position:"absolute"}).appendTo(document.body);screenSize=_swGetWindowSize();this._layer.css({width:screenSize.width+"px",height:screenSize.height+
"px"})};b.hide=function(){if(this._layer){this._layer.remove();delete this._layer}};b.complete=function(){this.hide();this._okcb&&this._okcb(this._fbJason.data,this._fbJason.authtoken,this._fbJason.firstTimeUser)};b.cancel=function(){this.hide();this._cancelcb&&this._cancelcb()};b.prompt=function(){alert("Sorry please try again(you have to allow permissions to use shwup)");this.hide();this._cancelcb&&this._cancelcb()};b.update=function(){var a=this;c.ajax({url:"/facebook/return",async:true,data:{fb_user_id:fb_session_data.uid,
fb_session_key:fb_session_data.session_key,fb_secret:fb_session_data.secret,fb_sig:fb_session_data.sig},complete:function(g,i,e){if(e.stat&&"ok"==e.stat){a._fbJason=e;a.complete()}else a.cancel()}})};b.handleGranted=function(){this.confirmPermToProceed()};b.confirmPermToProceed=function(){var a=this,g=new FB.BatchSequencer,i=[];c.each(this._askperms,function(n,j){i[n]={val:j,req:FB.Facebook.apiClient.users_hasAppPermission(j,g)}});var e=[];this.resetPermissions();this.showLoading();g.execute(function(){a.hideLoading();
c.each(i,function(){0==this.req.result?e.push(this.val):a.addPermission(this.val)});if(e.length){alert("You have to allow these permissions to use shwup");a.cancel();return false}else{a.update();return true}})};b.havePermission=function(a){for(var g in this._perms)if(this._perms[g]==a)return true;return false};b.resetPermissions=function(){this._perms=[]};b.addPermission=function(a){this._perms.push(a)};b.checkPermissions=function(){var a=this;if(fb_session_data.uid){var g=new FB.BatchSequencer,i=
[];c.each(this._askperms,function(n,j){i[n]={val:j,req:FB.Facebook.apiClient.users_hasAppPermission(j,g)}});var e=[];this.resetPermissions();this.showLoading();g.execute(function(){a.hideLoading();c.each(i,function(){0==this.req.result?e.push(this.val):a.addPermission(this.val)});e.length?FB.Connect.showPermissionDialog(e.join(","),c.delegate(a,"handleGranted")):a.update()})}else{alert("Unexpected error");this.hide();this._cancelfb&&this._cancelfb()}};b.setup=function(){var a=this;FB.init(api_key,
channel_path,{permsToRequestOnConnect:this._reqperms.join(",")});FB.ensureInit(function(){a.hideLoading();FB.Connect.requireSession(function(){FB.Facebook.get_sessionState().waitUntilReady(function(g){fb_session_data=g;a.checkPermissions()})},c.delegate(a,"prompt"))})};b.connect=function(){this.show();"undefined"===typeof FB?setTimeout(c.delegate(this,"setup"),0):this.setup()}})(jQuery);

