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 p=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 m=e.val();d.email=(m!="")?m:h.email;var c=jq("#choosepwform #genderM")[0];var j=jq("#choosepwform #genderF")[0];if(c.checked||j.checked){d.gender=(c.checked)?c.value:j.value}else{d.gender=h.gender}var k=h.birthday.split("/");d.birthMonth=k[0];d.birthDay=k[1];d.birthYear=k[2]}else{var n=this.activeForm.serializeArray();n.each(function(q){var r=q.name;var s=q.value;p.newUserMap[r]=s})}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 o={ts:this.fpTs,sig:this.fpSig};var l=jq.extend(this.extUserAuth.session,this.extUserInfo,this.newUserMap,o);jq.post(this.serviceLoginUrl+"?mode=create",l,function(r){p.extractFormProtectKeys(r);if(r.response.stat=="ok"){if(r.response.status=="loggedin"){if(!p.fromReg){tr("facebook_login_new_account_created_total")}document.location.href=r.response.redir}else{if(r.response.status=="loggedout"){p.hideProgress();p.fireMessage("error",r.response.message)}}}else{jq("#choosepwform .hilightError").each(function(s){jq(this).removeClass("hilightError")});var q=r.response.message;if(q.search(/Account already exists/i)!=-1){q="An account already exists with the same email address.<br/><br/>";q+='Please <a href="javascript:void(0);" onclick="LoginLBFacebookController.getInstance().handleExistingUser();return false;">login</a> or register with a different email address.';e.val(l.email);jq("#choosepwform .extra.emailext").each(function(s){jq(this).addClass("hilightError");jq(this).show()})}else{if(q.search(/gender/)!=-1){jq("#choosepwform .extra.genderext").each(function(s){jq(this).addClass("hilightError");jq(this).show()})}else{if(q.search(/birth/)!=-1){jq("#choosepwform .extra.birthdayext").each(function(s){jq(this).addClass("hilightError");jq(this).show()})}}}p.hideProgress();p.fireMessage("error",q)}},"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 k=this;var c=jq("#choosepwform #email");var h=this.activeForm.serializeArray();h.each(function(m){var n=m.name;var o=m.value;k.newUserMap[n]=o});var f={zip:jq("#zip")[0].value,country:jq("#country")[0].value,createdFromExt:this.createUserFromExtData};var l;if(this.extUserInfo.name){var d=this.extUserInfo.name.split(" ");l={first_name:d[0],last_name:d[1]}}this.newUserMap=jq.extend(this.newUserMap,f,l);var e=this.validateNewUserSubmit(this.newUserMap);if(e){document.fire(LoginLBTwitterController.EVENT.SUGGESTCLOSE);this.showProgress("Creating your account...");if(this.doFriendFinder){this.startMessageTimer()}var j={ts:this.fpTs,sig:this.fpSig};var g=jq.extend(this.extUserInfo,this.newUserMap,j);jq.post(this.serviceLoginUrl+"?mode=create",g,function(n){k.extractFormProtectKeys(n);if(n.response.stat=="ok"){if(n.response.status=="loggedin"){if(!k.fromReg){tr(k.serviceName+"_login_new_account_created_total")}if(k.isTwitterLanding){tr("twitter_landing_registration")}document.location.href=n.response.redir}else{if(n.response.status=="loggedout"){k.hideProgress();k.fireMessage("error",n.response.message)}}}else{jq("#choosepwform .hilightError").each(function(o){jq(this).removeClass("hilightError")});var m=n.response.message;if(m.search(/Account already exists/i)!=-1){m="An account already exists with the same email address.<br/><br/>";m+='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(o){jq(this).addClass("hilightError");jq(this).show()})}else{if(m.search(/gender/)!=-1){jq("#choosepwform .extra.genderext").each(function(o){jq(this).addClass("hilightError");jq(this).show()})}else{if(m.search(/birth/)!=-1){jq("#choosepwform .extra.birthdayext").each(function(o){jq(this).addClass("hilightError");jq(this).show()})}}}k.hideProgress();k.fireMessage("error",m)}},"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",s="/friendfinder/showfriends",K="/friendfinder/updatefacebookauth",A="/friendfinder/followfriends",f="/friendfinder/completeFollow/",r="/friendfinder/processInvite",N,z,w,k=false,b=null,o=6000,c=0,Z=["Busy finding friends...","Sled dogs at full speed!","Wow, some of your friends found good hiding places!  Still seeking..."],t=[],m=PBMessage.MESSAGE_TYPE,D=m.ALERT,T=m.SUCCESS,u=m.ERROR,l=0,y=0,V=[],F,Y=0;function I(){N=(k)?jq("#lightbox .container"):jq(".friendFinderContent")}function P(){if(!N){I()}N.find(".progress").remove();if(b){window.clearInterval(b);b=null}}function E(){var aa=N.find(".progress .message");if(aa&&c!==t.length){aa.html(t[c]);c++}else{c=0}}function g(ad,ab){P();var ac,aa;if(k){ac=N.prop("offsetWidth")-2;aa=N.prop("offsetHeight")-2}else{ac=N.parent().prop("offsetWidth")-2;aa=N.parent().prop("offsetHeight")-2}if(!ad){ad="We're searching for your friends who are using Photobucket."}N.prepend('<div class="progress modClrBg" style="width:'+ac+"px;height:"+aa+'px;z-index:5001;"><div class="message">'+ad+"</div></div>");if(ab){c=0;b=window.setInterval(E.bind(this),o)}}function S(ac,ad,ab){P();if(ad){var ae={type:ac,title:ad},aa=PBMessage.EVENT.NOTIFY;if(k){aa=PBLightbox.PBMessage.EVENT.NOTIFY}if(ab){ae.details=ab}document.fire(aa,{id:(k)?"":"friendFinderMessagePanel",message:new PBMessage(ae)})}else{document.fire(PBMessage.EVENT.CLOSE,{id:(k)?"":"friendFinderMessagePanel"})}}function Q(aa){if(aa.response.stat!=="ok"){if(aa.response.hasOwnProperty("loggedOut")&&aa.response.loggedOut){S(u,"You must be logged in to perform this action");P();return false}}return true}function W(aa){if(aa){jq("#friendSearch").show();jq("#inviteFriends").show();jq("#recentFollowsContainer").show()}else{jq("#friendSearch").hide();jq("#inviteFriends").hide();jq("#recentFollowsContainer").hide()}}function j(){var aa=jq("#invitation");if(aa&&aa.length>0){if(typeof"PBInvite"!=="undefined"){PBInvite.init()}}}function O(aa,ab,ac){document.fire(PBMessage.EVENT.CLOSE);jq.ajax({url:aa,dataType:"json",data:ab,success:ac,type:"post"})}function d(ae){if(!Q(ae)){return}AutoShareController.getInstance().unsetFindingFriends();var aa,ab=ae.response,ad,ac;if(ab.stat==="ok"){if(ab.hasOwnProperty("reconnect")&&ab.reconnect){P();AutoShareController.getInstance().setFindingFriends();W(true);S(D,ab.message.title,ab.message.details);return}if(ab.hasOwnProperty("redirect")&&ab.redirect){ac="http://"+location.host;if(w){ac+=w}else{ac+="/friendfinder"}if(ab.params){ac+=(ac.indexOf("?")===-1?"?":"&")+ab.params}location.href=ac;return}N.html(ab.innerHTML);ad=N.find("div.friendresults");if(!ad||ad.length===0){W(true)}aa=T}else{aa=u}S(aa,ab.message,ab.messageDetails)}function X(ac,ab){var aa="";if(ab){aa=ab+" "}aa+=(ac==="auth"?"friends":"contacts");t.splice(0,0,"When we're done, you'll be able to choose specific "+aa+" to follow on Photobucket");return"We're searching for your "+aa+" who are using Photobucket."}function q(ac,ab,aa){FB.login(function(ad){if(ad.authResponse){g(X("auth",aa),true);O(K,{},function(){M(ac,ab,aa)})}else{W(true);S(u,"You must allow Photobucket to access your Facebook account.")}},{scope:"publish_stream,offline_access"})}function M(ae,ad,ab){l=0;y=0;t=Z.slice(0);document.fire(PBMessage.EVENT.CLOSE);var ac,aa;I();ac={findingId:ae,findingType:"auth"};if(ab==="Facebook"){FB.getLoginStatus(function(af){if(af.authResponse){if(af.authResponse.userID===ad){FB.api("/me/permissions",function(ah){var ag=ah.data[0];if(ag.offline_access!==1||ag.publish_stream!==1){q(ae,ad,ab)}else{W(false);aa=N.find(".progress");if(!aa||aa.length===0){g(X("auth","Facebook"),true)}O(e,ac,d)}})}else{FB.logout(function(){q(ae,ad,ab)})}}else{q(ae,ad,ab)}},true)}else{W(false);g(X("auth",ab),true);O(e,ac,d)}}function h(aa,ab){l=0;y=0;t=Z.slice(0);document.fire(PBMessage.EVENT.CLOSE);I();var ac={findingId:aa,findingType:"contact"};W(false);g(X("contact",ab),true);O(s,ac,d)}function C(ac){var ad,aa,ab=ac.response;if(!Q(ac)){return}if(k){if(ab.stat!=="ok"){ad="There was a problem following your friends.  Please try again.";S(u,ad);return}else{document.fire(z.EVENT.SKIPFRIENDFINDER);S(T,ab.message,ab.messageDetails)}}else{if(ab.stat!=="ok"){ad="There was a problem following your friends.  Please try again.";S(u,ad)}else{N.html(ab.innerHTML);W(true);if(ab.hasOwnProperty("noAction")&&ab.noAction){aa=m.ALERT}else{aa=T}S(aa,ab.message,ab.messageDetails);if(ab.recentFollows){jq("#recentFollowsContainer").remove();jq("div.panelRight").append(ab.recentFollows)}}}P()}function L(){I();var aa=jq("#followFriendsForm"),ai=aa.find("input[name=findingId]").val(),ak=aa.find("input[name=findingType]").val(),ah=aa.find("div.friend input[type=checkbox]"),ae={},al=[],ac,ag,aj,ad,ab={},af={};ah.each(function(){aj=this.id.replace(/^follow_/,"");ad=jq(this).next("input[type=hidden][name^=findingId_]").val();if(this.checked){if(!ae.hasOwnProperty(ad)){ae[ad]=[]}ae[ad].push(aj)}else{al.push(aj)}});ag=jq(ae)[0];if(jq.isEmptyObject(ag)){ac="Please select at least one friend to follow";S(u,ac)}else{jq.each(ae,function(an,am){ab[an]=am.join(",")});af.userIds=ab;if(al){af.unfollowedUserIds=al.join(",")}if(ai){af.findingId=ai}if(ak){af.findingType=ak}if(w){af.returnUrl=w}ac="Following your "+(ak==="auth"?"friends":"contacts")+"...";g(ac);O(A,af,C)}}function J(){Y--;if(Y===0){jq("#followAll").prop("disabled",false);jq("div.friend a.followButton").unbind("followComplete unfollowComplete",J)}}function p(){var ac,ab=0,aa;jq("#followAll").prop("disabled",true);if(jq("#followAll").prop("checked")){ac=jq("div.friend a.followButton[data-followee]:not(.isFollowing)");aa="friend_finder_follow_all_click";ac.bind("followComplete",J)}else{ac=jq("div.friend a.followButton.isFollowing");aa="friend_finder_unfollow_all_click";ac.bind("unfollowComplete",J)}Y=ac.length;ac.click();tr(aa)}function B(){var ab=jq("#followFriendsForm"),aa=ab.find("input[name=findingId]").val(),ad=ab.find("input[name=findingType]").val(),ac={findingId:aa,findingType:ad,followedCount:y,invitedCount:l};if(w){ac.returnUrl=w}O(f,ac,C)}function x(ac,ab){if(!Q(ac)){return}var aa=ac.response;if(aa.stat==="ok"){jq("#invite_"+ab).closest("div.friend").fadeOut(2000,function(){jq(this).remove()});l+=1}else{S(u,aa.message);jq("#invite_"+ab).text("Invite").removeClass("invited").attr("onclick",'FriendFinder.sendInviteTo("'+ab+'");')}}function a(aa){I();var ad=jq("#followFriendsForm"),ab=ad.find("input[name=findingId]").val(),af=ad.find("input[name=findingType]").val(),ac=jq("#invite_"+aa),ae={toAddresses:ac.data("email"),findingId:ab,findingType:af};ac.attr("onclick","").addClass("invited").text("Sending...");O(r,ae,function(ag){x(ag,aa)})}function H(ac){if(!Q(ac)){return}var aa=ac.response,ab;if(aa.stat==="ok"){ab="http://"+location.host;if(w){ab+=w}else{ab+="/friendfinder"}if(aa.params){ab+=(ab.indexOf("?")===-1?"?":"&")+aa.params}location.href=ab}else{S(u,aa.message)}}function R(){I();var ab=jq("#followFriendsForm"),ad=ab.find("input[name=toAddresses]"),aa="",ac={};if(!ad.hasClass("hint")){aa=ad.val()}ac.toAddresses=aa;g("Inviting your friends...");O(r,ac,H)}function v(ab){var aa="div.friend input[type=checkbox]";if(ab){aa+=":not(:checked)"}else{aa+=":checked"}jq("div.friend input[type=checkbox]").each(function(){this.checked=ab})}function n(ab,aa){k=ab;z=aa}function G(aa){w=aa}function U(){document.fire(PBLightbox.EVENT.ACTIVATE,{contentUrl:"/friendfinder/invite?isLightbox=true",cache:false})}jq(document).ready(function(){jq("a.followButton").live("followComplete",function(){y+=1;if(jq("div.friendresults").data("site")==="Facebook"){V.push(jq(this).closest("div.friend").find("label").text());if(!F){F=jq("#followFriendsForm").find("input[name=findingId]").val()}}}).live("unfollowComplete",function(){y-=1;if(jq("div.friendresults").data("site")==="Facebook"){var aa=jq(this).closest("div.friend").find("label").text(),ab;for(ab=0;ab<V.length;ab++){if(V[ab]===aa){V.splice(ab,1);break}}}})});jq(window).unload(function(){if(V.length>0){var aa={findingId:F,findingType:"auth",friends:V};O("/friendfinder/postFollows",aa,function(){})}});return{getFriends:M,getFriendsFromContacts:h,followFriends:L,sendInvite:R,setIsLightBox:n,setPage:G,removeProgress:P,toggleSelected:v,completeFollow:B,followAllFriends:p,sendInviteTo:a,showInvitePreview:U}}());var TellmemoreGallery={selector:"#homepageGallery",setSelector:function(a){this.selector=a},handleMore:function(c,a){jq(this.selector).toggleClass("moreOpen");var b=jq("#galleryFooter");if(b.length>0){b.toggleClass("moreOpen")}jq("#tellMore").slideToggle("normal");jq(this.selector+" .showmore").hide();jq(this.selector+" .showless").show();if(typeof a!=="undefined"){tr(a+"_tell_me_more_click")}else{tr("homepage_tell_me_more_click")}},handleLess:function(){jq("#tellMore").slideToggle("normal",jq.proxy(function(){var a=jq("#galleryFooter");if(a.length>0){a.toggleClass("moreOpen")}jq(this.selector).toggleClass("moreOpen")},this));jq(this.selector+" .showless").hide();jq(this.selector+" .showmore").show()}};var GallerySlideshow={ptr:0,slides:null,buttons:null,showInt:null,sliding:false,afterIdx:-1,delay:6000,topz:10,middlez:9,bottomz:8,EVENT:{SWITCH:"GallerySlideshow:SWITCH"},init:function(a){this.slides=jq("#slideshow div.slide");this.buttons=jq("#slideshow div.buttons .control-button");if(this.slides.length>1){if(a.delay){this.delay=a.delay}this.lazyLoad(function(){this.go();Event.observe(document,GallerySlideshow.EVENT.SWITCH,this.switchSlide.bindAsEventListener(this))});Event.observe(document,"pb:homepage_stop",this.stop.bindAsEventListener(this))}},go:function(){this.showInt=setInterval(jq.proxy(function(){this.sliding=true;this.getActive().addClass("last-active");jq(this.buttons[this.ptr]).removeClass("active");this.getNext().css({opacity:0});this.getNext().addClass("active");var a=1000;this.getNext().animate({opacity:1},a,jq.proxy(function(){this.getActive().removeClass("active last-active");this.getActive().css({opacity:0});track="homepage_promo_"+this.getNext().find(".promo_title").html()+"_impression";track=track.replace(/<[^>]*>/g,"");tr(track);this.ptr=(this.ptr+1)%this.slides.length;jq(this.buttons[this.ptr]).addClass("active");this.sliding=false;if(this.afterIdx>=0){if(this.afterIdx!=this.ptr){this.doSwitch(this.afterIdx)}else{this.afterIdx=-1}}},this))},this),this.delay)},getNext:function(){return jq(this.slides[(this.ptr+1)%this.slides.length])},getActive:function(){return jq(this.slides[this.ptr])},switchSlide:function(b){var a=b.memo.index;if(this.sliding){this.afterIdx=a}else{this.doSwitch(a)}},doSwitch:function(a){if(a!=="undefined"&&a<this.slides.length&&a!=this.ptr){if(this.showInt!=null){clearInterval(this.showInt)}this.slides.removeClass("active");this.buttons.removeClass("active");this.slides.removeClass("last-active");this.ptr=a;this.afterIdx=-1;this.getActive().addClass("active");this.getActive().css({opacity:1});jq(this.buttons[this.ptr]).addClass("active");track="homepage_promo_"+this.getActive().find(".promo_title").html()+"_impression";track=track.replace(/<[^>]*>/g,"");tr(track);this.go()}},stop:function(){if(this.showInt!=null){clearInterval(this.showInt);this.showInt=null}},lazyLoad:function(a){this.slides.each(function(){if(typeof jq(this).attr("lazyload")!=="undefined"){jq(this).css({"background-image":"url("+jq(this).attr("lazyload")+")"})}if(photobucket.browser.isIE9){jq(this).css({filter:"alpha(opacity=0)"})}});img=new Image();Event.observe(img,"load",a.bind(this));img.src=this.slides.last().attr("lazyload")}};var UploadCounter={digits:null,value:0,inc:0,pace:0,counterInt:null,init:function(a){jq.extend(this,a);this.digits=jq("#uploadCounter .digit");this.counterInt=setInterval(jq.proxy(function(){this.value+=this.inc;this.roll(this.value)},this),this.pace);Event.observe(document,"pb:homepage_stop",this.stop.bindAsEventListener(this))},roll:function(e){var c=this.addCommas(e);this.update(c);if(e&&e!=0){for(i=c.length-1;i>=0;i--){var d=jq("#uploadCounter #num"+i);var b=c.charAt(i);if(d.val!=b){d.val(b);if(b==","){d.animate({top:"-240px"},1500)}else{var a=Number(b)*-24;d.animate({top:a+"px"},1500)}}}}},addCommas:function(b){b=String(b);var a=/(\d+)(\d{3})/;while(a.test(b)){b=b.replace(a,"$1,$2")}return b},update:function(b){var a=b.length-this.digits.length;if(a>0){for(i=1;i<=a;i++){jq("#uploadCounter").append('<div class="digit" id="num'+(this.digits.length+i-1)+'">&nbsp;</div>')}this.digits=jq("#uploadCounter .digit")}},stop:function(){if(this.counterInt!=null){clearInterval(this.counterInt);this.counterInt=null}}};
