(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(e){var a=null;if(typeof(e=="number")){if(e>=0&&e<this._items.length)a=this._items[e]}else c.each(this._items,
function(b,f){if(f.elmt.is(e)){a=f;return false}});if(a)return{width:a.width,height:a.height};return null},resize:function(e){var a=this.element.css({width:e.width+"px",height:e.height+"px"}).find(this.options.selector);if(this.options.columns){a.css("top",0).height(e.height);var b="width",f="left",g=this.options.columns.concat(),j={height:e.height}}else{a.css("left",0).width(e.width);b="height";f="top";g=this.options.rows.concat();j={width:e.width}}for(;g.length<a.length;)g.push("auto");g=this._items=
c.map(g,function(p,r){return c.extend({elmt:a.eq(r),hint:p,overridden:false,size:p,minSize:-1},j)});for(var k=this.options.space,l=e[b],i=l-(g.length-1)*k,o=[],m=[],n=0,h=0;h<g.length;h++){var d=g[h];if("number"==typeof d.size){n+=d.size;o.push(d)}else{d.size=d.hint+="";var q=/^(\d+)%$/.exec(d.size);if(q){d.size=Math.floor(i*parseInt(q[1])/100);n+=d.size;o.push(d)}else m.push(d)}}i-=n;if(i<0){do{if(k>0){k=(g.length-1)*k;if(k>-i){k=Math.floor((k+i)/(g.length-1));i=l-(g.length-1)*k-n;break}else{k=0;
i=l-n}}for(d=o.concat();i<0;){n=0;i=Math.ceil(-i/d.length);for(h=0;h<d.length;h++)if(d[h].size<i){d[h].size=0;d.splice(h,1)}else{d[h].size-=i;n+=d[h].size}i=l-n}if(i<0)i=0}while(0)}l=0;o=1/m.length;for(h=0;h<m.length;h++){m[h].size=Math.floor(i*o*(h+1))-l;l+=m[h].size}for(h=m=0;h<g.length;h++){d=g[h];d[b]=d.size;d[f]=m;d.elmt.css(b,d.size+"px").css(f,m+"px");m+=d.size+k;i=c.extend({},j);i[b]=d.size;d.elmt.muiResize(i)}this.options.onResize(e)}});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,e,a){if("undefined"==typeof a)a=["email","publish_stream"];if("undefined"==typeof c)c=facebookComplete;c=new FBHelper(c,e);c.setPermissions(a);c.setRequiredPermissions(a);c.connect()}
(function(c){var e={};FBHelper=function(b,f){this._okcb=b;this._cancelcb=f;this._askperms=[];this._reqperms=[];this._perms=[];this._fbJason={}};var a=FBHelper.prototype;a.setRequiredPermissions=function(b){var f=this;c.each(b,function(g,j){-1==c.inArray(j,f._askperms)&&f._askperms.push(j);f._reqperms.push(j)})};a.setPermissions=function(b){this._askperms=b};a.showLoading=function(){c("#fbloadingmsg").show()};a.hideLoading=function(){c("#fbloadingmsg").hide()};a.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"})};a.hide=function(){if(this._layer){this._layer.remove();delete this._layer}};a.complete=function(){this.hide();this._okcb&&this._okcb(this._fbJason.data,this._fbJason.authtoken,this._fbJason.firstTimeUser)};a.cancel=function(){this.hide();this._cancelcb&&this._cancelcb()};a.prompt=function(){alert("Sorry please try again(you have to allow permissions to use shwup)");this.hide();this._cancelcb&&this._cancelcb()};a.update=function(){var b=this;c.ajax({url:"/facebook/return",async:true,data:{fb_user_id:e.uid,
fb_session_key:e.session_key,fb_secret:e.secret,fb_sig:e.sig},complete:function(f,g,j){if(j.stat&&"ok"==j.stat){b._fbJason=j;b.complete()}else b.cancel()}})};a.handleGranted=function(){this.confirmPermToProceed()};a.confirmPermToProceed=function(){var b=this,f=new FB.BatchSequencer,g=[];c.each(this._askperms,function(k,l){g[k]={val:l,req:FB.Facebook.apiClient.users_hasAppPermission(l,f)}});var j=[];this.resetPermissions();this.showLoading();f.execute(function(){b.hideLoading();c.each(g,function(){0==
this.req.result?j.push(this.val):b.addPermission(this.val)});if(j.length){alert("You have to allow these permissions to use shwup");b.cancel();return false}else{b.update();return true}})};a.havePermission=function(b){for(var f in this._perms)if(this._perms[f]==b)return true;return false};a.resetPermissions=function(){this._perms=[]};a.addPermission=function(b){this._perms.push(b)};a.checkPermissions=function(){var b=this;if(e.uid){var f=new FB.BatchSequencer,g=[];c.each(this._askperms,function(k,
l){g[k]={val:l,req:FB.Facebook.apiClient.users_hasAppPermission(l,f)}});var j=[];this.resetPermissions();this.showLoading();f.execute(function(){b.hideLoading();c.each(g,function(){0==this.req.result?j.push(this.val):b.addPermission(this.val)});j.length?FB.Connect.showPermissionDialog(j.join(","),c.delegate(b,"handleGranted")):b.update()})}else{alert("Unexpected error");this.hide();this._cancelfb&&this._cancelfb()}};a.setup=function(){var b=this;FB.init(api_key,"/facebook/xd_receiver.htm",{permsToRequestOnConnect:this._reqperms.join(",")});
FB.ensureInit(function(){b.hideLoading();FB.Connect.requireSession(function(){FB.Facebook.get_sessionState().waitUntilReady(function(f){e=f;b.checkPermissions()})},c.delegate(b,"prompt"))})};a.connect=function(){this.show();"undefined"===typeof FB?setTimeout(c.delegate(this,"setup"),0):this.setup()}})(jQuery);
