var LoginLBBaseController={doFriendFinder:false,messageTimer:null,messageInterval:10000,messageIndex:0,connectMessages:["Busy finding friends...","Sled dogs at full speed!","Wow, some of your friends found good hiding places!  Still seeking..."],mixIn:function(a){for(var b in a){this[b]=a[b]}},skipToPrompt:function(a){this.handleIsPbUserPrompt()},skipToNewUser:function(b){this.setFormProtectKeys();var c=jq(".loginlb .welcome");if(this.extProfileUrl){c.before('<span class="share '+this.serviceName+'"></span>');c.before('<img src="'+this.extProfileUrl+'" />')}var a=(this.extUserName)?"Welcome to Photobucket "+this.extUserName+"!":"Register with "+this.displayName+"!";c.html(a);jq(".loginmain").hide();jq(".PBPrompt").show();this.handleToggleChoosePW(this.showExtras)},skipToFriendFinder:function(a){var b=jq(".loginlb .welcome");b.html("Make it easy to share...");jq(".friendresults").hide();jq(".autoshareprompt").show()},handleIsPbUserPrompt:function(){var b=jq(".loginlb .welcome");if(this.extProfileUrl){b.before('<span class="share '+this.serviceName+'"></span>');b.before('<img src="'+this.extProfileUrl+'" />')}var a=(this.extUserName)?"Welcome to Photobucket "+this.extUserName+"!":"Login with "+this.displayName+"!";b.html(a);jq(".loginmain").hide();jq(".PBPrompt").show();jq(".hasaccount").show()},handleExistingUser:function(){document.fire(PBLightbox.PBMessage.EVENT.CLOSE);jq(".hasaccount").hide();jq(".choosepw").hide();jq(".pblogin").show();this.activeForm=jq("#pbloginform")},handlePBUserLogin:function(){var b=this;var c=this.activeForm.serialize();var a=jq.param(this.extUserInfo);var d=c+"&"+a+"&mode=connect";d+="&ts="+this.fpTs+"&sig="+this.fpSig;this.showProgress("Connecting your account...");if(this.doFriendFinder){this.startMessageTimer()}jq.post(this.serviceLoginUrl,d,function(e){if(e.response.stat=="ok"){if(e.response.status=="loggedin"){if(b.isTwitterLanding){tr("twitter_landing_connect")}document.location.href=e.response.redir}else{if(e.response.status=="loggedout"){b.extractFormProtectKeys(e);b.hideProgress();b.fireMessage("error",e.response.message)}}}},"json")},handleToggleChoosePW:function(d){jq(".hasaccount").hide();if(this.extUserInfo.name){var b=(this.extUserInfo.screen_name)?this.extUserInfo.screen_name:this.extUserInfo.name;b=b.replace(" ","_");this.handleVerifyUserName(b);jq("#choosepwform #username")[0].value=b}if(d){jq("#choosepwform .choose").html("Please provide some additional information:");jq("#choosepwform .extra").each(function(e){jq(this).show()});if(typeof(this.extUserInfo.gender)=="string"){var c=this.extUserInfo.gender;var a=(c=="male")?"M":"F";jq("#choosepwform #gender"+a)[0].checked=true}}else{jq("#choosepwform .choose").html("Please choose a Photobucket username and password:")}jq(".choosepw").show();this.activeForm=jq("#choosepwform")},handleVerifyUserName:function(a){this.bubbleCtrl.hide("bubbleUsername");if(!this.isVerifyingUname){this.isVerifyingUname=true;new APIRequest("isusernameavailable",true,{username:a},this.handleUsernameOnSuccess.bind(this))}},handleUsernameOnSuccess:function(resp){if(resp.available!=1){var event=this.ctrlName+".EVENT.SUGGESTCLOSE";var bubble=new Bubble({elemId:"bubbleUsername",targetId:"username",eventOff:eval(event),posOffset:true,offsetX:435,offsetY:-10,useWindow:document});this.bubbleCtrl.addBubble(bubble);var suggestions="";for(var n in resp.suggestions){if(resp.suggestions[n].suggestion){suggestions+='<li><a href="javascript:void(0);" onclick="'+this.ctrlName+'.getInstance().handleSuggestion(this);">'+resp.suggestions[n].suggestion+"</a>"}}var bubContent=jq("#bubbleUsername #suggestions").html(suggestions);this.bubbleCtrl.show("bubbleUsername")}this.isVerifyingUname=false},handleNormalPBLogin:function(b){var d="#loginform ";var e=jq("#loginform");var a=jq("#loginform #usernameemail").val();var c=jq("#loginform #password").val();if(a==""){this.fireInputErrorMessage(d+"#usernameemail","A username or email is required.");return false}if(c==""){this.fireInputErrorMessage(d+"#password","A password required.");return false}if(!this.isHP){jq("#returnUrl").val(document.location.href)}this.showProgress();e.submit()},validateNewUserSubmit:function(c){var b="#choosepwform #";for(var e in c){if(e=="username"){if(this.isEmptyField(c[e])){this.fireInputErrorMessage(b+e,"Please enter a username");return false}var d="Usernames must be at least 3 characters long. ";d+="They can only contain the characters a-z, A-Z, 0-9, -, _, ";d+="and must begin with either a letter, a number, or an underscore. ";d+="Spaces are not allowed.";if(c[e].length<3||c[e].length>50){this.fireInputErrorMessage(b+e,d);return false}var a=/^[a-zA-Z0-9_][-a-zA-Z0-9_]+$/;if(!a.test(c[e])){this.fireInputErrorMessage(b+e,d);return false}}else{if(e=="password"){if(this.isEmptyField(c[e])){this.fireInputErrorMessage(b+e,"Please enter a password");return false}var d="Passwords must be at least 6 characters long. ";d+="They can only contain the characters a-z, A-Z, 0-9, -, _, ";d+="contain no spaces, and cannot start with a zero.";if(c[e].length<6||c[e].length>50){this.fireInputErrorMessage(b+e,d);return false}var a=/^[a-zA-Z1-9_-][a-zA-Z0-9_-]+$/;if(!a.test(c[e])){this.fireInputErrorMessage(b+e,d)}}else{if(e=="email"){var d="Please enter a valid email address";if(this.isEmptyField(c[e])){this.fireInputErrorMessage(b+e,d);return false}var a=/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;if(!a.test(c[e])){this.fireInputErrorMessage(b+e,d);return false}}else{if(e=="gender"){var d="Please select a gender";if(this.isEmptyField(c[e])){this.fireInputErrorMessage(b+e,d);return false}}else{if(e=="birthMonth"||e=="birthDay"||e=="birthYear"){if(!this.isNumber(c[e])){this.fireInputErrorMessage(b+e,"Please enter your birth date.");return false}}}}}}}return true},isEmptyField:function(a){return(a=="")},isNumber:function(a){return !isNaN(parseFloat(a))&&isFinite(a)},watchUname:function(a){var b=this;jq("#choosepwform #username").bind("blur",function(){b.handleVerifyUserName(jq(this).val())})},handleSuggestion:function(obj){var uname=obj.innerHTML;var formFields=jq("#choosepwform :input");formFields[0].value=uname;formFields[0].focus();formFields[1].focus();var event=this.ctrlName+".EVENT.SUGGESTCLOSE";document.fire(eval(event))},setFriendstoFollow:function(a){this.hasFriendsToFollow=true;this.friendsToFollow=a},startMessageTimer:function(){this.messageTimer=window.setInterval(this.updateMessage.bind(this),this.messageInterval)},updateMessage:function(){var a=jq(".loginlb .progress .message");if(a.length&&this.messageIndex<this.connectMessages.length){a.html(this.connectMessages[this.messageIndex]);this.messageIndex++}},resetChoosePWForm:function(){var a=jq("#choosepwform #email").val("");jq("#choosepwform .extra.emailext").each(function(b){jq(this).removeClass("hilightError");jq(this).hide()});jq("#choosepwform .extra.genderext").each(function(b){jq(this).removeClass("hilightError");jq(this).hide()})},extractFormProtectKeys:function(a){if(a.response.sig){this.fpSig=a.response.sig}if(a.response.ts){this.fpTs=a.response.ts}},setFormProtectKeys:function(){this.fpSig=jq('#extLoginkeys input[name="sig"]').val();this.fpTs=jq('#extLoginkeys input[name="ts"]').val()},fireInputErrorMessage:function(a,b){this.fireMessage("error",b);jq(a)[0].focus()},fireMessage:function(d,c){var a=(d=="success")?"success":"error";var b=(a=="success")?"Success":"Attention";document.fire(PBLightbox.PBMessage.EVENT.NOTIFY,{message:new PBMessage({title:b,details:c,type:a})})},showProgress:function(b){var a=(typeof(b)!="undefined")?{message:b}:{};document.fire(PBLightbox.PBProgress.EVENT.ACTIVATE,a)},hideProgress:function(){window.clearInterval(this.messageTimer);document.fire(PBLightbox.PBProgress.EVENT.DEACTIVATE)}};LoginLBBaseController=Class.create(LoginLBBaseController);var LoginLBFacebookController;(function(){var a={ctrlName:"LoginLBFacebookController",displayName:"Facebook",serviceName:"facebook",serviceLoginUrl:"/lblogin/facebooklogin/",bttnPBLogIn:null,isHP:false,isUpload:false,isBanner:false,extUserAuth:null,extUserInfo:null,extUserName:null,extProfileUrl:null,createUserFromExtData:false,bubbleCtrl:null,isVerifyingUname:false,fromReg:false,showExtras:false,hasBasicPerms:true,activeForm:null,fpTs:null,fpSig:null,newUserMap:{username:null,password:null,email:null,gender:null,birthMonth:null,birthDay:null,birthYear:null},hasFriendsToFollow:false,friendsToFollow:null,initialize:function(){Event.observe(document,LoginLBFacebookController.EVENT.LOADED,this.bindHandlers.bindAsEventListener(this));Event.observe(document,LoginLBFacebookController.EVENT.PROMPT,this.skipToPrompt.bindAsEventListener(this));Event.observe(document,LoginLBFacebookController.EVENT.NEWUSER,this.skipToNewUser.bindAsEventListener(this));Event.observe(document,LoginLBFacebookController.EVENT.NEWUSERFB,this.handleFBNewUser.bindAsEventListener(this));Event.observe(document,LoginLBFacebookController.EVENT.AUTOSHAREPROMPT,this.skipToAutoSharePrompt.bindAsEventListener(this));Event.observe(document,LoginLBFacebookController.EVENT.SKIPFRIENDFINDER,this.skipToFriendFinder.bindAsEventListener(this));Event.observe(document,LoginLBFacebookController.EVENT.CHECKLOGINSTATUS,this.checkLoginStatus.bindAsEventListener(this));Event.observe(document,LoginLBFacebookController.EVENT.LOGOUT,this.handleLogout.bindAsEventListener(this));Event.observe(document,LoginLBFacebookController.EVENT.WATCHUNAME,this.watchUname.bindAsEventListener(this));this.bubbleCtrl=new BubbleController()},bindHandlers:function(c){this.setFormProtectKeys();if(typeof(FB)!="undefined"){FB.XFBML.parse()}this.bttnPBLogIn=jq("#loginform #bttnPBLogIn")[0];if(this.bttnPBLogIn){Event.observe(this.bttnPBLogIn,"click",this.handleNormalPBLogin.bindAsEventListener(this))}jq(".loginmain").show()},skipToAutoSharePrompt:function(c){var d=this;FB.getLoginStatus(function(e){if(e.authResponse){d.extUserAuth=e.authResponse;d.extProfileUrl="http://graph.facebook.com/"+e.authResponse.userID+"/picture";FB.api("/me",function(g){d.extUserInfo=g;d.extUserName=g.name;var h=jq(".loginlb .welcome");if(d.extProfileUrl){h.before('<span class="share facebook"></span>');h.before('<img src="'+d.extProfileUrl+'" />')}if(d.hasFriendsToFollow&&this.doFriendFinder){jq(".autoshareprompt").before(d.friendsToFollow.html);var f="Welcome to Photobucket";f+=(d.extUserName)?" "+d.extUserName+"!":"!";h.html(f)}else{var f="Make it easy to share...";h.html(f);jq(".autoshareprompt").show()}jq(".loginmain").hide();jq(".PBPrompt").show()})}},true)},checkLoginStatus:function(c){this.isHP=c.memo.isHP;this.isUpload=c.memo.isUpload;if(c.memo.isBanner){this.isBanner=c.memo.isBanner}var d=this;FB.getLoginStatus(function(e){if(e.authResponse){FB.api({method:"users.hasAppPermission",ext_perm:"publish_stream"},function(f){if(f!="1"){d.hasBasicPerms=false}});FB.api({method:"users.hasAppPermission",ext_perm:"offline_access"},function(f){if(f!="1"){d.hasBasicPerms=false}});if(!d.hasBasicPerms){tr("facebook_login_initial_permission_impression")}d.extUserAuth=e.authResponse;d.extProfileUrl="http://graph.facebook.com/"+e.authResponse.userID+"/picture";FB.api("/me",function(f){d.extUserInfo=f;d.extUserName=f.name;if(d.isHP||d.isUpload){d.handleFacebookHP(f)}else{d.handleFacebook(f)}})}},true)},handleFBNewUser:function(c){this.showFBProgress(true);this.setFormProtectKeys();var d=this;var e={mode:"lookup",sig:this.fpSig,ts:this.fpTs};jq.post(this.serviceLoginUrl,e,function(f){if(f.response.stat=="ok"){if(f.response.status=="loggedin"){document.location.href=f.response.redir}else{d.showFBProgress(false);FB.getLoginStatus(function(g){if(g.authResponse){d.extUserAuth=g.authResponse;d.extProfileUrl="http://graph.facebook.com/"+g.authResponse.userID+"/picture";FB.api("/me",function(h){d.extUserInfo=h;d.extUserName=h.name;if(h.birthday){d.createUserFromExtData=true}else{d.showExtras=true}d.fromReg=true;document.fire(PBLightbox.EVENT.ACTIVATE,{contentUrl:"/lblogin/?service=facebook&newuser=1",cache:false});tr("facebook_registration_allow_permissions")})}else{jq(".regright h3").addClass("hilightError");document.fire(PBMessage.EVENT.NOTIFY,{message:new PBMessage({title:"There was an error with your submission",details:"You must allow Photobucket permission to access your Facebook information to sign up for a new account.",type:"error"})});tr("facebook_registration_deny_permissions")}},true)}}},"json")},handleFacebookHP:function(){this.showFBProgress(true);this.setFormProtectKeys();var c=this;var d={mode:"lookup",sig:this.fpSig,ts:this.fpTs};jq.post(this.serviceLoginUrl,d,function(e){if(e.response.stat=="ok"){if(e.response.status=="loggedin"){if(c.isUpload){tr("uploadsignup_login_total");document.location.reload(true)}else{if(!this.isBanner){tr("homepage_login_total")}document.location.href=e.response.redir}}else{if(e.response.status=="loggedout"){c.showFBProgress(false);if(c.hasBasicPerms){if(jq("#hpLoginbox").length>0){jq("#hpLoginbox").hide()}document.fire(PBLightbox.EVENT.ACTIVATE,{contentUrl:"/lblogin/?service=facebook&prompt=1",cache:false})}}}}},"json")},handleFacebook:function(){this.setFormProtectKeys();this.showProgress();var c=this;var d={mode:"lookup",sig:this.fpSig,ts:this.fpTs};jq.post(this.serviceLoginUrl,d,function(e){if(e.response.stat=="ok"){if(e.response.status=="loggedin"){document.location.href=e.response.redir}else{if(e.response.status=="loggedout"){c.extractFormProtectKeys(e);c.hideProgress();if(c.hasBasicPerms){c.handleIsPbUserPrompt()}else{c.fireMessage("error","You must allow Photobucket permission to access your Facebook account to connect")}}}}},"json")},handleNewUser:function(){document.fire(PBLightbox.PBMessage.EVENT.CLOSE);this.resetChoosePWForm();var c=this;FB.login(function(d){if(d.authResponse){c.showProgress();FB.api("/me",function(e){c.extUserInfo=e;c.extUserName=e.name;if(e.birthday){c.createUserFromExtData=true}else{c.showExtras=true}c.hideProgress();jq(".pblogin").hide();c.handleToggleChoosePW(c.showExtras)});tr("facebook_login_allow_second_set_of_permissions");tr("facebook_login_second_set_of_permission_impression")}else{c.fireMessage("error","You must be logged into Facebook.")}},{scope:"email,user_birthday,user_location"})},handleNewUserSubmit:function(){var o=this;var e=jq("#choosepwform #email");if(this.createUserFromExtData){var d=this.newUserMap;var h=this.extUserInfo;d.username=jq("#choosepwform #username").val();d.password=jq("#choosepwform #password1").val();var l=e.val();d.email=(l!="")?l:h.email;var c=jq("#choosepwform #genderM")[0];var i=jq("#choosepwform #genderF")[0];if(c.checked||i.checked){d.gender=(c.checked)?c.value:i.value}else{d.gender=h.gender}var j=h.birthday.split("/");d.birthMonth=j[0];d.birthDay=j[1];d.birthYear=j[2]}else{var m=this.activeForm.serializeArray();m.each(function(p){var q=p.name;var r=p.value;o.newUserMap[q]=r})}var g={zip:jq("#zip")[0].value,country:jq("#country")[0].value,createdFromExt:this.createUserFromExtData};this.newUserMap=jq.extend(this.newUserMap,g);var f=this.validateNewUserSubmit(this.newUserMap);if(f){document.fire(LoginLBFacebookController.EVENT.SUGGESTCLOSE);this.showProgress("Creating your account...");if(this.doFriendFinder){this.startMessageTimer()}var n={ts:this.fpTs,sig:this.fpSig};var k=jq.extend(this.extUserAuth.session,this.extUserInfo,this.newUserMap,n);jq.post(this.serviceLoginUrl+"?mode=create",k,function(q){o.extractFormProtectKeys(q);if(q.response.stat=="ok"){if(q.response.status=="loggedin"){if(!o.fromReg){tr("facebook_login_new_account_created_total")}document.location.href=q.response.redir}else{if(q.response.status=="loggedout"){o.hideProgress();o.fireMessage("error",q.response.message)}}}else{jq("#choosepwform .hilightError").each(function(r){jq(this).removeClass("hilightError")});var p=q.response.message;if(p.search(/Account already exists/i)!=-1){p="An account already exists with the same email address.<br/><br/>";p+='Please <a href="javascript:void(0);" onclick="LoginLBFacebookController.getInstance().handleExistingUser();return false;">login</a> or register with a different email address.';e.val(k.email);jq("#choosepwform .extra.emailext").each(function(r){jq(this).addClass("hilightError");jq(this).show()})}else{if(p.search(/gender/)!=-1){jq("#choosepwform .extra.genderext").each(function(r){jq(this).addClass("hilightError");jq(this).show()})}else{if(p.search(/birth/)!=-1){jq("#choosepwform .extra.birthdayext").each(function(r){jq(this).addClass("hilightError");jq(this).show()})}}}o.hideProgress();o.fireMessage("error",p)}},"json")}},handleLogout:function(){if(typeof(FB)=="undefined"){document.location.href="/logout"}FB.getLoginStatus(function(c){if(c.authResponse){document.fire(PBLightbox.EVENT.ACTIVATE,{contentUrl:"/lblogin/fblogout/",cache:false})}else{document.location.href="/logout"}},true)},doFacebookLogout:function(){document.fire(PBLightbox.PBProgress.EVENT.ACTIVATE);if(typeof(FB)=="undefined"){document.location.href="/logout"}FB.logout(function(c){document.location.href="/logout"})},handleAutoShareSetting:function(){var c={siteId:2,active:true,fromPromo:true,isLB:true};document.fire(AutoShareController.EVENT.SAVESHARESETTING,c)},showFBProgress:function(c){if(c){jq(".fbload").show()}else{jq(".fbload").hide()}}};var b={EVENT:{LOADED:"LoginLBFacebookController:loaded",PROMPT:"LoginLBFacebookController:prompt",NEWUSER:"LoginLBFacebookController:newuser",NEWUSERFB:"LoginLBFacebookController:newuserfb",AUTOSHAREPROMPT:"LoginLBFacebookController:autoshareprompt",SKIPFRIENDFINDER:"LoginLBFacebookController:skipfriendfinder",CHECKLOGINSTATUS:"LoginLBFacebookController:checkloginstatus",LOGOUT:"LoginLBFacebookController:logout",SUGGESTCLOSE:"LoginLBFacebookController:suggestclose",WATCHUNAME:"LoginLBFacebookController:watchuname"}};Controller.create("LoginLBFacebookController",a,b,LoginLBBaseController)})();var LoginLBTwitterController;(function(){var a={ctrlName:"LoginLBTwitterController",displayName:"Twitter",serviceName:"twitter",serviceLoginUrl:"/lblogin/twitterlogin/",bttnPBLogIn:null,isHP:false,isUpload:false,isBanner:false,extUserAuth:null,extUserInfo:null,extUserName:null,extProfileUrl:null,createUserFromExtData:false,bubbleCtrl:null,isVerifyingUname:false,fromReg:false,showExtras:false,hasBasicPerms:true,activeForm:null,fpTs:null,fpSig:null,newUserMap:{username:null,password:null,email:null,gender:null,birthMonth:null,birthDay:null,birthYear:null},hasFriendsToFollow:false,friendsToFollow:null,isTwitterLanding:false,authWin:null,authTimer:null,initialize:function(){Event.observe(document,LoginLBTwitterController.EVENT.LOADED,this.bindHandlers.bindAsEventListener(this));Event.observe(document,LoginLBTwitterController.EVENT.PROMPT,this.skipToPrompt.bindAsEventListener(this));Event.observe(document,LoginLBTwitterController.EVENT.HANDLETWITTERAUTH,this.handleTwitterAuth.bindAsEventListener(this));Event.observe(document,LoginLBTwitterController.EVENT.NEWUSER,this.skipToNewUser.bindAsEventListener(this));Event.observe(document,LoginLBTwitterController.EVENT.AUTOSHAREPROMPT,this.skipToAutoSharePrompt.bindAsEventListener(this));Event.observe(document,LoginLBTwitterController.EVENT.SKIPFRIENDFINDER,this.skipToFriendFinder.bindAsEventListener(this));Event.observe(document,LoginLBTwitterController.EVENT.LOGOUT,this.handleLogout.bindAsEventListener(this));Event.observe(document,LoginLBTwitterController.EVENT.WATCHUNAME,this.watchUname.bindAsEventListener(this));this.bubbleCtrl=new BubbleController()},bindHandlers:function(c){this.setFormProtectKeys();this.bttnPBLogIn=jq("#loginform #bttnPBLogIn")[0];if(this.bttnPBLogIn){Event.observe(this.bttnPBLogIn,"click",this.handleNormalPBLogin.bindAsEventListener(this))}jq(".loginmain").show()},authenticate:function(c){if(c){this.isTwitterLanding=true}this.authWin=window.open("/lblogin/twitterauthstart","Twitter_Auth","width=800,height=800,modal=yes,alwaysRaised=yes");this.authTimer=window.setInterval(this.checkIsAuthWindowClosed.bind(this),300)},checkIsAuthWindowClosed:function(){if(!this.authWin||this.authWin.closed){window.clearInterval(this.authTimer);document.fire(LoginLBTwitterController.EVENT.HANDLETWITTERAUTH)}},setTwitterParams:function(c){this.extUserInfo=c;this.extUserName=c.screen_name;this.extProfileUrl=c.profile_image_url},skipToAutoSharePrompt:function(d){var e=jq(".loginlb .welcome");if(this.extProfileUrl){e.before('<span class="share twitter"></span>');e.before('<img src="'+this.extProfileUrl+'" />')}if(this.hasFriendsToFollow&&this.doFriendFinder){var c="Welcome to Photobucket";c+=(this.extUserName)?", "+this.extUserName+"!":"!";jq(".autoshareprompt").before(this.friendsToFollow.html);e.html(c)}else{var c="Make it easy to share...";e.html(c);jq(".autoshareprompt").show()}jq(".loginmain").hide();jq(".PBPrompt").show()},handleTwitterAuth:function(c){this.showTWProgress(true);this.setFormProtectKeys();var d=this;var e={mode:"lookup",sig:this.fpSig,ts:this.fpTs,isTwitterLanding:this.isTwitterLanding};jq.post(this.serviceLoginUrl,e,function(f){if(f.response.stat=="ok"){if(f.response.status=="loggedin"){if(d.isUpload){tr("uploadsignup_login_total");document.location.reload(true)}else{if(!d.isBanner){tr("homepage_login_total")}if(d.isTwitterLanding){tr("twitter_landing_connect")}document.location.href=f.response.redir}}else{if(f.response.status=="loggedout"){d.showTWProgress(false);if(f.response.extParams){d.setTwitterParams(f.response.extParams);if(jq("#hpLoginbox").length>0){jq("#hpLoginbox").hide()}document.fire(PBLightbox.EVENT.ACTIVATE,{contentUrl:"/lblogin/?service=twitter&prompt=1",cache:false})}}}}},"json")},handleNewUser:function(){document.fire(PBLightbox.PBMessage.EVENT.CLOSE);this.resetChoosePWForm();if(!this.extUserInfo){this.fireMessage("error","You must be logged into Twitter.");return}jq(".pblogin").hide();this.showExtras=true;this.handleToggleChoosePW(this.showExtras)},handleNewUserSubmit:function(){var j=this;var c=jq("#choosepwform #email");var h=this.activeForm.serializeArray();h.each(function(l){var m=l.name;var n=l.value;j.newUserMap[m]=n});var f={zip:jq("#zip")[0].value,country:jq("#country")[0].value,createdFromExt:this.createUserFromExtData};var k;if(this.extUserInfo.name){var d=this.extUserInfo.name.split(" ");k={first_name:d[0],last_name:d[1]}}this.newUserMap=jq.extend(this.newUserMap,f,k);var e=this.validateNewUserSubmit(this.newUserMap);if(e){document.fire(LoginLBTwitterController.EVENT.SUGGESTCLOSE);this.showProgress("Creating your account...");if(this.doFriendFinder){this.startMessageTimer()}var i={ts:this.fpTs,sig:this.fpSig};var g=jq.extend(this.extUserInfo,this.newUserMap,i);jq.post(this.serviceLoginUrl+"?mode=create",g,function(m){j.extractFormProtectKeys(m);if(m.response.stat=="ok"){if(m.response.status=="loggedin"){if(!j.fromReg){tr(j.serviceName+"_login_new_account_created_total")}if(j.isTwitterLanding){tr("twitter_landing_registration")}document.location.href=m.response.redir}else{if(m.response.status=="loggedout"){j.hideProgress();j.fireMessage("error",m.response.message)}}}else{jq("#choosepwform .hilightError").each(function(n){jq(this).removeClass("hilightError")});var l=m.response.message;if(l.search(/Account already exists/i)!=-1){l="An account already exists with the same email address.<br/><br/>";l+='Please <a href="javascript:void(0);" onclick="LoginLBTwitterController.getInstance().handleExistingUser();return false;">login</a> or register with a different email address.';c.val(g.email);jq("#choosepwform .extra.emailext").each(function(n){jq(this).addClass("hilightError");jq(this).show()})}else{if(l.search(/gender/)!=-1){jq("#choosepwform .extra.genderext").each(function(n){jq(this).addClass("hilightError");jq(this).show()})}else{if(l.search(/birth/)!=-1){jq("#choosepwform .extra.birthdayext").each(function(n){jq(this).addClass("hilightError");jq(this).show()})}}}j.hideProgress();j.fireMessage("error",l)}},"json")}},handleLogout:function(){document.location.href="/logout"},handleAutoShareSetting:function(){var c={siteId:3,active:true,fromPromo:true,isLB:true};document.fire(AutoShareController.EVENT.SAVESHARESETTING,c)},showTWProgress:function(c){if(c){jq(".twload").show()}else{jq(".twload").hide()}}};var b={EVENT:{HANDLETWITTERAUTH:"LoginLBTwitterController:handletwitterauth",LOADED:"LoginLBTwitterController:loaded",PROMPT:"LoginLBTwitterController:prompt",NEWUSER:"LoginLBTwitterController:newuser",AUTOSHAREPROMPT:"LoginLBTwitterController:autoshareprompt",SKIPFRIENDFINDER:"LoginLBTwitterController:skipfriendfinder",CHECKLOGINSTATUS:"LoginLBTwitterController:checkloginstatus",LOGOUT:"LoginLBTwitterController:logout",SUGGESTCLOSE:"LoginLBTwitterController:suggestclose",WATCHUNAME:"LoginLBTwitterController:watchuname"}};Controller.create("LoginLBTwitterController",a,b,LoginLBBaseController)})();var FriendFinder=(function(){var e="/friendfinder/showfriends",r="/friendfinder/showfriends",J="/friendfinder/updatefacebookauth",z="/friendfinder/followfriends",f="/friendfinder/completeFollow/",q="/friendfinder/processInvite",M,y,v,j=false,b=null,n=6000,c=0,Y=["Busy finding friends...","Sled dogs at full speed!","Wow, some of your friends found good hiding places!  Still seeking..."],s=[],l=PBMessage.MESSAGE_TYPE,C=l.ALERT,S=l.SUCCESS,t=l.ERROR,k=0,x=0,U=[],E,X=0;function H(){M=(j)?jq("#lightbox .container"):jq(".friendFinderContent")}function O(){if(!M){H()}M.find(".progress").remove();if(b){window.clearInterval(b);b=null}}function D(){var Z=M.find(".progress .message");if(Z&&c!==s.length){Z.html(s[c]);c++}else{c=0}}function g(ac,aa){O();var ab,Z;if(j){ab=M.prop("offsetWidth")-2;Z=M.prop("offsetHeight")-2}else{ab=M.parent().prop("offsetWidth")-2;Z=M.parent().prop("offsetHeight")-2}if(!ac){ac="We're searching for your friends who are using Photobucket."}M.prepend('<div class="progress modClrBg" style="width:'+ab+"px;height:"+Z+'px;z-index:5001;"><div class="message">'+ac+"</div></div>");if(aa){c=0;b=window.setInterval(D.bind(this),n)}}function R(ab,ac,aa){O();if(ac){var ad={type:ab,title:ac},Z=PBMessage.EVENT.NOTIFY;if(j){Z=PBLightbox.PBMessage.EVENT.NOTIFY}if(aa){ad.details=aa}document.fire(Z,{id:(j)?"":"friendFinderMessagePanel",message:new PBMessage(ad)})}else{document.fire(PBMessage.EVENT.CLOSE,{id:(j)?"":"friendFinderMessagePanel"})}}function P(Z){if(Z.response.stat!=="ok"){if(Z.response.hasOwnProperty("loggedOut")&&Z.response.loggedOut){R(t,"You must be logged in to perform this action");O();return false}}return true}function V(Z){if(Z){jq("#friendSearch").show();jq("#inviteFriends").show();jq("#recentFollowsContainer").show()}else{jq("#friendSearch").hide();jq("#inviteFriends").hide();jq("#recentFollowsContainer").hide()}}function i(){var Z=jq("#invitation");if(Z&&Z.length>0){if(typeof"PBInvite"!=="undefined"){PBInvite.init()}}}function N(Z,aa,ab){document.fire(PBMessage.EVENT.CLOSE);jq.ajax({url:Z,dataType:"json",data:aa,success:ab,type:"post"})}function d(ad){if(!P(ad)){return}AutoShareController.getInstance().unsetFindingFriends();var Z,aa=ad.response,ac,ab;if(aa.stat==="ok"){if(aa.hasOwnProperty("reconnect")&&aa.reconnect){O();AutoShareController.getInstance().setFindingFriends();V(true);R(C,aa.message.title,aa.message.details);return}if(aa.hasOwnProperty("redirect")&&aa.redirect){ab="http://"+location.host;if(v){ab+=v}else{ab+="/friendfinder"}if(aa.params){ab+=(ab.indexOf("?")===-1?"?":"&")+aa.params}location.href=ab;return}M.html(aa.innerHTML);ac=M.find("div.friendresults");if(!ac||ac.length===0){V(true)}Z=S}else{Z=t}R(Z,aa.message,aa.messageDetails)}function W(ab,aa){var Z="";if(aa){Z=aa+" "}Z+=(ab==="auth"?"friends":"contacts");s.splice(0,0,"When we're done, you'll be able to choose specific "+Z+" to follow on Photobucket");return"We're searching for your "+Z+" who are using Photobucket."}function p(ab,aa,Z){FB.login(function(ac){if(ac.authResponse){g(W("auth",Z),true);N(J,{},function(){L(ab,aa,Z)})}else{V(true);R(t,"You must allow Photobucket to access your Facebook account.")}},{scope:"publish_stream,offline_access"})}function L(ad,ac,aa){k=0;x=0;s=Y.slice(0);document.fire(PBMessage.EVENT.CLOSE);var ab,Z;H();ab={findingId:ad,findingType:"auth"};if(aa==="Facebook"){FB.getLoginStatus(function(ae){if(ae.authResponse){if(ae.authResponse.userID===ac){FB.api("/me/permissions",function(ag){var af=ag.data[0];if(af.offline_access!==1||af.publish_stream!==1){p(ad,ac,aa)}else{V(false);Z=M.find(".progress");if(!Z||Z.length===0){g(W("auth","Facebook"),true)}N(e,ab,d)}})}else{FB.logout(function(){p(ad,ac,aa)})}}else{p(ad,ac,aa)}},true)}else{V(false);g(W("auth",aa),true);N(e,ab,d)}}function h(Z,aa){k=0;x=0;s=Y.slice(0);document.fire(PBMessage.EVENT.CLOSE);H();var ab={findingId:Z,findingType:"contact"};V(false);g(W("contact",aa),true);N(r,ab,d)}function B(ab){var ac,Z,aa=ab.response;if(!P(ab)){return}if(j){if(aa.stat!=="ok"){ac="There was a problem following your friends.  Please try again.";R(t,ac);return}else{document.fire(y.EVENT.SKIPFRIENDFINDER);R(S,aa.message,aa.messageDetails)}}else{if(aa.stat!=="ok"){ac="There was a problem following your friends.  Please try again.";R(t,ac)}else{M.html(aa.innerHTML);V(true);if(aa.hasOwnProperty("noAction")&&aa.noAction){Z=l.ALERT}else{Z=S}R(Z,aa.message,aa.messageDetails);if(aa.recentFollows){jq("#recentFollowsContainer").remove();jq("div.panelRight").append(aa.recentFollows)}}}O()}function K(){H();var Z=jq("#followFriendsForm"),ah=Z.find("input[name=findingId]").val(),aj=Z.find("input[name=findingType]").val(),ag=Z.find("div.friend input[type=checkbox]"),ad={},ak=[],ab,af,ai,ac,aa={},ae={};ag.each(function(){ai=this.id.replace(/^follow_/,"");ac=jq(this).next("input[type=hidden][name^=findingId_]").val();if(this.checked){if(!ad.hasOwnProperty(ac)){ad[ac]=[]}ad[ac].push(ai)}else{ak.push(ai)}});af=jq(ad)[0];if(jq.isEmptyObject(af)){ab="Please select at least one friend to follow";R(t,ab)}else{jq.each(ad,function(am,al){aa[am]=al.join(",")});ae.userIds=aa;if(ak){ae.unfollowedUserIds=ak.join(",")}if(ah){ae.findingId=ah}if(aj){ae.findingType=aj}if(v){ae.returnUrl=v}ab="Following your "+(aj==="auth"?"friends":"contacts")+"...";g(ab);N(z,ae,B)}}function I(){X--;if(X===0){jq("#followAll").prop("disabled",false);jq("div.friend a.followButton").unbind("followComplete unfollowComplete",I)}}function o(){var ab,aa=0,Z;jq("#followAll").prop("disabled",true);if(jq("#followAll").prop("checked")){ab=jq("div.friend a.followButton[data-followee]:not(.isFollowing)");Z="friend_finder_follow_all_click";ab.bind("followComplete",I)}else{ab=jq("div.friend a.followButton.isFollowing");Z="friend_finder_unfollow_all_click";ab.bind("unfollowComplete",I)}X=ab.length;ab.click();tr(Z)}function A(){var aa=jq("#followFriendsForm"),Z=aa.find("input[name=findingId]").val(),ac=aa.find("input[name=findingType]").val(),ab={findingId:Z,findingType:ac,followedCount:x,invitedCount:k};if(v){ab.returnUrl=v}N(f,ab,B)}function w(ab,aa){if(!P(ab)){return}var Z=ab.response;if(Z.stat==="ok"){jq("#invite_"+aa).closest("div.friend").fadeOut(2000,function(){jq(this).remove()});k+=1}else{R(t,Z.message);jq("#invite_"+aa).text("Invite").removeClass("invited").attr("onclick",'FriendFinder.sendInviteTo("'+aa+'");')}}function a(Z){H();var ac=jq("#followFriendsForm"),aa=ac.find("input[name=findingId]").val(),ae=ac.find("input[name=findingType]").val(),ab=jq("#invite_"+Z),ad={toAddresses:ab.data("email"),findingId:aa,findingType:ae};ab.attr("onclick","").addClass("invited").text("Sending...");N(q,ad,function(af){w(af,Z)})}function G(ab){if(!P(ab)){return}var Z=ab.response,aa;if(Z.stat==="ok"){aa="http://"+location.host;if(v){aa+=v}else{aa+="/friendfinder"}if(Z.params){aa+=(aa.indexOf("?")===-1?"?":"&")+Z.params}location.href=aa}else{R(t,Z.message)}}function Q(){H();var aa=jq("#followFriendsForm"),ac=aa.find("input[name=toAddresses]"),Z="",ab={};if(!ac.hasClass("hint")){Z=ac.val()}ab.toAddresses=Z;g("Inviting your friends...");N(q,ab,G)}function u(aa){var Z="div.friend input[type=checkbox]";if(aa){Z+=":not(:checked)"}else{Z+=":checked"}jq("div.friend input[type=checkbox]").each(function(){this.checked=aa})}function m(aa,Z){j=aa;y=Z}function F(Z){v=Z}function T(){document.fire(PBLightbox.EVENT.ACTIVATE,{contentUrl:"/friendfinder/invite?isLightbox=true",cache:false})}jq(document).ready(function(){jq("a.followButton").live("followComplete",function(){x+=1;if(jq("div.friendresults").data("site")==="Facebook"){U.push(jq(this).closest("div.friend").find("label").text());if(!E){E=jq("#followFriendsForm").find("input[name=findingId]").val()}}}).live("unfollowComplete",function(){x-=1;if(jq("div.friendresults").data("site")==="Facebook"){var Z=jq(this).closest("div.friend").find("label").text(),aa;for(aa=0;aa<U.length;aa++){if(U[aa]===Z){U.splice(aa,1);break}}}})});jq(window).unload(function(){if(U.length>0){var Z={findingId:E,findingType:"auth",friends:U};N("/friendfinder/postFollows",Z,function(){})}});return{getFriends:L,getFriendsFromContacts:h,followFriends:K,sendInvite:Q,setIsLightBox:m,setPage:F,removeProgress:O,toggleSelected:u,completeFollow:A,followAllFriends:o,sendInviteTo:a,showInvitePreview:T}}());
