$('a[href="http://www.bangonthedoor.com/shop"]').bind("click",function(){showComingSoonOverlay();return false});function showComingSoonOverlay(){var b=$("#soon_overlay a");b.css("background-image","url(/img/overlay-close.png)");b.unbind("click");b.bind("click",function(){$("#soon_overlay").fadeOut();return false});$("#soon_overlay").fadeIn()}function stickerFactory(b){var a={top:0,left:0,holder:$("#card .holder"),img:$('<img src="/'+b+'">'),url:b,init:function(){this.holder.append(this.img);var c=this;this.img.draggable({containment:this.holder,scroll:false,stop:function(d,e){c.top=e.position.top;c.left=e.position.left}})},getPosition:function(){return{top:this.top,left:this.left}},getURL:function(){return this.url}};a.init();return a}function returnCardCreator(b){var a={holder:$("#card .holder"),headline:$("#card h1"),maxPages:0,currPage:0,stickerData:[],stickers:[],cardText:"",init:function(){for(var c=0;c<6;c++){$("div.gallery div:eq("+c+")").bind("click",{menuController:this,n:c},function(e){e.data.menuController.buttonPressed(e.data.n)})}$("#choose a.back").bind("click",{menuController:this},function(e){e.data.menuController.prevPressed();return false});$("#choose a.next").bind("click",{menuController:this},function(e){e.data.menuController.nextPressed();return false});$("#clear_button a").bind("click",{menuController:this},function(e){$("#special_overlay").fadeIn();return false});$("#yes_button a").bind("click",{menuController:this},function(e){e.data.menuController.clearCard();$("#special_overlay").fadeOut();return false});$("#no_button a").bind("click",function(e){$("#special_overlay").fadeOut();return false});$("#print_button a").bind("click",function(f){var e=window.open("/card-print.html","_blank");return false});$("#card_text").bind("keyup",{menuController:this},function(e){e.data.menuController.updateText(e.target.value)});this.updateText($("#card_text").val());var d="<p>Click on your favourite<br>characters to<br>create your card.</p>";showOverlay(d,"close",function(){return})},fillStickers:function(c){this.stickerData=c;this.maxPages=Math.floor((c.length-1)/6);this.currPage=0;this.updateStickerButtonImages();this.checkPaginationDisplay()},updateStickerButtonImages:function(){for(var c=0;c<6;c++){var d=c+(this.currPage*6);if(d>=this.stickerData.length){$("div.gallery div:eq("+c+")").hide();continue}$("div.gallery div:eq("+c+")").show();$("div.gallery div:eq("+c+") img").attr("src","/"+this.stickerData[d].url)}},buttonPressed:function(d){var c=d+(this.currPage*6);this.stickers.push(stickerFactory(this.stickerData[c].url))},nextPressed:function(){if(this.currPage==this.maxPages){return}this.currPage++;this.updateStickerButtonImages();this.checkPaginationDisplay()},prevPressed:function(){if(this.currPage==0){return}this.currPage--;this.updateStickerButtonImages();this.checkPaginationDisplay()},clearCard:function(){this.holder.empty();this.stickers=[]},updateText:function(c){this.cardText=c;this.headline.text(c)},checkPaginationDisplay:function(){if(this.currPage==this.maxPages){$("#choose a.next").hide()}else{$("#choose a.next").show()}if(this.currPage==0){$("#choose a.back").hide()}else{$("#choose a.back").show()}},getStickers:function(){return this.stickers}};a.init();a.fillStickers(b);return a}function getNameGameObject(b){$.each(b,function(d,c){b[d]=shuffleLetters(c)});var a={l:b,s:"",wordsArray:[],gameState:"waiting_for_words",setWords:function(d){if(d==""){return false}this.s=d.toLowerCase();this.wordsArray=[];if(checkWords(d)){showErrorOverlay(["<p>Oops! Sorry, you can't use that name on the Bang on the Door website :(</p>"],function(){return});return false}var e=this.s.length;for(var c=0;c<e;c++){this.wordsArray.push(this.getWordFromLetter(this.s.charAt(c)))}drawWords(this.wordsArray);return true},getWordFromLetter:function(d){if(d.match(/[a-z]/)==null){return""}var c=this.l[d].shift();this.l[d].push(c);return c},playPressed:function(){switch(this.gameState){case"waiting_for_words":if(!this.setWords($("#name").val())){break}$(".play_button span").text("play again");this.gameState="ready_to_reset";break;case"ready_to_reset":$("#name").val("");$("#game_holder p").empty();$(".play_button span").text("go");this.gameState="waiting_for_words";break}}};return a}function shuffleLetters(b){for(var c,a,d=b.length;d;c=parseInt(Math.random()*d),a=b[--d],b[d]=b[c],b[c]=a){}return b}function drawWords(a){var e=$("#game_holder p");var c=false;for(var b in a){if(a[b]==""){if(c){continue}e.append("<br><br>");c=true;continue}e.append("<span>"+a[b]+"</span>");c=false}}function checkWords(a){var b=/anal|anus|arse|ass|ballsack|balls|bastard|bitch|biatch|bloody|blowjob|blow job|bollock|bollok|boner|boob|bugger|bum|butt|buttplug|clitoris|cock|coon|crap|cunt|damn|dick|dildo|dyke|fag|feck|fellate|fellatio|felching|fuck|f u c k|fudgepacker|fudge packer|flange|goddamn|god damn|homo|jerk|jizz|knobend|knob end|labia|lmao|lmfao|muff|nigger|nigga|omg|penis|piss|poop|prick|pube|pussy|queer|scrotum|sex|shit|s hit|sh1t|slut|smegma|spunk|tit|tosser|turd|twat|vagina|wank|whore|wtf/;if(a.match(b)==null){return false}return true}function doFABOverlay(a){switch(a){case"upload":showErrorOverlay(["<p>Oops! Sorry, we didn't get your photo :( It might be that you need to make the filesize smaller.</p>"],function(){return});break;case"db":showErrorOverlay(["<p>Oops! Sorry, our pen ran out when taking your entry :(</p>"],function(){return});break;case"success":showOverlay("<p>Thanks for your entry!</p><p>Check back soon to see if your pet's been chosen!</p>","close",function(){return});break}}function FABEntryCheck(e,a,d){var c=false;var b=[];if(a==""){c=true;b.push("<p>Oops! You need to tell us your name!</p>");return{error:c,errorMessages:b}}if(e==""){c=true;b.push("<p>Oops! You need to tell us your Pet's Name!</p>");return{error:c,errorMessages:b}}if(d==""){c=true;b.push("<p>Oops! You need to pick a photo of your pet from your computer!</p>");return{error:c,errorMessages:b}}return{error:c,errorMessages:b}}function doCompetitionOverlay(a){switch(a){case"upload":showErrorOverlay(["<p>Oops! Sorry, we didn't get your file :( It might be that you need to make the filesize smaller.</p>"],function(){return});break;case"db":showErrorOverlay(["<p>Oops! Sorry, our pen ran out when taking your entry :(</p>"],function(){return});break;case"success":showOverlay("<p>Thanks for your entry!</p><p>Check back soon to see if you are a winner!</p>","close",function(){return});break}}function competitionEntryCheck(d,e,f,i,b,h,a){var c=false;var g=[];if(d==""){c=true;g.push("<p>Oops! You need to tell us your name!</p>");return{error:c,errorMessages:g}}if(e==""){c=true;g.push("<p>Oops! You need to tell us your parent's email!</p>");return{error:c,errorMessages:g}}else{if(!isValidEmail(e)){c=true;g.push("<p>Oops! Your parent's email address doesn't appear to be quite right.</p>");return{error:c,errorMessages:g}}}if(f==""){c=true;g.push("<p>Oops! You need to tell us your parent's address!</p>");return{error:c,errorMessages:g}}if(i==""){c=true;g.push("<p>Oops! You need to tell us your parent's postcode!</p>");return{error:c,errorMessages:g}}if(!b){c=true;g.push("<p>Oops! You need to tell us that you've got your parent's permission to enter!</p>");return{error:c,errorMessages:g}}if(h==""){c=true;g.push("<p>Oops! You forgot to write your entry!</p>");return{error:c,errorMessages:g}}if(a.length){if(a.val()==""){c=true;g.push("<p>Oops! You need to pick your entry from your computer!</p>");return{error:c,errorMessages:g}}}return{error:c,errorMessages:g}}function initEntrySlider(b){var a={options:null,slideIndex:0,holder:$(".holder"),setHolderWidth:function(){this.holder.width(this.options.slideWidth*this.options.numSlides)},nextSlide:function(){this.slideIndex++;if(this.slideIndex>=this.options.numSlides){this.slideIndex=0}var c=this.slideIndex*this.options.slideWidth*-1;this.holder.animate({left:c},{duration:500,easing:"swing"})}};$(".next").bind("click",function(){a.nextSlide();return false});a.options=b||{slideWidth:411,numSlides:2};a.setHolderWidth();return a}function messageEntryCheck(d,a){var c=false;var b=[];if(d==""){c=true;b.push("<p>Oops! You need to tell us your name!</p>");return{error:c,errorMessages:b}}if(a==""){c=true;b.push("<p>Oops! You need to fill out a message!</p>");return{error:c,errorMessages:b}}return{error:c,errorMessages:b}}function submitMessage(){var a={act:"add_message",name:$("#name").val(),message:$("#message").val()};$.ajax("/api",{data:a,dataType:"json",type:"POST",success:function(d,e,c){console.log("AJAX response = "+e);if(d.success){var b="<p>Thanks for the message! We'll read it and maybe add it to the site!</p>";showOverlay(b,"close",function(){return});return}console.log("API error = "+d.toString());showErrorOverlay(["<p>Oops! Sorry, our pen ran out when writing down your message :(</p>"],function(){return})},error:function(b,d,c){console.log("AJAX error: "+d+" - "+c);showErrorOverlay(["<p>Oops! Sorry, we couldn't find any paper to write down your message :( We' rushing around to find some now.</p>"],function(){return})}})}function newsletterSignupCheck(d,a){var c=false;var b=[];if(d==""){c=true;b.push("<p>Oops! You need to tell us your email!</p>");return{error:c,errorMessages:b}}else{if(!isValidEmail(d)){c=true;b.push("<p>Oops! Your email address doesn't appear to be quite right.</p>");return{error:c,errorMessages:b}}}if(!a){c=true;b.push("<p>Oops! You need to tell us that you've read and agreed to the privacy policy.</p>");return{error:c,errorMessages:b}}return{error:c,errorMessages:b}}function newsletterOptionCheck(c,a,b){if(!c&&!a&&!b){return{error:true,errorMessages:["<p>Oops! You need to tell us what you are interested in receiving!</p>"]}}return{error:false,errorMessages:""}}function isValidEmail(a){var b=/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/;return b.test(a)}function showChoiceOverlay(){var a='<p>I\'d like to receive<br>information about:</p><p>Groovy Chick and Friends <input type="checkbox" id="groovy" name="groovy"><br>FABric Animals <input type="checkbox" id="fab" name="fab"><br>Classic Animals <input type="checkbox" id="classic" name="classic"></p>';showOverlay(a,"send",function(){var b=newsletterOptionCheck($("#groovy").attr("checked"),$("#fab").attr("checked"),$("#classic").attr("checked"));if(b.error){showErrorOverlay(b.errorMessages,showChoiceOverlay)}else{if($("#groovy").attr("checked")){$("#info_groovy").val(1)}if($("#fab").attr("checked")){$("#info_fab").val(1)}if($("#classic").attr("checked")){$("#info_classic").val(1)}$("#newsletterform").submit()}})}function showThanksOverlay(){var a="<p>Thanks for signing up!</p><p>We'll be in touch really soon!</p>";showOverlay(a,"close",function(){return})}function showErrorOverlay(a,c){var b=a.join("");b+="<p>Please try again!</p>";showOverlay(b,"close",c)}function showOverlay(e,c,d){$("#overlay div").html(e);var b=$("#overlay a");b.css("background-image","url(/img/overlay-"+c+".png)");b.unbind("click");b.bind("click",function(){$("#overlay").fadeOut(d);return false});$("#overlay").fadeIn()}function getStarSignsObject(a){var b={rgStars:[],chosen:[0,0],rgButtons:[],setStars:function(c){this.rgStars=c;for(var d in this.rgStars){this.rgStars[d].id=d}this.chooseStars()},chooseStars:function(){var c=[];for(var d in this.rgStars){c.push(d)}this.chosen[0]=c.splice(Math.round(Math.random()*(c.length-1)),1);this.chosen[1]=c.splice(Math.round(Math.random()*(c.length-1)),1)},init:function(){var c=this;$("#stars_list a").each(function(d,f){c.addButton($(f))});this.updateButtons();this.updateChosen()},addButton:function(e){var d=this;var c={star:null,a:e,parent:d,update:function(f){this.star=f;this.a.html(this.star.name)},clicked:function(){this.parent.buttonClicked(this)}};e.bind("click",function(){c.clicked();return false});this.rgButtons.push(c)},buttonClicked:function(d){var c=this.chosen.shift();this.chosen.push(d.star.id);this.updateButtons();this.updateChosen()},updateButtons:function(){var c=this.getUnchosen();for(var d in c){this.rgButtons[d].update(c[d])}},getUnchosen:function(){var c=[];for(var d in this.rgStars){if((d==this.chosen[0])||(d==this.chosen[1])){continue}c.push(this.rgStars[d])}return c},updateChosen:function(){$(".star_holder.first h2").html(this.rgStars[this.chosen[0]].name);$(".star_holder.first .animal").attr("src",this.rgStars[this.chosen[0]].animal_image_path);$(".star_holder.first .day").attr("src",this.rgStars[this.chosen[0]].day_image_path);$(".star_holder.first .colour").attr("src",this.rgStars[this.chosen[0]].colour_image_path);$(".star_holder.first .number").attr("src",this.rgStars[this.chosen[0]].number_image_path);$(".star_holder.second h2").html(this.rgStars[this.chosen[1]].name);$(".star_holder.second .animal").attr("src",this.rgStars[this.chosen[1]].animal_image_path);$(".star_holder.second .day").attr("src",this.rgStars[this.chosen[1]].day_image_path);$(".star_holder.second .colour").attr("src",this.rgStars[this.chosen[1]].colour_image_path);$(".star_holder.second .number").attr("src",this.rgStars[this.chosen[1]].number_image_path)}};b.setStars(a);return b}function initQuiz(b){var a={options:null,answers:{a:0,b:0,c:0},slideIndex:0,numSlides:9,holder:$(".holder"),optionChosen:function(c){this.answers[c]++;this.nextSlide()},nextSlide:function(){this.slideIndex++;if(this.slideIndex==(this.numSlides-1)){this.showOutcome()}if(this.slideIndex>=this.numSlides){this.slideIndex=0;this.answers={a:0,b:0,c:0}}var c=this.slideIndex*this.options.slideWidth*-1;this.holder.animate({left:c},{duration:800,easing:"swing"})},showOutcome:function(){var d={key:null,val:null};for(var c in this.answers){if(this.answers[c]>d.val){d.key=c;d.val=this.answers[c]}}$("#outcome span").hide();$("#outcome span#"+d.key).show()}};$(".play_button").bind("click",function(){a.nextSlide();return false});$("a.a").bind("click",function(){a.optionChosen("a");return false});$("a.b").bind("click",function(){a.optionChosen("b");return false});$("a.c").bind("click",function(){a.optionChosen("c");return false});a.options=b||{slideWidth:300};return a}function getTickerTapeObject(a){var b={rgMessages:["Message 1","Message 2","Longer Message 3 is here"],i:-1,left:0,target:0,p:$("#tickertape p"),startPoint:$("#tickertape div").width()+10,initialHeight:33,addMessages:function(c){this.rgMessages=c},getNextMessage:function(){this.i++;if(this.i>=this.rgMessages.length){this.i=0}return this.rgMessages[this.i]},resizeWidth:function(){do{var c=this.p.width();this.p.width(c+100)}while(this.p.height()>this.initialHeight)},run:function(){this.p.html(this.getNextMessage());this.p.css("left",this.startPoint);this.left=this.startPoint;this.p.width(100);this.resizeWidth();this.target=-this.p.width()-this.startPoint;$(this).animate({left:this.target},{duration:this.target*-15,easing:"linear",step:function(){this.moveTape()},complete:function(){this.run()}})},moveTape:function(){this.p.css("left",this.left)}};if(a.length>0){b.addMessages(a)}return b}function wrapPollImagesInVoteLinks(b){var a=0;$(".poll_item img.pollimage").wrap('<a href="#vote" />');$(".poll_item a").map(function(c,d){var e={pollId:b,option:c+1};$(d).bind("click",function(){doVote(e);return false})})}function doVote(a){$.ajax("/api",{data:{act:"vote",pollId:a.pollId,option:a.option},dataType:"json",type:"POST",success:function(c,d,b){console.log("AJAX response = "+d);if(c.success){displayVoteResults(c.votes,true);return}console.log("API error = "+c.toString())},error:function(b,d,c){console.log("AJAX error: "+d+" - "+c)}})}function displayVoteResults(b,c){var a=convertVotesToPercentages(b);if(c){$(".poll_item a").unbind("click");$(".poll_item img.pollimage").unwrap()}$(".barholder").fadeIn(200,animatePollResults(a))}function convertVotesToPercentages(a){var c=0;for(var b in a){a[b]=(+a[b]);c+=a[b]}if(c==0){return[0,0,0,0]}rgPercents=jQuery.map(a,function(d){return Math.round((d/c)*100)});return rgPercents}function animatePollResults(j){var l=74;var k=Math.max.apply(Math,j);if(k==0){return}var c=j.length;for(var f=0;f<c;f++){var g=(j[f]/k)*l;var a=1000+(Math.random()*2000);var e=f+1;$("#bar_"+e).animate({height:g},a,"swing");var d="#poll_item_"+e+" p";var b={domElement:$(d),val:0};$(b).animate({val:j[f]},{duration:a,easing:"swing",step:function(){var h=Math.ceil(this.val)+"%";this.domElement.text(h)}})}}function randInt(a){return Math.round(Math.random()*a)};
