myDeco.popin={options:{base:"popin",width:616,height:200,url:"",afterOpen:null,beforeClose:null,closeIn:0,autoResizeX:false,autoResizeY:true,ajaxLoaderClass:"ajaxLoader",template:null,borders:50},_body:null,_window:null,_cclose:null,_ccloseByKeyPress:null,_cresize:null,windowOptions:{},visible:false,holder:"",contentContainer:"",background:"",init:function(a){if(this._cclose){return}this._window=$(window);this._body=$(document.body);this.options=$.extend(true,this.options,a||{});this._cclose=this.close.bind(this);this._ccloseByKeyPress=this._closeByKeyPress.bind(this);this._cresize=this.resize.bind(this)},open:function(b){this.init();if(this.visible&&$.isFunction(this.windowOptions.beforeClose)){this.windowOptions.beforeClose()}this.windowOptions=$.extend(true,this.windowOptions,this.options,b||{});if(this.windowOptions.url==""&&this.windowOptions.template==null){return}var d=this.windowOptions.base+"-content-holder",c=this.windowOptions.base+"-content";if(!this.visible){this.holder=$('<div id="'+d+'" class="'+d+'" style="display:none;position:absolute"></div>').appendTo(this._body);this.contentContainer=$('<div class="clearfix '+c+'" id="'+c+'"></div>').appendTo(this.holder);this.holder.append('<a href="#" class="'+this.windowOptions.base+'-close-title"></a>');this.contentContainer.hide();this.holder.css({display:"block",left:parseInt(this._window.scrollLeft()+this._window.width()/2)+"px",top:parseInt(this._window.scrollTop()+this._window.height()/2)+"px",width:0,height:0});this._showBackground();this._window.keypress(this._ccloseByKeyPress).bind("resize",this._cresize);this._body.bind("close.popin",this._cclose)}else{if($.isFunction(this.windowOptions.beforeCreate)){this.windowOptions.beforeCreate(this.contentContainer)}this.holder.find("."+this.windowOptions.base+"-close-title").unbind("click",this._cclose);this.contentContainer.find("."+this.windowOptions.base+"-close").unbind("click",this._cclose);this._hideContent()}this._hideProblemElements();if(this.windowOptions.template||this.windowOptions.url.indexOf("#")==0){this.windowOptions.template=this.windowOptions.template||$(this.windowOptions.url).html();this.contentContainer.html(this.windowOptions.template);this._processContent()}else{var a=this;this.contentContainer.addClass(this.windowOptions.ajaxLoaderClass);this.contentContainer.load(this.windowOptions.url,"",function(){a.contentContainer.removeClass(a.windowOptions.ajaxLoaderClass);a._processContent()})}},_processContent:function(){var a=this;this._showContent();this.holder.find("."+this.windowOptions.base+"-close-title").bind("click",this._cclose);this.contentContainer.find("."+this.windowOptions.base+"-close").bind("click",this._cclose);if($.isFunction(this.windowOptions.afterOpen)){this.windowOptions.afterOpen(this.contentContainer)}this.resize();this.visible=true;if(this.windowOptions.closeIn>0){this.contentContainer.timed=true;setTimeout(function(){if(a.contentContainer.timed){a.close()}},this.windowOptions.closeIn*1000)}},close:function(a){if(a){a.stop()}if(!this.visible){return false}if($.isFunction(this.windowOptions.beforeClose)){this.windowOptions.beforeClose(this.contentContainer)}this._window.unbind("keypress",this._ccloseByKeyPress).unbind("resize",this._cresize);this._body.unbind("close.popin",this._cclose);this.holder.find("."+this.windowOptions.base+"-close-title").unbind("click",this._cclose);this.contentContainer.find("."+this.windowOptions.base+"-close").unbind("click",this._cclose);this.visible=false;this._hideHolder();this._hideBackground();this._showProblemElements()},content:function(){return this.contentContainer},isOpen:function(){return this.visible},resize:function(a,i){if(typeof a=="object"){a=undefined}if(typeof i=="object"){i==undefined}var d=this._window.scrollLeft(),b=this._window.scrollTop(),e=this._window.width(),f=this._window.height(),c=0,h={width:a||this.windowOptions.width,height:i||this.windowOptions.height},g={left:parseInt(d+(e-h.width)/2),top:parseInt(b+(f-h.height)/2)};this.holder.css({left:g.left+"px",top:g.top+"px",width:h.width+"px",height:h.height+"px"});if(this.windowOptions.autoResizeX){h.width=this.contentContainer.innerWidth();c=e-this.contentContainer.outerWidth(true)-this.windowOptions.borders*2;if(c<0){h.width+=c}g.left=parseInt(d+(e-h.width)/2)}if(this.windowOptions.autoResizeY){h.height=this.contentContainer.innerHeight();c=f-this.contentContainer.outerHeight(true)-this.windowOptions.borders*2;if(c<0){h.height+=c}g.top=parseInt(b+(f-h.height)/2)}if(this.windowOptions.autoResizeX||this.windowOptions.autoResizeY){this.holder.css({left:g.left+"px",top:g.top+"px",width:h.width+"px",height:h.height+"px"})}this._showBackground()},_showContent:function(){this.contentContainer.show()},_hideContent:function(){this.contentContainer.hide()},_hideHolder:function(){this.holder.remove()},_showBackground:function(){var e,a,d={},c,f,b=this.windowOptions.base+"-background";if(window.innerHeight&&window.scrollMaxY){e=document.body.scrollWidth;a=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){e=document.body.scrollWidth;a=document.body.scrollHeight}else{e=document.body.offsetWidth;a=document.body.offsetHeight}}if(document.documentElement&&document.documentElement.clientHeight){c=document.documentElement.clientWidth;f=document.documentElement.clientHeight}else{if(document.body){c=document.body.clientWidth;f=document.body.clientHeight}}d.height=Math.max(f,a);d.width=Math.max(c,e);if(!this.background||this.background.size()==0){this.background=$('<div id="'+b+'" class="'+b+'" />').css({position:"absolute",left:0,top:0});this._body.append(this.background);this._fixTransparency(this.background.get(0))}this.background.width(d.width).height(d.height)},_fixTransparency:function(b){if(myDeco.browser.isIE){var a=b.currentStyle.opacity;if(a!=undefined&&a!=1){a=Math.round(a*100);var c=b.filters["DXImageTransform.Microsoft.alpha"]||b.filters.alpha;if(c){c.opacity=a}else{b.style.filter+="progid:DXImageTransform.Microsoft.Alpha(opacity="+a+")"}}}},_hideBackground:function(){this.background.remove();this.background=null},_hideProblemElements:function(){if(myDeco.browser.isIE6&&!this.visible){$.each($("select, object, embed, iframe"),function(b,a){a=$(a);a.data("visibility",a.css("visibility")).css("visibility","hidden")})}},_showProblemElements:function(){if(myDeco.browser.isIE6){$.each($("select, object, embed, iframe"),function(c,b){b=$(b);var a=b.data("visibility");if(a){b.css("visibility",a)}})}},_closeByKeyPress:function(a){if(a.keyCode==27){this.close()}},plugin:function(c,a,d){this.init();var b=this;if(this[c]!=undefined){throw"Name is already occuped"}a=a||{};d=d||function(){};this[c]=function(e){e=e||{};var f=e.afterOpen?function(g){(d.bind(b))(g);e.afterOpen(g)}:d.bind(b);this.open($.extend(true,{},a,e,{afterOpen:f}))}}};$(function(){var a=myDeco.popin;a.init.apply(a);a.plugin("alert",{template:'<h2 class="top-line title">Alert</h2><p class="message"></p><div class="toolbar"><a href="#" class="button green-button popin-close"><span class="inner close-button-text">Close</span></a></div>'},function(b){if(this.windowOptions.closeButtonText){b.find(".close-button-text").html(this.windowOptions.closeButtonText)}if(this.windowOptions.title){b.find(".title").html(this.windowOptions.title)}else{b.find(".title").remove()}if(this.windowOptions.message){b.find(".message").html(this.windowOptions.message)}else{b.find(".message").remove()}});a.plugin("confirm",{template:'<h2 class="top-line title">Confirm</h2><p class="message"></p><div class="toolbar"><a href="#" class="button green-button yes-button"><span class="inner yes-button-text">Yes</span></a><a href="#" class="button button-no-arrow no-button"><span class="inner no-button-text">No</span></a></div>'},function(b){this.windowOptions.yesButtonText&&b.find(".yes-button-text").html(this.windowOptions.yesButtonText);this.windowOptions.noButtonText&&b.find(".no-button-text").html(this.windowOptions.noButtonText);this.windowOptions.yesButton&&b.find(".yes-button").click(this.windowOptions.yesButton);b.find(".no-button").click(this.windowOptions.noButton||this._cclose);if(this.windowOptions.title){b.find(".title").html(this.windowOptions.title)}else{b.find(".title").remove()}if(this.windowOptions.message){b.find(".message").html(this.windowOptions.message)}else{b.find(".message").remove()}});a.plugin("image",{autoResizeX:true,template:'<h2 class="top-line title">Image</h2><div class="popin-image" style="position:relative" />'},function(c){var b=this;if(this.windowOptions.title){c.find(".title").html(this.windowOptions.title)}else{c.find(".title").remove()}$('<img src="'+this.windowOptions.url+'" />').load(function(k){var h=$(k.target);c.find(".popin-image").css("height","auto").prepend(h);var d=h.width(),n=h.height();b.contentContainer.width(d);b.resize();var m=b.contentContainer.outerWidth(true),j=b.contentContainer.outerHeight(true),f=b.holder.innerWidth(),l=b.holder.innerHeight();if(m>f||j>l){var g=m-f,i=j-l;if(g>i){h.width(d-g);b.contentContainer.width(d-g)}else{h.height(n-i);b.contentContainer.width(parseInt((n-i)*d/n))}b.resize()}})})});$(function(){var a=$("#tags_form"),b=$("#cloud-tags-ul");if(myDeco.username){function c(e){if(e.length==0){return false}if(!$.isArray(e)){e=e.split(/\s*,\s*/)}b.text("").show();var d=a.find("#tag_url").val();$.each(e,function(g,f){b.append('<li class="tag"><a href="'+d.replace(/TAG_NAME/,f)+'">'+f+"</a></li>")})}a.submit(function(g){var d=$("#tags_input"),f=d.val();if(f==""){return false}myDeco.buttons.disable(a);$.ajax({url:a.find("#post_tags_url").val(),type:"post",data:"tags="+f,dataType:"json",success:function(h){var e=$("#tags-error-notice");if(h.success){d.val("");e.hide();$("#not-tagged-message").hide();c(h.tags)}else{e.css("display","inline").text("Error adding tags")}},complete:function(){myDeco.buttons.enable(a)}});return false});if(b.children().size()==0){$.ajax({url:a.find("#get_tags_url").val(),type:"post",dataType:"json",success:function(d){c(d.tags)}})}}else{a.hide()}});$(function(){var d={},b=this,a=0;$("div.happy-sad-bar").each(function(){var e=$(this);d[e.identify()]={ctype:e.find("input[name=content_type]").val(),object_id:e.find("input[name=object_id]").val(),rate_type:"rating"};a=true});if(!a){return}function c(m){m.stop();var l=$(m.target).closest("a");if(l.hasClass("disabled")){return false}var i=l.hasClass("smiley")?1:-1,h=l.closest(".happy-sad-bar"),g=h.find("form"),j=g.find(".like_count"),n=g.find(".dislike_count"),f=parseInt(j.text()),k=parseInt(n.text());g.find(".v").val(i);if(i>0){j.text(++f)}else{n.text(++k)}$.ajax({type:"post",data:g.serialize(),dataType:"json",url:myDeco.urls.setScore,success:function(o){if(!o.error){var p=f+k,e=Math.round(f*100/p);h.find(".loved").width(e+"%");h.find(".percentage").text(e+"% loved");h.find(".votes").text(p+" vote"+(p!=1?"s":""))}h.children().addClass("has_votes").find("a.button").addClass("disabled")}})}$.ajax({type:"post",data:"ratings="+JSON.stringify(d),dataType:"json",url:myDeco.urls.canRateMulti,success:function(f){if(!f.success){return}f=f.ratings;for(var e in f){var g=$("#"+e);if(!f[e].canRate){g.children().addClass("voted").find(".buttons a.button").addClass("disabled")}g.find("a.button").click(c)}}})});$(function(){myDeco.formDispatcher.initForm($("#send-to-friend-form"),"sendToMyFriend",{fetchUrl:myDeco.urls.forms.sendToMyFriend,position:"center",method:"post",onBeforeShow:function(a){this._form.find("textarea").val($("#send-to-my-friend-message").text());this.ajaxUrl=this._form.attr("action");this._form.find("#email-input").val("")},onBeforeSubmit:function(a){if(!myDeco.username){location.href=myDeco.urls.userLoginQuick+"?next="+location.href;return false}if(!myDeco.formValidation.validate(this._form)){return false}myDeco.buttons.disable(this._form)},onBeforeClose:function(a){myDeco.bubbles.removeAll()},onSuccess:function(a){this._form.hide();myDeco.formDispatcher.alert(a.success?"An article has been successfully sent.":(a.error.message||"Some email send error"))},onFailure:function(){this._form.hide();myDeco.formDispatcher.alert("Sorry, we were unable to process your request. Please try again later.")}})});myDeco.formValidation={init:function(){var a=this;$("form.validate").submit(function(b){return a.validate($(b.target))})},validate:function(c){var a=this,b=false;c.find(".validate").each(function(){var d=$(this),e=a.isInvalid(d);if(e){a.showError(d,e);b=true}});return !b},showError:function(b,d){var c=b.parents("form"),a=c.hasClass("bubble-container")||c.closest("#popin-content").size()>0;this.clearError(b);if(d){b.data("bubble",myDeco.bubbles.create(b,d,a))}},clearError:function(a){$.each(a,function(){element=$(this);if(element.data("bubble")){element.data("bubble").remove();element.removeData("bubble")}})},isInvalid:function(e){if(!e.is(":visible")){return false}var f=e.val();if(e.hasClass("v-required")&&f==""){return"Please ensure each field is complete before you re-submit."}if(e.hasClass("v-number")&&f.match(/\D/)){return"Please enter a number."}if(e.hasClass("v-required-inbox")&&f==""){return"Oops! You forgot your message!"}if(e.hasClass("v-email")&&!this.validateEmail(f)){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(e.hasClass("v-password")&&!this.validatePassword(f)){return"Passwords must be 5-15 characters and may contain numbers, letters and underscores."}if(e.hasClass("v-passwordconfirm")&&!this.validatePasswordConfirm(f)){return"Your passwords must match."}if(e.hasClass("v-date")&&!this.validateDate(f)){return"Must be a valid date of the form dd/mm/yyyy. Eg: 19/09/2007"}if(e.hasClass("v-url")&&!this.validateUrl(f)){return"Please enter a valid url that begins with http://"}var c="v-word-length-",d=e.get(0).className,b=d.indexOf(c);if(b!=-1){var g=d.indexOf(" ",b);if(g==-1){g=d.length}var a=parseInt(d.substr(b+c.length,g));if(!this.validateWordLength(f,a)){return"Oops! Please make sure words in your comment do not exceed "+a+" characters in length."}}if(e.hasClass("v-no-html")&&!this.validateNoHTML(f)){return"Should not contain any HTML-like tags"}return false},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){return $("#sign-up-password1, #id_password1").val()==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(c,b){var e=c.split(" ");for(var d=0,a=e.length;d<a;d++){if(e[d].length>b){return false}}return true},validateNoHTML:function(a){return !/<[a-zA-Z]+(\s[^>]*)?>/.test(a)}};$(myDeco.formValidation.init.bind(myDeco.formValidation));myDeco.bubbles={create:function(f,h,e){function g(i){$(i.target).closest(".bubble").fadeOut("fast")}var d=f,c=e?f.offsetParent():$(document.body),b=c.append('<div class="bubble" style="display:none"><div class="rounded"><p>'+h+'</p></div><div class="bubble-tip"></div></div>').children(":last");if(f.is("textarea:hidden")&&f.prev(":first").is("iframe")){d=f.prev(":first")}var a=e?d.position():d.offset();if(f.hasClass("right")){b.addClass("bubble-right").css({left:(a.left-b.outerWidth()-15)+"px",top:a.top+"px"})}else{b.css({left:(a.left+f.outerWidth()+15)+"px",top:a.top+"px"})}if(myDeco.browser.isIE6){b.append(document.createTextNode(" "))}b.click(g).fadeIn("fast");return b},removeAll:function(){$(".bubble").remove()}};$(function(){function c(){myDeco.popin.alert({title:"Error",message:"An unexpected error occurred.  Please try again."})}$("#room-image-enlarge").show().click(function(f){f.stop();var d=$(f.target).closest("a");myDeco.popin.image({url:d.attr("href"),title:d.attr("title")||myDeco.roomDetail.name,afterOpen:function(g){var e=$("#room-image-map");if(e.size()>0){g.find(".popin-image").append(e.html())}}})});$("#print").click(function(d){d.stop();if(window.print!=undefined){window.print()}});if(!myDeco.roomDetail){return false}$.each(myDeco.roomDetail.competitions,function(d,e){$("#vote-"+e).click(function(f){f.stop();if(!myDeco.username){document.location=myDeco.urls.userLogin+"?next="+document.location.href;return false}$.ajax({type:"post",data:{entry_id:e},dataType:"json",url:myDeco.urls.room_competition.vote_ajax,success:function(h){var g=$("#thankyou-"+h.entry_id);$("#vote-"+h.entry_id).hide();if(!h.success){g.addClass("error");g.html(h.error)}g.show()},error:c})})});if(myDeco.username&&myDeco.roomDetail.owner==myDeco.username){function a(f,e){var d=$("#entry-form-"+f);if(e){d.find("input[name=coords]").val(e.slice(0,2).join(","))}$.ajax({type:"post",data:d.serialize()+"&room="+myDeco.roomDetail.id+"&competition="+f,dataType:"json",url:myDeco.urls.room_competition.entry_ajax,success:function(h){var g=$("#error-"+f);if(h.error){g.html(h.error).show()}else{g.hide();$("#entry-form-"+f).hide();$("#goodluck-"+f).show().find("a.force-cache-miss").each(function(){myDeco.addCacheMissParam(this)})}},error:c,complete:function(){myDeco.buttons.enable(d)}})}$(".other-option, .own-option").toggle();$("#competition-vote").hide();$("#switchstate").click(function(d){d.stop();$.ajax({type:"post",data:{room_id:myDeco.roomDetail.id},dataType:"json",url:myDeco.roomDetail.state=="public"?myDeco.urls.markRoomPrivate:myDeco.urls.markRoomPub,success:function(e){myDeco.roomDetail.state=e["public"]?"public":"private";$("#private-public").text(!e["public"]?"public":"private")},error:function(g,e){var f=JSON.parse(g.responseText);if(f&&f.error){myDeco.popin.alert({title:"Make "+myDeco.roomDetail.humanType+" private",message:f.error.message})}else{c()}}})});$("#delete-room-link").click(function(f){f.stop();var d=$(this),g="Delete "+myDeco.roomDetail.humanType;myDeco.popin.confirm({title:g,message:"Are you sure you want to delete this "+myDeco.roomDetail.humanType+"?",noButtonText:"Cancel",yesButtonText:"Delete",yesButton:function(h){h.stop();myDeco.popin.content().find(".toolbar").addClass("disabled");$.ajax({url:myDeco.urls.deleteRoom,type:"post",data:d.attr("rel"),dataType:"json",success:function(e){if(myDeco.roomDetail&&myDeco.roomDetail.delete_next_url){window.location.href=myDeco.roomDetail.delete_next_url}else{d.remove();myDeco.popin.alert({title:g,message:"Your "+myDeco.roomDetail.humanType+" has been successfuly deleted.",closeIn:2})}},error:function(j,e){var i=JSON.parse(j.responseText);if(i&&i.error){myDeco.popin.alert({title:"Delete "+myDeco.roomDetail.humanType,message:i.error.message})}else{c()}}})}})});var b=$("#competition-entry");if(b.size()>0){$.ajax({type:"post",data:{room_id:myDeco.roomDetail.id},dataType:"json",url:myDeco.urls.room_competition.available_competitions_ajax,success:function(f){if(f.success&&f.entry_block.length>0){var d=$("#competition-entry"),e=d.closest(".room-detail-competition-block");if(myDeco.user.isCurrentUser()&&d.is(":empty")&&e.size()>0){e.hide();return}d.html(f.entry_block).show();myDeco.buttons.initSubmitButtons(d.find("input:submit"));$.each(f.competition_ids,function(g,h){$("#entry-form-"+h).submit(function(k){k.stop();var j=$(this),i=j.find("input[name=postcode]");if(i.size()>0){myDeco.location2coords(i.val(),function(l){a(h,l)},function(l){a(h)})}else{a(h)}})})}},error:c})}}});