myDeco.auth={init:function(){this.activateAuthBlocks();this.checkAuth()},isCurrentUser:function(){return !Object.isUndefined(myDeco.username)&&!Object.isUndefined(myDeco.ownername)&&myDeco.username==myDeco.ownername},activateAuthBlocks:function(){if(this.isCurrentUser()){$$(".authorized").invoke("show")}else{$$(".unauthorized").invoke("show")}},checkAuth:function(){var c=$$(".logout-info"),a=$$(".login-info"),b=$$(".user-rating-form fieldset:first");if(myDeco.username){a.invoke("show");if(b.length==0){return}b._each(function(d){var e=d.down("textarea");if(e.getValue()){d.down(".login-info").hide()}d.observe("click",function(f){d.down(".login-info").hide();e.focus()})})}else{redirect_to_login=function(d){d.stop();document.location=document.body.down(".review-login-link").href};$$(".user-rating-form").invoke("observe","sumbit",redirect_to_login);c.invoke("show")}}};addLoadEvent(myDeco.auth.init.bind(myDeco.auth));myDeco.closable={_effect:Effect.Fade,_effectOptions:{duration:0.5},_observers:{close:null,toggle:null,beforeClose:null},init:function(b){var c=Object.isElement(b)?[b]:$$(".closable"),a=this;if(!this._observers.close){this._observers.close=this._close.bindAsEventListener(this);this._observers.toggle=this._toggle.bindAsEventListener(this)}c._each(function(f){f=$(f);var e=!f.hasClassName("no-hide");var d=f.down("a.close-square");if(Object.isUndefined(d)){d=new Element("a",{href:"#"});if(e){d.hide()}f.insert(d.addClassName("close-square"))}if(e){f.observe("mouseover",a._observers.toggle).observe("mouseout",a._observers.toggle)}d.observe("click",a._observers.close)})},setObservers:function(a){if(typeof a!=="object"&&!Object.isHash(a)){return}var b=this;if(Object.isFunction(a.beforeClose)){b._observers.beforeClose=a.beforeClose}},_toggle:function(a){var b=a.element();if(!b.hasClassName("closable")){b=b.up(".closable")}if(!b){return}a.type=="mouseover"?b.down("a.close-square").show():b.down("a.close-square").hide()},_close:function(c){c.stop();var b=c.findElement("a");var a=b.up(".closable");if(this._observers.beforeClose&&this._observers.beforeClose(a,this)===false){return}this.close(a)},close:function(b){var a=Object.extend({afterFinish:function(c){c.element.remove()}},this._effectOptions);this._effect(b,a)}};addLoadEvent(myDeco.closable.init.bind(myDeco.closable));myDeco.tabs={};myDeco.tabs.Tab=function(a,b){this._dom=a;this._link=a.down(".cmslink");this._container=$(a.id+"-container");this.isActive=a.hasClassName("active");this._switcherId="";this.prev=null;this.next=null;this._preActivateCallback=b};myDeco.tabs.Tab.prototype={activate:function(a){if(this.isActive){return}this._dom.addClassName("active");if(!a){this._container.show()}else{new Effect.Appear(this._container,{duration:0.4,queue:{scope:this._switcherId,position:"end"}})}this.isActive=true},deactivate:function(a){if(!this.isActive){return}this._dom.removeClassName("active");if(!a){this._container.hide()}else{Effect.Queues.get(this._switcherId).each(function(b){b.cancel()});new Effect.Fade(this._container,{duration:0.1,queue:{scope:this._switcherId}})}this.isActive=false},getId:function(){return this._dom.identify()},attachHandlers:function(a,b,c){this._link.observe("click",function(f){f.stop();if(this.isActive){return}if(a){window.clearInterval(a)}this._preActivateCallback(this);this.activate(b);for(var d=0;d<c.length;d++){c[d](this)}}.bind(this));if(a){this._container.observe("mouseover",function(d){window.clearInterval(a)})}},setContent:function(a){this._container.innerHTML=a},hasContent:function(){return !this._container.innerHTML.blank()},getLink:function(){return this._link},getContainer:function(){return this._container}};myDeco.tabs.TabSwitcher=function(c,b){var a=this;this._options={use_effects:true,period:7000,endless:false,auto_switch:true};this._options=Object.extend(this._options,b);this._dom=c;this._firstTab=null;this.activeTab=null;this._navigationLinks=null;this._interval=null;if(this._options.auto_switch){this._interval=window.setInterval(this.activateNext.bind(this),this._options.period)}this._navigationLinks=this._dom.select(".tabs-navigation");this._navigationLinks.invoke("observe","click",function(h){var g=Event.findElement(h,".tabs-navigation");Event.stop(h);a._navigationLinks.invoke("removeClassName","disabled");var f=!(g.hasClassName("prev-link")?a.activatePrev():a.activateNext());if(f){g.addClassName("disabled")}});this._callbacks=[];var d=null;this._dom.select(".tab:not(.inactive)")._each(function(f){var e=new myDeco.tabs.Tab(f,function(g){a.activeTab.deactivate(a._options.use_effects);a.activeTab=g});e.attachHandlers(a._interval,a._options.use_effects,a._callbacks);e._switcherId=a.getId();if(e.isActive){a.activeTab=e}e.prev=d;if(d){d.next=e}d=e;if(!a._firstTab){a._firstTab=e}})};myDeco.tabs.TabSwitcher.prototype={activateNext:function(){if(!this._firstTab){return false}var a=true;var b=this.activeTab;if(!b.next){if(!this._options.endless){a=false;window.clearInterval(this._interval)}else{b=this._firstTab}}else{b=this.activeTab.next}if(a){this.activeTab.deactivate(this._options.use_effects);b.activate(this._options.use_effects);this.activeTab=b}return a&&b.next},activatePrev:function(){if(!this._firstTab){return false}var a=true;var b=this.activeTab;if(!b.prev){a=false;window.clearInterval(this._interval)}else{b=this.activeTab.prev}if(a){this.activeTab.deactivate(this._options.use_effects);b.activate(this._options.use_effects);this.activeTab=b}return a&&b.prev},getId:function(){return this._dom.identify()},getTabById:function(b){var a=this._firstTab;while(a){if(a.getId()==b){return a}a=a.next}return null},switchTabById:function(b){var a=this.getTabById(b);if(!a||b==this.activeTab.getId()){return}this.activeTab.deactivate(this._options.use_effects);a.activate(this._options.use_effects);this.activeTab=a},addCallback:function(a){if(a instanceof Function){this._callbacks.push(a)}}};myDeco.tabs.tabSwitcherCollection={switchers:[],init:function(b,a){if(myDeco.tabs.tabSwitcherCollection.switchers.length&&!a){return}$$(".tab-switcher")._each(function(d){var c={use_effects:!d.hasClassName("noeffect"),endless:d.hasClassName("endless"),auto_switch:!d.hasClassName("no-auto-switch")};myDeco.tabs.tabSwitcherCollection.switchers.push(new myDeco.tabs.TabSwitcher(d,c))})},getSwitcherById:function(a){if(!myDeco.tabs.tabSwitcherCollection.switchers.length){myDeco.tabs.tabSwitcherCollection.init()}return myDeco.tabs.tabSwitcherCollection.switchers.find(function(b){return b.getId()==a})}};addLoadEvent(myDeco.tabs.tabSwitcherCollection.init);myDeco.bubbles={init:function(){$$(".bubble")._each(function(a){a.appendChild(Builder.node("div",{className:"bubble-tip"}))})},create:function(b){var a=Builder.node("div",{className:"bubble"},[Builder.node("div",{className:"rounded"},[Builder.node("p",[b])]),Builder.node("div",{className:"bubble-tip"})]);Effect.Appear(a);return a}};addLoadEvent(myDeco.bubbles.init);myDeco.formValidation={init:function(){$$("form.validate:not(.popup-form):not(.inline-form)")._each(function(a){Event.observe(a,"submit",function(b){if(!myDeco.formValidation.validate(a).valid){b.stop();myDeco.formControls.submitButtons.enable(a)}})})},validate:function(a){var c=false;var b=new Array();a.select(".validate")._each(function(e){var f=myDeco.formValidation.isValid(e);if(f===true){if(e.bubble instanceof Object){e.bubble.remove();e.bubble=""}}else{c=true;var d=myDeco.bubbles.create(f);if(e.hasClassName("right")){d.addClassName("bubble-right");d.setStyle({right:e.getWidth()+15+"px",top:"2px"})}else{d.setStyle({left:e.getWidth()+20+"px",top:"2px"})}e.insert({after:d});if(myDeco.browser.isIE6){d.appendChild(document.createTextNode(" "))}e.bubble=d}});return{valid:!c}},isValid:function(d){if(d.hasClassName("v-required")&&d.value==""){return"Please ensure each field is complete before you re-submit."}if(d.hasClassName("v-required-inbox")&&d.value==""){return"Oops! You forgot your message!"}if(d.hasClassName("v-email")&&!myDeco.formValidation.validateEmail(d.value)){return"We'd love you to bend the rules in room design, but not in our forms! Sorry, our system doesn't recognise your email address. Please check and try again."}if(d.hasClassName("v-password")&&!myDeco.formValidation.validatePassword(d.value)){return"Passwords must be 5-15 characters and may contain numbers, letters and underscores."}if(d.hasClassName("v-passwordconfirm")&&!myDeco.formValidation.validatePasswordConfirm(d.value)){return"Your passwords must match."}if(d.hasClassName("v-date")&&!myDeco.formValidation.validateDate(d.value)){return"Must be a valid date of the form dd/mm/yyyy. Eg: 19/09/2007"}if(d.hasClassName("v-url")&&!myDeco.formValidation.validateUrl(d.value)){return"Please enter a valid url."}var c="v-word-length-",b=d.className.indexOf(c);if(b!=-1){var e=d.className.indexOf(" ",b);if(e==-1){e=d.className.length}var a=d.className.substr(b+c.length,e);if(!myDeco.formValidation.validateWordLength(d.value,parseInt(a))){return"Oops! Please make sure words in your comment do not exceed "+a+" characters in length."}}if(d.hasClassName("v-no-html")&&!myDeco.formValidation.validateNoHTML(d.value)){return"Should not contain any HTML-like tags"}return true},validateEmail:function(a){return/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/.test(a)},validatePassword:function(a){return/^[a-zA-Z]\w{3,14}$/.test(a)},validatePasswordConfirm:function(a){var b=($("sign-up-password1")!=null)?"sign-up-password1":"id_password1";return $(b).value==a},validateDate:function(a){return/(((0[13578]|10|12)([-.\/])(0[1-9]|[12][0-9]|3[01])([-.\/])(\d{4}))|((0[469]|11)([-.\/])([0][1-9]|[12][0-9]|30)([-.\/])(\d{4}))|((2)([-.\/])(0[1-9]|1[0-9]|2[0-8])([-.\/])(\d{4}))|((2)(\.|-|\/)(29)([-.\/])([02468][048]00))|((2)([-.\/])(29)([-.\/])([13579][26]00))|((2)([-.\/])(29)([-.\/])([0-9][0-9][0][48]))|((2)([-.\/])(29)([-.\/])([0-9][0-9][2468][048]))|((2)([-.\/])(29)([-.\/])([0-9][0-9][13579][26])))/.test(a)},validateUrl:function(a){return/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(a)},validateWordLength:function(b,a){var d=b.split(" ");for(var c=0;c<d.length;c++){if(d[c].length>a){return false}}return true},validateNoHTML:function(a){return !/<[a-zA-Z]+(\s[^>]*)?>/.test(a)}};addLoadEvent(myDeco.formValidation.init);myDeco.projectList={_observers:{remove:null,edit:null,save:null,cancel:null,toggle:null,beforeDelete:null,afterDelete:null,beforeInsert:null,afterInsert:null},_nth:3,_inited:false,init:function(b){if(this._inited&&!Object.isElement(b)){return}this._inited=true;if(!Object.isFunction(this._observers.remove)){this._observers={remove:this.remove.bindAsEventListener(this),edit:this._edit.bindAsEventListener(this),save:this._save.bindAsEventListener(this),cancel:this._cancel.bindAsEventListener(this),toggle:this._toggle.bindAsEventListener(this)}}var a=this;(Object.isElement(b)?$A([b]):$$(".project-list"))._each(function(c){a._insertDividers(c);a._setLocalObservers(c)})},setObservers:function(c){this.init();if(typeof c!=="object"&&!Object.isHash(c)){return}var a=this,d=$A(["beforeDelete","afterDelete","beforeInsert","afterInsert"]);for(var b in c){if(d.include(b)&&Object.isFunction(c[b])){a._observers[b]=c[b]}}},holder:function(a){this.init();return a.up(".project-list")},nodes:function(a){this.init();return a.down("ul").select(".project-list-item")},_setLocalObservers:function(b){var a=this;(b.hasClassName("project-list")?b.select(".project-list-item"):$A([b]))._each(function(c){c.select(".photo .controls")._each(function(d){d.up(".photo").observe("mouseover",a._observers.toggle).observe("mouseout",a._observers.toggle)});c.select("a.delete, a.remove").invoke("observe","click",a._observers.remove);c.select("form a.name").invoke("observe","click",a._observers.edit);c.select("form a.save").invoke("observe","click",a._observers.save);c.select("form a.cancel").invoke("observe","click",a._observers.cancel)})},_toggle:function(c){var b=c.element();if(!b.hasClassName("photo")){b=b.up(".photo")}var a=b.down(".controls");if(!a){return}c.type=="mouseover"?a.show():a.hide()},_edit:function(c){c.stop();var b=c.element().up("FORM"),d=b.down(".name-edit"),a=b.down("textarea");c.findElement("A").toggle();d.toggle()},_save:function(b){b.stop();var a=b.element().up("FORM");new Ajax.Request(a.action,{parameters:a.serialize(),onComplete:function(f){try{var c=f.responseText.evalJSON()}catch(d){this._cancel(b);return}a.down("a.name span").update(c.href);a.down("div.name textarea").value=c.textarea;this._cancel(b)}})},_cancel:function(b){b.stop();var a=b.element().up("FORM");a.down(".name-edit").toggle();a.down("a.name").toggle()},remove:function(b){this.init();var a;if(!Object.isElement(b)){b.stop();a=b.element().up(".project-list-item")}else{a=b}if(this._observers.beforeDelete&&this._observers.beforeDelete(a,this)===false){return}this._removeProjectListItem(a);if(this._observers.afterDelete){this._observers.afterDelete(this)}},insert:function(g,c,a){this.init();if(this._observers.beforeInsert&&this._observers.beforeInsert(this)===false){return}var f=g.select(".project-list-item");if(!Object.isNumber(a)||f.length<a){a=f.length}a=Math.max(f.length+a,0);this._removeDividers(g);var e=f[a],d,b=g.down("ul");if(!e){b.insert(c);d=b.childElements().last()}else{e.insert({before:c});d=b.childElements()[a]}this._setLocalObservers(d);this._insertDividers(g);if(this._observers.afterInsert){this._observers.afterInsert(d,this)}return d},_removeProjectListItem:function(a){var b=this.holder(a);this._removeDividers(b);a.replace("");this._insertDividers(b)},_removeDividers:function(a){if(a.hasClassName("no-dividers")){return}a.select(".project-list-divider").invoke("remove")},_insertDividers:function(b){if(b.hasClassName("no-dividers")){return}if(b.select(".project-list-divider").length>0){return}var a=b.down("ul").childElements().length;b.select(".project-list-item:nth-child("+this._nth+"n)")._each(function(c){c.insert({after:new Element("li").addClassName("project-list-divider")})});if((a%this._nth)!=0){b.select(".project-list-item").last().insert({after:new Element("li").addClassName("project-list-divider")})}}};addLoadEvent(myDeco.projectList.init.bind(myDeco.projectList));myDeco.fileInputs={_observers:{update:null,keystrokes:null},init:function(c){if(this._observers.update==null){this._observers={update:this.update.bindAsEventListener(this),keystrokes:this.getKeyStrokes.bindAsEventListener(this)}}var b=Object.isElement(c)?c.select(".fileinputs > input"):$$(".fileinputs > input"),a=this;b._each(function(f){f.addClassName("file");var e=f.up(".fileinputs");var g=e.select("input.text").first();if(Object.isUndefined(g)){g=Builder.node("input",{className:"text",type:"text"})}var d=e.select("div.fakefile").first();if(Object.isUndefined(d)){d=Builder.node("div",{className:"fakefile"},[Builder.node("div",{className:"field"},g),Builder.node("a",{className:"button"},Builder.node("span",{className:"inner"},"Browse"))]);f.up().insert(d)}f.textInput=g;f.observe("change",a._observers.update);f.observe("keypress",a._observers.keystrokes)})},getKeyStrokes:function(c){var a=c.element();var b=(window.event)?window.event:c;if(b.keyCode==8){a.textInput.value=a.textInput.value.substring(0,a.textInput.value.length-1)}else{a.textInput.value=a.value+String.fromCharCode(b.charCode)}},update:function(b){var a=b.element();a.textInput.value=a.value}};addLoadEvent(myDeco.fileInputs.init.bind(myDeco.fileInputs));myDeco.editable={_inited:false,_observers:{edit:null,save:null,cancel:null},init:function(){if(this._inited){return}this._inited=true;if(!Object.isFunction(this._observers.edit)){this._observers.edit=this._edit.bindAsEventListener(this);this._observers.save=this._save.bindAsEventListener(this);this._observers.cancel=this._cancel.bindAsEventListener(this)}var a=this;$$("a.editable span")._each(function(b){b.observe("click",a._observers.edit);b.up("form").observe("submit",a._observers.save)});$$("div.editable a.cancel").invoke("observe","click",this._observers.cancel)},_edit:function(d){d.stop();var e=d.findElement("form").down("div.editable");if(e){var c=e.down("textarea, input"),b=c.getAttribute("maxlength"),a=e.down(".character-count");c.oldValue=c.getValue();d.findElement("A").toggle();if(a&&b){b=parseInt(b);a.update(b-c.getValue().length)}e.toggle();c.focus()}},_cancel:function(d){d.stop();var c=d.findElement("FORM"),e=c.down("div.editable"),a=e.down("textarea, input"),b=c.down(".error");if(b){b.hide()}a.value=a.oldValue;a.oldValue="";e.toggle();c.down("a.editable").toggle()},_save:function(d){d.stop();var c=d.element(),e=c.down("textarea, input"),b=c.down(".error"),a=e&&!myDeco.formValidation.validateNoHTML(e.getValue());if(a&&b){b.update("Should not contain any HTML-like tags").show();return}new Ajax.Request(c.action,{parameters:c.serialize(),onComplete:function(j){try{var g=j.responseText.evalJSON()}catch(h){g={}}var i=c.select("a.editable span").first(),f=c.select("div.editable textarea,div.editable input").first();if(!g.textarea){g.textarea=f.getValue()}if(!g.href){g.href=g.textarea}i.update(g.href).removeClassName("empty");f.value=g.textarea;c.down("div.editable").toggle();c.down("a.editable").toggle()}})}};addLoadEvent(myDeco.editable.init.bind(myDeco.editable));myDeco.followers={init:function(b){if(!Object.isElement(b)){b=$("body")}if(!myDeco.username){b.select(".follow-switcher").invoke("hide");return}b.select(".follow-switcher a.follow").invoke("observe","click",this.follow.bindAsEventListener(this));b.select(".follow-switcher a.following").invoke("observe","click",this.unfollow.bindAsEventListener(this));var a=this,c=$A([]);b.select(".follower-"+myDeco.userid).invoke("hide");b.select(".follow-switcher")._each(function(f){var d=a._extractUserID(f.className);if(d!=myDeco.userid){c.push(d)}});if(c.length>0){new Ajax.Request(myDeco.urls.friendFollow,{parameters:c.uniq().map(function(d){return"id="+d}).join("&")+"&_nc="+new Date().valueOf(),method:"get",onSuccess:function(f){try{var d=f.responseText.evalJSON()}catch(g){return}if(d.success==true){c._each(function(h){var e=".follower-"+h;if(d.followed_users.include(h)){b.select(e+" .following").invoke("show");b.select(e+" .follow").invoke("hide")}else{b.select(e+" .following").invoke("hide");b.select(e+" .follow").invoke("show")}})}}})}},follow:function(a){this._setState(a,true)},unfollow:function(a){this._setState(a,false)},_setState:function(b,c){var a=b.findElement("a");if(a&&a.hasClassName("no-change")){return}b.stop();if(!myDeco.username){document.location=myDeco.urls.userLogin+"?next="+document.location;return}var d=this._extractUserID(b.element().up(".follow-switcher").className);new Ajax.Request(myDeco.urls.friendFollow,{parameters:{id:d,action:(c?"follow":"delete")},method:"post",onSuccess:function(g){try{var f=g.responseText.evalJSON()}catch(h){return}if(f.success==true){$$(".follower-"+d+" .follow").invoke(c?"hide":"show");$$(".follower-"+d+" .following").invoke(c?"show":"hide")}}})},_extractUserID:function(a){return a.match(/follower\-(\d+)/)[1]}};addLoadEvent(myDeco.followers.init.bind(myDeco.followers));var addthis_config={username:"AlexZv"},addthis_url=location.href,addthis_title=document.title;myDeco.sharethis={init:function(){var a=$$(".addthis-link");a.invoke("observe","mouseover",function(){return addthis_open(this,"")});a.invoke("observe","mouseout",function(){addthis_close()});a.invoke("observe","click",function(b){b.stop();return addthis_sendto()})}};addLoadEvent(myDeco.sharethis.init);myDeco.happySadBar={_observers:{vote:null},init:function(){if(this._observers.vote==null){this._observers.vote=this.vote.bindAsEventListener(this)}var b={},a=this;$$("div.happy-sad-bar")._each(function(c){b[c.identify()]={ctype:c.down("input[name=content_type]").getValue(),object_id:c.down("input[name=object_id]").getValue(),rate_type:"rating"}});if(Object.keys(b).length==0){return}new Ajax.Request(myDeco.urls.canRateMulti,{parameters:{ratings:$H(b).toJSON()},onSuccess:function(c){try{b=c.responseText.evalJSON()}catch(g){return}if(!b.success){return}b=b.ratings;for(var d in b){var f=$(d);if(!b[d].canRate){f.down().addClassName("voted").select(".buttons a.button").invoke("addClassName","disabled")}f.select("a.button").invoke("observe","click",a._observers.vote)}}})},vote:function(e){e.stop();var b=e.findElement("a");if(b.hasClassName("disabled")){return}var f=b.up(".happy-sad-bar"),d=f.down("form"),a=d.down(".like_count"),c=d.down(".dislike_count"),h=parseInt(a.innerHTML),g=parseInt(c.innerHTML);if(b.hasClassName("smiley")){h++;a.update(h);d.down(".v").value="1"}else{g++;c.update(g);d.down(".v").value="-1"}new Ajax.Request(myDeco.urls.setScore,{parameters:d.serialize(),onComplete:function(j){try{var i=j.responseText.evalJSON()}catch(m){}if(!i.error){var l=h+g,k=(h*100/l).round();f.down(".loved").setStyle({width:k+"%"});f.down(".percentage").update(k+"% loved");f.down(".votes").update(l+" vote"+(l!=1?"s":""))}f.select("a.button").invoke("addClassName","disabled");f.down().addClassName("has_votes").addClassName("voted")}})}};addLoadEvent(myDeco.happySadBar.init.bind(myDeco.happySadBar));myDeco.sidebarMenu={activeClass:"active",paneHiddenClass:"hidden",init:function(a){(a?a.select(".sidebar-menu li"):$$(".sidebar-menu input")).invoke("observe","click",this.menuTab.bindAsEventListener(this))},menuTab:function(g){if(g&&g.element().tagName=="A"){g.stop()}var b=this,d=g.findElement("li"),f=d.down("input"),h=d.up(".sidebar-menu"),a=h.down("li."+this.activeClass),c=a?a.down("input"):false;if(d==a){return}if(a){a.removeClassName(this.activeClass);c.checked=false;a.up(".sidebar-menu-root").select("."+c.value).invoke("addClassName",this.paneHiddenClass)}d.addClassName(this.activeClass);f.checked=true;d.up(".sidebar-menu-root").select("."+f.value).invoke("removeClassName",this.paneHiddenClass);if(myDeco.popin&&myDeco.popin.isOpen()){myDeco.popin._resize()}}};myDeco.profile={photoDestination:null,isEditProfile:false,init:function(){this.isEditProfile=$$(".edit-profile").length;this.updateNavigation();myDeco.closable.setObservers({beforeClose:this.closableObserver.bind(this)});myDeco.projectList.setObservers({beforeDelete:this.projectListDeleteObserver.bind(this)});$$(".profile-add-image").invoke("observe","click",this.addScrapbookPhotoPopin.bindAsEventListener(this));$$(".room-photo-upload").invoke("observe","click",this.addRoomPhoto.bindAsEventListener(this));this.setAlertsObservers();var b=$("profile-create-showcase");if(b){b.observe("click",function(i){var h=$("profile-designer-showcase");if(h){i.element().up("li").removeClassName("section");i.findElement("A").hide();h.show()}i.stop()})}$$(".email-wishlist-popin-creator").invoke("observe","click",this.wishlistPopin.bindAsEventListener(this));$$("#profile-survey a.button").invoke("observe","click",this.surveySubmit.bindAsEventListener(this));$$(".autopost input[type=checkbox]").invoke("observe","change",this.setSectionVisibility.bindAsEventListener(this));$$(".autopost select").invoke("observe","change",this.setObjectsPerSection.bindAsEventListener(this));if($("messages-search-select")){new Autocompleter.SelectBox("messages-search-select",{onShow:myDeco.menu.onShow})}if(document.location.hash=="#room-photos"){$("profile-photos-list-holder").scrollTo();this.addRoomPhoto()}var d=$("profile-rooms-order-select");if(d){d.observe("change",this.roomsChangeOrder.bindAsEventListener(this))}this.setPaginateObserver(true);var e=$("add-scrapbook-photo-creator");if(e){e.observe("click",this.addScrapbookPhotoPopin.bindAsEventListener(this))}if($("profile-message-to")){$$(".profile-message-compose a.cancel").invoke("observe","click",function(h){h.stop();history.go(-1)});new Ajax.Autocompleter("profile-message-to","profile-message-to-autocomplete",myDeco.urls.sendMessageSuggestRecipient,{minChars:3,frequency:0.5})}$$(".sorting-selector .sorter").invoke("observe","click",this.changeSortingView.bindAsEventListener(this));if(this.isEditProfile){this.setAffiliationObservers();this.setAttachmentObservers();$$(".room-toggle").invoke("observe","click",this.roomStateChange.bindAsEventListener(this))}var g=$$(".edit-settings .errorlist");if(g.length>0){g[0].up("li.section").scrollTo()}if(Prototype.Browser.IE){$$(".profile-post-view img")._each(function(h){if(h.getWidth()>576){h.setStyle({width:576+"px"})}});$$("#profile-posts-list .post-message img")._each(function(h){if(h.getWidth()>360){h.setStyle({width:360+"px"})}})}var f=$("delete-account");if(f){f.observe("submit",this.handleDeleteAccount.bindAsEventListener(this))}var a=$$("body"),c=this;["save","delete"]._each(function(h){a.invoke("observe","modeleditor:"+h,c.observeModelEditor.bindAsEventListener(c))})},updateNavigation:function(){var a=$("left-navigation-sub");if(a&&myDeco.auth.isCurrentUser()){new Ajax.Request(myDeco.urls.objectsCount,{onSuccess:function(c){try{var d=c.responseText.evalJSON();var b=false;for(name in d){var g=d[name];if(g.count>0){a.select("."+name)._each(function(e){e.show();b=true})}}if(b){a.show()}}catch(f){}}})}},setAlertsObservers:function(){var a=$("alerts-list-type-selector");if(a){a.observe("change",function(c){var b=$("profile-whats-hot");switch(c.element().getValue()){case"personal":b.select(".alert.personal").invoke("show");b.select(".alert.friend").invoke("hide");break;case"friends":b.select(".alert.personal").invoke("hide");b.select(".alert.friend").invoke("show");break;default:b.select(".alert").invoke("show")}})}$$(".alerts-delete-all").invoke("observe","submit",this.alertsDeleteAll.bindAsEventListener(this))},closableObserver:function(a,c){var b="";if(a.up("#profile-whats-hot")){b={ctype:"alert",object_id:a.id.substring(a.id.indexOf("-")+1)}}else{if(a.up(".profile-messages-thread")){b={ctype:"mailmessage",object_id:a.select(".name a").first().rel}}}if(b){new Ajax.Request(myDeco.urls.deleteObject,{parameters:b,onSuccess:function(d){try{if(d.responseText.evalJSON().success){myDeco.closable.close(a)}}catch(f){}}});return false}return true},projectListDeleteObserver:function(c,e){var b=c.up(".project-list"),a=this;var f=c.down("a.page-ajax-remove");if(f){if(!myDeco.popin.isOpen()){var d="";if(c.hasClassName("room")){d="3D room"}else{if(c.hasClassName("moodboard")){d="moodboard"}else{if(c.hasClassName("photo")||c.hasClassName("scrapbook")){d="photo"}else{if(c.hasClassName("product")){d="product"}else{console.error("unknown media type requested")}}}}myDeco.popin.confirm({title:"Delete "+d,message:"Do you really want to delete this "+d+"?",yesButtonText:"Delete "+d,noButtonText:"Cancel",yesButton:function(i){i.stop();var g=$("profile-list-content"),j=g?g.select(".paginator li a.active"):false,h=(j&&j.length>0)?parseInt(j.first().innerHTML.replace(/[^\d]/g,"")):0;new Ajax.Request(f.href,{parameters:f.rel+(h?"&page="+h:""),onComplete:function(n){var m=false;try{var k=n.responseText.evalJSON()}catch(q){m="Unexpected error"}if(!m&&k.error){m=k.error.message}if(m){myDeco.popin.alert({title:"Error",message:m});return false}if(d=="product"){var l=(/guid=(.{40})/.exec(f.rel)||[])[1];myDeco.shortlist.remove(l)}myDeco.popin.alert({closeIn:2,title:"Delete "+d,message:"This "+d+" has been successfully deleted."});if(g){g.update(k.objects);a.setPaginateObserver()}else{if(c.up(".edit-profile")){var o=c.up(".section").down("form"),p=$F(o.section);a.editProfileObjectsUpdate(p,k)}else{e.remove(c)}}},onError:function(k){myDeco.popin.alert({title:"Error",message:"Unexpected error"})}})}});return false}else{return true}}return true},setAffiliationObservers:function(){var a=this;$$(".affiliation-upload").invoke("observe","click",function(b){b.stop();myDeco.popin.open({url:"#affiliation-upload",afterOpen:function(c){myDeco.fileInputs.init(c);c.select("div.fakefile a.button").invoke("addClassName","button-no-arrow");c.select("a.save").invoke("observe","click",function(d){d.stop();d.element().up("form").submit()})}})});$$(".affiliation-delete").invoke("observe","click",function(b){b.stop();myDeco.popin.confirm({title:"Delete affiliation logo",message:"Do yoy really want to delete this logo?",yesButtonText:"Delete logo",noButtonText:"Cancel",yesButton:function(c){c.stop();new Ajax.Request(b.findElement("a").href,{onComplete:function(f){try{var d=f.responseText.evalJSON();if(!d.error){$("affiliation-holder").update(d.response);a.setAffiliationObservers()}}catch(g){}myDeco.popin.alert({title:"Delete affiliation logo",message:"Logo has been successfully deleted.",closeIn:2})}})}})})},affiliationUpload:function(a){if(a.error){myDeco.popin.content().down(".error").update(a.response)}else{$("affiliation-holder").update(a.response);this.setAffiliationObservers();myDeco.popin.open({url:"#affiliation-upload-result",closeIn:2})}},setAttachmentObservers:function(){$$(".attachment-upload").invoke("observe","click",function(a){a.stop();myDeco.popin.open({url:"#file-upload",afterOpen:function(b){myDeco.fileInputs.init(b);b.select("div.fakefile a.button").invoke("addClassName","button-no-arrow");b.select("a.save").invoke("observe","click",function(c){c.stop();c.element().up("form").submit()})}})});$$(".attachment-delete").invoke("observe","click",function(a){a.stop();myDeco.popin.confirm({title:"Delete file",message:"Do yoy really want to delete this file?",yesButtonText:"Delete file",noButtonText:"Cancel",yesButton:function(b){b.stop();new Ajax.Request(a.findElement("a").href,{onComplete:function(d){try{var c=d.responseText.evalJSON();if(!c.error){$("attachment-holder").update(c.response)}this.setAttachmentObservers()}catch(f){}myDeco.popin.alert({title:"Delete file",message:"File has been successfully deleted.",closeIn:2})}})}})})},attachedFileUpload:function(a){if(a.error){myDeco.popin.content().down(".error").update(a.response)}else{$("attachment-holder").update(a.response);this.setAttachmentObservers();myDeco.popin.open({url:"#file-upload-result",closeIn:2})}},wishlistPopin:function(b){b.stop();var a=this;myDeco.popin.open({url:"#email-wishlist-popin",afterOpen:function(d){var c=d.down("form");c.observe("submit",a.wishlistSubmit.bindAsEventListener(a));c.observe("mydeco:submit",a.wishlistSubmit.bindAsEventListener(a));c.down("a.submit").observe("click",function(f){f.element().up("form").fire("mydeco:submit")})}})},wishlistSubmit:function(b){b.stop();var a=b.element();new Ajax.Request(a.action,{parameters:a.serialize(),onComplete:function(c){myDeco.popin.alert({title:"Email your wishlist",message:"Your wishlist has been successfully emailed",closeIn:2})}})},addImageSuccess:function(a){if(a){a.stop()}myDeco.popin.alert({title:"Add image",message:"Your image has been successfuly added.",closeIn:2})},roomPhotoUpload:function(a){if(a.error){myDeco.popin.content().down(".error").update(a.response)}else{var b=$(this.photoDestination);if(b){new PeriodicalExecuter(function(c){c.stop();Event.fireRealEvent(b.down("select"),Event.createRealEvent("change"),"change")},0.2)}this.addImageSuccess()}},photoPopinInit:function(b){var a=b.down("form");myDeco.fileInputs.init(a);a.select("div.fakefile a.button").invoke("addClassName","button-no-arrow");if(!this.isEditProfile){a.insert(new Element("input",{type:"hidden",name:"list",value:"true"}))}a.down("a.save").observe("click",function(c){c.stop();Event.fireRealEvent(a,Event.createRealEvent("submit"),"submit")});a.observe("submit",function(e){e.stop();var c=a.down("input[name=tags]");if(c){var d=a.select(".checkbox .tag").select(function(f){return f.checked}).pluck("value");d.push.apply(d,a.down(".text.tags").value.split(/\s*,\s*/));c.value=d.join(",")}a.submit()})},addRoomPhoto:function(a){if(a){a.stop()}myDeco.popin.open({url:"#rooms-photo-upload-popin",afterOpen:function(b){this.photoPopinInit(b)}.bind(this)})},setPaginateObserver:function(b){var d=$("profile-list-content"),a=this;if(!d){return}var c=$("profile-followers");$$("#profile-rooms-list, #profile-products-wishlist, #profile-followers")._each(function(f){f.select('.paginator[rel!=""] a:not(.disabled)').invoke("observe","click",a.roomsPaginate.bindAsEventListener(a));if(!b){if(c){myDeco.followers.init(c)}myDeco.projectList.init($$(".project-list").first())}});d.select(".room-toggle").invoke("observe","click",this.roomStateChange.bindAsEventListener(this));initToolLinks(d);if(myDeco.username){d.select(".edit-room-project").invoke("show")}},_handleAjaxErrors:function(b,a){if(typeof a.error.message=="object"){for(error in a.error.message){var c=b.down("."+error+"_error");if(c){c.update(a.error.message[error]).show()}}}else{b.down(".general_error").update(a.response||a.error.message)}},addPhotoUpload:function(b){myDeco.popin.content().select(".error").invoke("hide");if(b.error){myDeco.profile._handleAjaxErrors(myDeco.popin.content(),b);myDeco.popin._resize()}else{var c=$("profile-list-content"),a=this;if(c){c.update(b.objects);a.setPaginateObserver()}this.addImageSuccess()}},addRoomProfileUpload:function(a){myDeco.popin.content().select(".error").invoke("hide");if(a.error){myDeco.profile._handleAjaxErrors(myDeco.popin.content(),a);myDeco.popin._resize()}else{this.editProfileObjectsUpdate("room_photos",a);myDeco.profile.addImageSuccess()}},addPhotoProfileUpload:function(a){myDeco.popin.content().select(".error").invoke("hide");if(a.error){myDeco.profile._handleAjaxErrors(myDeco.popin.content(),a);myDeco.popin._resize()}else{this.editProfileObjectsUpdate("photos",a);myDeco.profile.addImageSuccess()}},addScrapbookPhotoPopin:function(a){a.stop();myDeco.popin.open({url:"#scrapbook-photo-upload-popin",afterOpen:function(b){this.photoPopinInit(b)}.bind(this)})},surveySubmit:function(b){b.stop();var c=$("profile-survey");var a=c.down("form");new Ajax.Request(a.action,{parameters:b.findElement("a").hasClassName("cancel")?"cancel=true":a.serialize(),onComplete:function(d){new PeriodicalExecuter(function(f){f.stop();$$("div.blocker").invoke("remove")},0.5);Effect.Fade(c,{duration:0.5})}})},setSectionVisibility:function(d){var b=d.findElement("input"),c=b.up("form"),a=b.checked?1:0;b.disable();new Ajax.Request(myDeco.urls.profile.setSectionVisibility,{parameters:Object.extend({is_visible:a},c.serialize(true)),onComplete:function(){b.enable()},onFailure:function(){b.checked=!b.checked}})},setObjectsPerSection:function(c){var a=c.findElement("select"),b=a.up("form"),d=$F(b.section);new Ajax.Request(myDeco.urls.profile.objectsPerSection,{parameters:b.serialize(true),onSuccess:function(f){a.enable();var e=f.responseText.evalJSON();if(e.success&&$("profile-"+d+"-list")){this.editProfileObjectsUpdate(d,e)}}.bind(this),onLoading:function(){a.disable()},onFailure:function(){a.enable()}})},editProfileObjectsUpdate:function(e,a){var c=$("profile-"+e+"-list"),d=c.up(".section"),b=d?d.down(".project-list-empty"):null;if(!c){return}if(a.count>0){c.update(a.objects);b.hide();c.up(".project-list").show();c.select(".room-toggle").invoke("observe","click",this.roomStateChange.bindAsEventListener(this));myDeco.projectList.init(c.up(".project-list"));switch(e){case"rooms":case"moodboards":case"decorated_photos":case"furnished_photos":initToolLinks(c);break;case"room_photos":c.select(".room-photo-upload").invoke("observe","click",this.addRoomPhoto.bindAsEventListener(this));break;case"photos":c.select(".profile-add-image").invoke("observe","click",this.addScrapbookPhotoPopin.bindAsEventListener(this));break;default:console.log("Incorrect section")}myDeco.profile.external.facebookPostLinkObserver(c)}else{b.show();c.up(".project-list").hide()}if(a.slideshow&&myDeco.profile.slideshow){myDeco.profile.slideshow.update(a.slideshow)}},projectDeleteAll:function(a){a.stop();myDeco.popin.open({url:"#profile-project-delete-all",afterOpen:function(b){b.down("a.delete").observe("click",function(c){new Ajax.Request(a.findElement("a").href,{onComplete:function(d){myDeco.popin.open({url:"#profile-project-delete-all-result",closeIn:2})}});c.stop()})}})},alertsDeleteAll:function(a){a.stop();form=a.findElement("a");new Ajax.Request(myDeco.urls.alertsDeleteAll,{parameters:form.serialize(true),onSuccess:function(){Effect.Fade(form.next(".top-lines"),{duration:0.5});form.down(".form-submit-button").hide()}})},changeSortingView:function(c){c.stop();var b=c.findElement("a"),a=this;new Ajax.Request(b.readAttribute("href")+"&ajax=1",{method:"get",onSuccess:function(f){var d=f.responseText,e=$(b.readAttribute("rel"));if(d&&e){e.update(d);a.setPaginateObserver();b.siblings().invoke("removeClassName","active");b.addClassName("active")}}})},roomsChangeOrder:function(c){var a=c.findElement("select"),b=this;new Ajax.Request($F(a)+"&ajax=1",{method:"get",onSuccess:function(f){var d=f.responseText,e=$(a.readAttribute("rel"));if(d&&e){e.update(d);b.setPaginateObserver()}}})},roomsPaginate:function(d){d.stop();var c=d.findElement("a"),b=c.readAttribute("href"),a=this;if(b.indexOf("ajax")==-1){b+="&ajax=1"}new Ajax.Request(b,{method:"get",onSuccess:function(g){var e=g.responseText,f=$(c.up(".paginator").readAttribute("rel"));if(e&&f){f.update(e);a.setPaginateObserver()}}})},roomStateChange:function(c){c.stop();var b=c.findElement("a");var a=b.up(".project-list-item");var d=a.id.replace(/^.*?\-(\d+)$/,"$1");new Ajax.Request(!b.hasClassName("room-private")?myDeco.urls.markRoomPub:myDeco.urls.markRoomPrivate,{method:"post",parameters:{room_id:d},onSuccess:function(g){try{var f=g.responseText.evalJSON();a.select(".room-private, .room-public").invoke("toggle")}catch(h){}},onFailure:function(g){try{var f=g.responseText.evalJSON();if(f.error){myDeco.popin.alert({title:"Make design private",message:f.error.message})}}catch(h){}}})},handleDeleteAccount:function(b){b.stop();var a=b.element();myDeco.popin.confirm({title:"Delete account",message:"Are you sure you want to delete your account from mydeco?",yesButtonText:"Delete account",noButtonText:"Cancel",yesButton:function(){if(a.hasClassName("has-facebook")){FB.Connect.requireSession(function(){a.submit()})}else{a.submit()}}})},observeModelEditor:function(c){if(this.isEditProfile){Event.fireRealEvent($("profile-"+c.memo.type+"-list-holder").down("select"),Event.createRealEvent("change"),"change");return}var b=$("profile-list-content");if(b){var a=b.down(".paginator .active");if(a){Event.fireRealEvent(a,Event.createRealEvent("click"),"click")}else{Event.fireRealEvent(b.up(".section").down(".sorting-selector select"),Event.createRealEvent("change"),"change")}}}};addLoadEvent(myDeco.profile.init.bind(myDeco.profile));if(!myDeco.profile){throw ("No myDeco.profile loaded")}myDeco.profile.avatar={init:function(){var a=$("profile-photo").down("div.edit-button, div.add-button");if(a){var b=this._switch.bindAsEventListener(this);a.observe("mouseover",b).observe("mouseout",b).down("a.button").observe("click",this._edit.bindAsEventListener(this))}},_switch:function(b){var a=b.element();if(!a.hasClassName("edit-button")){a=a.up(".edit-button")}if(!a){return}if(b.type=="mouseover"){a.addClassName("semi");a.down("A").show()}else{a.removeClassName("semi");a.down("A").hide()}},_edit:function(a){a.stop();myDeco.popin.open({url:"#photo_upload",width:616,afterOpen:function(b){myDeco.fileInputs.init(b);b.select("div.fakefile a.button").invoke("addClassName","button-no-arrow");b.select("a.save").invoke("observe","click",function(c){c.stop();c.element().up("form").submit()})}})},upload:function(a){if(a.error){myDeco.popin.content().down(".error").update(a.response)}else{$("profile-photo").update(a.response);$("profile-photo-holder").down(".authorized").show();this.init();myDeco.popin.open({url:"#photo_upload_result",width:616,closeIn:2})}}};addLoadEvent(myDeco.profile.avatar.init.bind(myDeco.profile.avatar));if(!myDeco.profile){throw ("No myDeco.profile is loaded")}myDeco.profile.external={init:function(){var b=$("disassociate"),a=$("invite-friends");if(b){b.observe("click",this.disassociate.bindAsEventListener(this))}if(a){a.observe("click",this.inviteFriends.bindAsEventListener(this))}$$(".invite-your-friend").invoke("observe","click",this.invitePopin.bindAsEventListener(this));this.facebookPostLinkObserver()},disassociate:function(b){b.stop();var a=this;FB.Connect.requireSession(function(){new Ajax.Request(myDeco.urls.facebookDisassociate,{method:"post",onSuccess:function(d){var c=d.responseText.evalJSON();if(c.success){$("disassociate-text").update("Your account has been succesfully disconnected from Facebook.");$("disassociate-form").remove()}else{myDeco.popupForms.alert("Internal error. Please try again later.",b)}},onFailure:function(d){var c=d.responseText.evalJSON();if(c.error){myDeco.popupForms.alert(c.error.message,b)}}})})},inviteFriends:function(a){a.stop();FB.Connect.requireSession(function(){new Ajax.Request(myDeco.urls.facebookInviteIframe,{method:"get",onSuccess:function(c){var b=new FB.UI.FBMLPopupDialog("Invite your Facebook friends to mydeco!",c.responseText);b.setContentWidth(760);b.show()},onFailure:function(){myDeco.poupForms.alert("Internal error. Please try again later.",a)}})})},invitePopin:function(b){b.stop();var a=this;myDeco.popin.open({width:616,url:"#invite-friend-popin",afterOpen:function(c){c.down("a.add-contact").observe("click",a.invitePopinAddContact.bindAsEventListener(a));c.down("a.add-contacts").observe("click",a.invitePopinAddContacts.bindAsEventListener(a));c.down("a.send").observe("click",a.invitePopinSendInvite.bindAsEventListener(a))}})},invitePopinFillList:function(c){var a=myDeco.popin.content(),b=a.down("ul.invited-friends"),d=b.childElements().collect(function(f){return f.email});c._each(function(e){if(!e.email){return}if(!d.include(e.email)){var f=new Element("li",{className:"closable"}).update(e.email);f.email=e.email;f.name=e.name;b.insert({top:f});myDeco.closable.init(f)}})},invitePopinAddContact:function(d){d.stop();var a=d.findElement("fieldset"),c=a.down("input.name"),b=a.down("input.email");$("popin-content").down(".importer-error").update("&nbsp;");this.invitePopinFillList([{email:b.getValue(),name:c.getValue()}]);b.clear();c.clear()},invitePopinAddContacts:function(e){e.stop();var b=this,d=e.findElement("form"),a=d.up("#popin-content").down("img.ajaxLoader").show();var c=$("popin-content").down(".importer-error").update("&nbsp;");new Ajax.Request(d.action,{parameters:d.serialize(),onSuccess:function(g){var f=g.responseText.evalJSON();if(f.success){b.invitePopinFillList(f.contacts)}else{c.update(f.errors[0].error)}a.hide()},onFailure:function(f){a.hide();myDeco.popin.alert({title:"Invite friends",message:"An error has occured. Please try later."})}})},invitePopinSendInvite:function(b){b.stop();var a=b.element().up(".invite-friend-popin").down("form.sendform"),d=a.select("ul.invited-friends li");$("popin-content").down(".importer-error").update("&nbsp;");if(d.length>0){var c=d.collect(function(f){return[f.email,f.name]});a.down("input").value=c.toJSON();new Ajax.Request(a.action,{parameters:a.serialize(),onSuccess:function(f){var e=f.responseText.evalJSON();if(e.success){myDeco.popin.alert({title:"Invite friends",message:"Your friends have successfully been invited.",closeIn:2})}},onFailure:function(e){myDeco.popin.alert({title:"Invite friends",message:"An error has occured. Please try later."})}})}},facebookPostLinkObserver:function(a){(Object.isElement(a)?a:$(document.body)).select(".facebook-post-link").invoke("observe","click",myDeco.profile.external.facebookPostLink.bindAsEventListener(myDeco.profile.external))},facebookPostLink:function(b){b.stop();var a=b.findElement("a"),c=a.rel?a.rel:document.title;window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(a.href)+"&t="+encodeURIComponent(c),"sharer","toolbar=0,status=0,width=626,height=436")}};addLoadEvent(myDeco.profile.external.init.bind(myDeco.profile.external));myDeco.profile.slideshow={_types:["rooms","moodboards","room_photos"],_ajax:null,_container:null,_upload_contaner:null,_object_id:null,_object_type:null,_type_selector:null,init:function(){$$(".slideshow-append").invoke("observe","click",this.show.bindAsEventListener(this));$$(".slideshow-delete-all").invoke("observe","click",this.removeAll.bindAsEventListener(this));var a=$$("body"),b=this;["save","delete"]._each(function(c){a.invoke("observe","modeleditor:"+c,b.observeModelEditor.bindAsEventListener(b))});this.setObservers()},show:function(b){if(b){b.stop();if(b.findElement("a").hasClassName("no-more")){myDeco.popin.alert({title:"Add item",message:"Sorry - maximum number of slideshow items is 6. If you'd like to add something new please choose remove an item from the existing showcase"});return}}var a=this;myDeco.popin.open({url:"#slideshow-popin",width:690,height:590,afterOpen:function(c){a._container=c.down(".sidebar-menu-pane");a._upload_container=c.down(".slideshow-source-upload");a._ajax=a._container.down(".image-ajax-loader");a._type_selector=a._container.down("select.slideshow-mydeco-source-type");c.select(".form-submit-button")._each(function(d){d.observe("click",function(e){e.stop();if(d.hasClassName("disabled")){return}d.addClassName("disabled");Event.fireRealEvent(d.up("form"),Event.createRealEvent("submit"),"submit")})});a._container.down("form").observe("submit",a.addItem.bindAsEventListener(a));myDeco.sidebarMenu.init(c);initToolLinks(c);c.select(".slideshow-upload").invoke("observe","click",a.goUpload.bindAsEventListener(a));myDeco.profile.photoPopinInit(a._upload_container);c.down("div.fileinputs input.file").size=48;a._type_selector.observe("change",function(d){a._objects_list_request({section:d.findElement("select").getValue()})});Event.fireRealEvent(a._type_selector,Event.createRealEvent("change"),"change")}})},_objects_list_request:function(f){var c=this,e=[".slideshow-mydeco-items"];this._object_type=f.section;function b(){c._ajax.hide();c._container.select(".slideshow-mydeco-"+c._object_type+"-empty").invoke("show")}for(var d=0,a=this._types.length;d<a;d++){e.push(".slideshow-mydeco-"+this._types[d]+"-empty");e.push(".slideshow-mydeco-"+this._types[d]+"-append");e.push(".slideshow-mydeco-items label."+this._types[d])}this._container.select(e.join(",")).invoke("hide");this._container.down("a.add-item").addClassName("disabled");this._ajax.show();new Ajax.Request(myDeco.urls.profileSlideshowObjectsToAddAjax,{parameters:f,onSuccess:function(h){c._ajax.hide();e=[".slideshow-mydeco-items"];try{var g=h.responseText.evalJSON()}catch(j){b();return}if(!g.error&&g.count>0){var i=c._container.down(".slideshow-mydeco-items").down(".objects").update(g.objects).down("ul.items");i.select("a, span, input").invoke("observe","click",c.select.bindAsEventListener(c));c._container.select(".slideshow-mydeco-items .paginator a:not(.disabled)").invoke("observe","click",function(k){k.stop();c._objects_list_request({section:c._object_type,page:(k.findElement("a").href.replace(/.*page=(\d+).*$/,"$1")||1)})});e.push(".slideshow-mydeco-"+c._object_type+"-append");e.push(".slideshow-mydeco-items label."+c._object_type);c._container.select(e.join(",")).invoke("show");i.scrollTop=0}else{b()}},onError:function(){c._ajax.hide()}})},select:function(b){var a=b.element();if(b.findElement("a")){b.stop()}a=b.findElement("li").down("input");a.checked=true;this._object_id=a.getValue();this._container.down(".add-item").removeClassName("disabled")},goUpload:function(a){a.stop();this._upload_container.select(".error").invoke("hide");Event.fireRealEvent(a.element().up(".slideshow-popin").down("ul.sidebar-menu li:nth-child(2)"),Event.createRealEvent("click"),"click")},update:function(a){if(typeof a!="object"){try{a=a.evalJSON()}catch(b){this.error();return false}}if(a.error){this.error(false,a.error);return false}$$("#profile-designer-showcase .slideshow-append").invoke(a.count==6?"addClassName":"removeClassName","no-more");if(a.count>0){$("profile-slideshow-list").update(a.objects);this.setObservers();$("slideshow-container").show();$("slideshow-empty").hide();myDeco.tabs.tabSwitcherCollection.init(null,true)}else{$("slideshow-container").hide();$("slideshow-empty").show()}this._types._each(function(c){if(a[c]){myDeco.profile.editProfileObjectsUpdate(c,a[c])}});return true},error:function(b,a){myDeco.popin.alert({title:b||"Error",message:a||"Unexpected error has occured. Please try again later"})},setObservers:function(){var a=this;$$(".slideshow-remove-item")._each(function(b){b.observe("mouseover",a.mouse.bindAsEventListener(a)).observe("mouseout",a.mouse.bindAsEventListener(a)).down(".button").observe("click",a.remove.bindAsEventListener(a))})},mouse:function(b){var a=b.element();if(!a.hasClassName("slideshow-remove-item")){a=a.up(".slideshow-remove-item")}if(!a){return}if(b.type=="mouseover"){a.addClassName("semi");a.down("A").show()}else{a.removeClassName("semi");a.down("A").hide()}},remove:function(c){c.stop();var a=this,b=c.findElement("a");myDeco.popin.confirm({title:"Remove image",message:"Do you really want to remove this image from slideshow?",yesButtonText:"Remove image",noButtonText:"Cancel",yesButton:function(d){d.stop();new Ajax.Request(myDeco.urls.profileSlideshowDeleteAjax,{parameters:{id:b.rel},onSuccess:function(e){a.update(e.responseText);myDeco.popin.alert({title:"Remove image",message:"Image has been successfully removed from slideshow",closeIn:2})},onError:function(e){a.error("Remove image")}})}})},removeAll:function(b){b.stop();var a=this;myDeco.popin.confirm({title:"Remove all slideshow items",message:"Do you really want to remove all items from slideshow?",yesButtonText:"Remove",noButtonText:"Cancel",yesButton:function(c){c.stop();new Ajax.Request(myDeco.urls.profileSlideshowDeleteAllAjax,{onSuccess:function(f){try{var d=f.responseText.evalJSON()}catch(g){a.error("Remove all images");return}if(f.error){a.error("Remove all images",d.error);return}a.update({count:0});myDeco.popin.alert({title:"Remove all slideshow items",message:"All slideshow items have been removed successfully.",closeIn:2})},onError:function(d){a.error("Remove all slideshow items")}})}})},addItem:function(c){c.stop();var a=this,b="room";if(this._object_type=="scrapbook"){b="scrapbook"}new Ajax.Request(myDeco.urls.profileSlideshowAddAjax,{parameters:{content_type:b,object_id:a._object_id},onSuccess:function(d){if(a.update(d.responseText)){myDeco.popin.alert({title:"Add slideshow item",message:"This item has been successfully added to slideshow",closeIn:2})}},onError:function(d){a.error()}})},upload:function(a){if(typeof a.error!="undefined"&&a.error!=false){if(typeof a.error.message=="object"){for(error in a.error.message){var b=this._upload_container.down("."+error+"_error");if(b){b.update(a.error.message[error]).show()}}}else{if(a.error.message){this._upload_container.down(".general_error").update(a.error.message)}}this._upload_container.select(".disabled").invoke("removeClassName","disabled");myDeco.popin._resize()}else{if(this.update(a)){myDeco.popin.alert({title:"Add slideshow item",message:"Your photo has been successfully added to slideshow",closeIn:2})}}},observeModelEditor:function(a){if(myDeco.popin.isOpen()&&myDeco.popin.content().down(".slideshow-popin")&&this._container.visible()&&this._type_selector.getValue()==a.memo.type){Event.fireRealEvent(this._type_selector,Event.createRealEvent("change"),"change")}}};addLoadEvent(myDeco.profile.slideshow.init.bind(myDeco.profile.slideshow));