/*
	Better Things website script
	by Jason Crosse (c) 2010 Antanova.com
	Requires jQuery 1.4
*/
(function(){function a(){this.twitterName="Better_Things";this.WORK=1;this.THOUGHTS=2;this.LIKE=4;this.TWEETS=8;this.aState=this.WORK+this.THOUGHTS+this.LIKE+this.TWEETS;this.shareThisSuffix="";this.init()}a.prototype={init:function(){if($.browser.msie&&(parseInt($.browser.version)<8)){$("#contentholder .skillsblock p").each(function(){var c=$(this).html();var b=c.replace(/ /g,"&nbsp;");$(this).html(b)})}$(document).ready(function(){try{if(Typekit){}}catch(b){}});$("#nall, #prevpage, #nextpage, #header h1 a").click(function(){document.cookie="antanova="+(antanova.WORK+antanova.THOUGHTS+antanova.LIKE+antanova.TWEETS)+"; path=/"});$(window).load(function(){$("img.roll, input.roll").each(function(){var d=$(this).attr("src");var b=d.replace(/(^.+)(\.\w{3,4}$)/i,"$1-o$2");var c=$("<img />");$(c).attr("src",b);$(this).data("newsrc",b);$(this).hover(function(){var e=$(this);e.data("oldsrc",e.attr("src"));e.attr("src",e.data("newsrc"))},function(){var e=$(this);e.attr("src",e.data("oldsrc"))});$(this).click(function(){var e=$(this);e.attr("src",e.data("oldsrc"))})})})},home:function(){$("#nav img").not("#nall img").each(function(){var h=$(this);var f=$("<img />");var g=h.attr("src").replace(/(^.+)(\.\w{3,4}$)/i,"$1-n$2");$(f).attr("src",g)});$("#nav a").not("#nall").data("active",true);if(document.cookie.match(/\bantanova= ?\d+/gi)){var c=document.cookie.match(/\bantanova= ?\d+/gi);var b=c[0].match(/\d+/i);this.aState=parseInt(b);if(!(this.WORK&this.aState)){$("#nwork, #nworktick").data("active",false);$("#contentholder .category-our-work").stop(true,true).hide(antanova._checkVisible)}if(!(this.THOUGHTS&this.aState)){$("#nthoughts, #nthoughtstick").data("active",false);$("#contentholder .category-our-thoughts").stop(true,true).hide(antanova._checkVisible)}if(!(this.LIKE&this.aState)){$("#nlike, #nliketick").data("active",false);$("#contentholder .category-what-we-like").stop(true,true).hide(antanova._checkVisible)}if(!(this.TWEETS&this.aState)){$("#ntweets, #ntweetstick").data("active",false);$("#contentholder .category-tweets").stop(true,true).hide(antanova._checkVisible)}$("#nav a").not("#nall").each(function(){if($(this).data("active")==false){$(this).children("img").each(function(){if(!this.src.match(/\-n\.\w{3,4}$/i)){this.src=this.src.replace(/(\.\w{3,4})$/i,"-n$1")}})}})}else{document.cookie="antanova="+(this.WORK+this.THOUGHTS+this.LIKE+this.TWEETS)+"; path=/"}$("#nav a").not("#nall").hover(function(){if(!$(this).attr("id").match(/tick$/i)){var g=$(this);var f="#"+g.attr("id")+"tick";$("#nav a").not("#nall").not(f).not(g).children("img").each(function(){var h=$(this);h.attr("src",h.attr("src").replace(/(\-n)?(\.\w{3,4})$/i,"-n$2"))});$(f).add(this).children("img").each(function(){var h=$(this);h.attr("src",h.attr("src").replace(/(\-n)?(\.\w{3,4})$/i,"$2"))})}else{if($(this).data("active")){$(this).children("img").each(function(){if(!this.src.match(/\-n\.\w{3,4}$/i)){this.src=this.src.replace(/(\.\w{3,4}$)/i,"-n$1")}});$("#"+$(this).attr("id").replace(/(.+)tick$/i,"$1")).children("img").each(function(){if(!this.src.match(/\-n\.\w{3,4}$/i)){this.src=this.src.replace(/(\.\w{3,4}$)/i,"-n$1")}})}else{$(this).children("img").each(function(){this.src=this.src.replace(/(\-n)(\.\w{3,4}$)/i,"$2")});$("#"+$(this).attr("id").replace(/(.+)tick$/i,"$1")).children("img").each(function(){this.src=this.src.replace(/(\-n)(\.\w{3,4}$)/i,"$2")})}}},function(){$("#nav a").not("#nall").each(function(){if($(this).data("active")==true){$(this).children("img").each(function(){if(this.src.match(/\-n\.\w{3,4}$/i)){this.src=this.src.replace(/(\-n)(\.\w{3,4}$)/i,"$2")}})}else{$(this).children("img").each(function(){if(!this.src.match(/\-n\.\w{3,4}$/i)){this.src=this.src.replace(/(\.\w{3,4})$/i,"-n$1")}})}})});$("#nwork, #nlike, #nthoughts, #ntweets").click(function(){var f=$(this);f.data("active",true);antanova._removeMessage();$("#nav a").not("#nall").not(f).not("#"+f.attr("id")+"tick").data("active",false);$("#"+f.attr("id")+"tick").data("active",true);$("#contentholder .content").not("."+antanova._getCat(f.attr("id"))).stop(true,true).slideUp("slow");$("#contentholder ."+antanova._getCat(f.attr("id"))).stop(true,true).slideDown("slow",antanova._checkVisible);f.children("img").each(function(){$(this).attr("src",$(this).attr("src").replace(/(\-n)(\.\w{3,4}$)/i,"$2"))});$("#"+f.attr("id")+"tick img").each(function(){$(this).attr("src",$(this).attr("src").replace(/(\-n)(\.\w{3,4}$)/i,"$2"))});if(f.attr("id")!="ntweets"){antanova._loadAJAX(antanova._getCat(f.attr("id")))}return false});$("#nav .tick").click(function(){var f=$(this);antanova._removeMessage();if(f.data("active")){$("."+antanova._getCat(f.attr("id").replace(/(.+)tick$/i,"$1"))).stop(true,true).slideUp("slow",antanova._checkVisible);f.data("active",false);var g=f.attr("id").replace(/(.+)tick$/i,"$1");$("#"+g).data("active",false);$("#"+g).add(this).children("img").each(function(){if(!this.src.match(/\-n\.\w{3,4}$/i)){this.src=this.src.replace(/(\.\w{3,4}$)/i,"-n$1")}})}else{$(".removable").slideUp("slow",function(){$(this).remove()});$("."+antanova._getCat(f.attr("id").replace(/(.+)tick$/i,"$1"))).stop(true,true).slideDown("slow",antanova._checkVisible);f.data("active",true);var g=f.attr("id").replace(/(.+)tick$/i,"$1");$("#"+g).data("active",true);$("#"+g).add(this).children("img").each(function(){this.src=this.src.replace(/(\-n)(\.\w{3,4})$/i,"$2")})}antanova.activeCount=0;antanova.activeId="";$("#nwork, #nlike, #nthoughts, #ntweets").each(function(){var i=$(this);if(i.data("active")==true){antanova.activeCount++;antanova.activeId=i.attr("id")}});if(antanova.activeCount===1){var h="";switch(antanova.activeId){case"nwork":h="category-our-work";break;case"nlike":h="category-what-we-like";break;case"nthoughts":h="category-our-thoughts";break}if(h.length>0){antanova._loadAJAX(h)}}return false});var d=window.location.toString();var e=1;if(d.match(/page\/(\d+)(\/?)$/i)){var e=parseInt(d.match(/\d+(\/?)$/i))}$.getJSON("http://twitter.com/status/user_timeline/"+antanova.twitterName+".json?page="+e+"&callback=?",function(g){$.each(g,function(){$("#contentholder").append('<div class="content category-tweets" style="display:none;" data-time="'+this.created_at+'"><div class="cblock"><div class="tweetlink"><a href="http://twitter.com/'+antanova.twitterName+"/status/"+this.id+'">&nbsp;</a></div><div class="cblock2"><p>'+antanova.twitify(this.text)+'</p></div><div class="c"><!----></div></div><div class="c bottommargin"><div class="cblock"><!----></div></div></div>')});var f=$("#contentholder .content").get();f.sort(function(i,h){var k=new Date($(i).attr("data-time").replace(/\+\d{4} /i,""));var j=new Date($(h).attr("data-time").replace(/\+\d{4} /i,""));return j.getTime()-k.getTime()});$.each(f,function(h,i){$("#contentholder").append(i)});if(antanova.aState&antanova.TWEETS){if($.browser.msie&&parseInt($.browser.version)<8){$(".category-tweets").stop(true).show(0)}else{$(".category-tweets").stop(true).slideDown("slow",antanova._checkVisible)}}})},singlePage:function(){$("#nav a").not("#nall").children("img").each(function(){$(this).data("oldsrc",this.src);var b=$("<img />");b.attr("src",this.src.replace(/(\-\w)(\.\w{3,4})$/i,"$2"));if(this.src.match(/\-c\.\w{3,4}$/i)){var c=$("<img />");c.attr("src",this.src.replace(/(\-c)(\.\w{3,4})$/i,"-n$2"))}});$("#singleindex").click(function(){var b=window.location.toString().split("/");var c=0;switch(b[3]){case"our-thoughts":c=antanova.THOUGHTS;break;case"our-work":c=antanova.WORK;break;case"what-we-like":c=antanova.LIKE;break;default:c=antanova.WORK+antanova.LIKE+antanova.THOUGHTS+antanova.TWEETS}document.cookie="antanova="+c+"; path=/";window.location="/";return false});$("#nav a").not("#nall").click(function(){var b=0;$("#nwork, #nlike, #nthoughts, #ntweets").children("img").each(function(){if(this.src.match(/\-c\.\w{3,4}$/i)){b+=antanova._getCookieVal($(this).parent().attr("id"))}if(!this.src.match(/\-\w\.\w{3,4}$/i)){b+=antanova._getCookieVal($(this).parent().attr("id"))}});document.cookie="antanova="+b+"; path=/";window.location="/";return false});$("#nav a").not("#nall").hover(function(){if(!$(this).attr("id").match(/tick$/i)){$("#nav a").not("#nall").children("img").each(function(){if(this.src.match(/\-c\.\w{3,4}$/i)){this.src=this.src.replace(/(\-c)(\.\w{3,4}$)/i,"-n$2")}});$(this).children("img").each(function(){this.src=this.src.replace(/\-\w(\.\w{3,4}$)/i,"$1")});$("#"+$(this).attr("id")+"tick").children("img").each(function(){this.src=this.src.replace(/\-n(\.\w{3,4}$)/i,"$1")})}else{$(this).children("img").each(function(){this.src=this.src.replace(/(\-n)(\.\w{3,4}$)/i,"$2")});$("#"+$(this).attr("id").replace(/(.+)tick$/i,"$1")).children("img").each(function(){this.src=this.src.replace(/(\-\w)(\.\w{3,4}$)/i,"$2")});$("#nav a").not("#nall").children("img").each(function(){if(this.src.match(/\-c\.\w{3,4}$/i)){this.src=this.src.replace(/(\-c)(\.\w{3,4}$)/i,"$2");$("#"+$(this).parent().attr("id")+"tick img").each(function(){this.src=this.src.replace(/(\-n)(\.\w{3,4}$)/i,"$2")})}})}},function(){$("#nav a").not("#nall").children("img").each(function(){this.src=$(this).data("oldsrc")})});if(!($.browser.msie&&parseInt($.browser.version)<7)){$("object, embed").unwrap()}},_getCat:function(b){switch(b){case"nwork":return"category-our-work";break;case"nlike":return"category-what-we-like";break;case"nthoughts":return"category-our-thoughts";break;case"ntweets":return"category-tweets";break;default:return"content"}},_checkVisible:function(){if($.browser.msie&&parseInt($.browser.version)<8){return false}antanova._removeMessage();if($("#contentholder .content:visible").length==0){var b=$('<div class="cblock" id="messageempty"><p>You have de-selected all of our categories. It’s kind of zen like this but not so interesting after a while. You can select one or more categories from the navigation bar above, or hit the reload icon to see everything again.</p></div>');$("#contentholder").prepend(b)}},_removeMessage:function(){if($.browser.msie&&parseInt($.browser.version)<8){return false}$("#messageempty").remove()},_loadAJAX:function(b){switch(b){case"category-our-work":break;case"category-our-thoughts":break;case"category-what-we-like":break;default:return false}if(!window.location.toString().match(/page\/\d+\/?$/i)){var c="/category/"+b.replace(/^category\-(.+)/i,"$1");$(".removable").remove();antanova.catName=b;$.get(c,function(f){antanova._removeMessage();var d=$("#contentholder ."+antanova.catName).length;var e=$(f).find(".content").get();while(d<e.length){$(e[d++]).appendTo("#contentholder").addClass("removable")}})}},_getCookieVal:function(d){var b=d.replace(/(.+)tick$/i,"$1");var c=0;switch(b){case"nwork":c+=antanova.WORK;break;case"nlike":c+=antanova.LIKE;break;case"nthoughts":c+=antanova.THOUGHTS;break;case"ntweets":c+=antanova.TWEETS;break}return c},caseStudy:function(){var b=0;this.shareThisSuffix="-grey";$("body").addClass("csbg");$("#item-contentblock h1").after('<p id="cslink" class="cslink"><a href="/category/our-work/">Case Study</a></p>').css({"margin-bottom":"0"});$("#item-contentblock img").prependTo("#item-contentblock").each(function(){$(this).data("order",b++)});$("#item-contentblock img").not(":first-child").css("display","none");$("#item-contentblock img:first-child").addClass("ourworkviewing");if($("#item-contentblock img").length>1){$(".leftarrow").append('<a href="javascript:void(0);"></a>');$(".rightarrow").append('<a href="javascript:void(0);"></a>');if($.browser.msie&&(parseInt($.browser.version)==6)){$(".wp-caption").css("width","20px")}$(".leftarrow a").click(function(){$("#item-contentblock img").css("display","none");if($(".ourworkviewing").data("order")==0){$(".ourworkviewing").each(function(){$(this).removeClass("ourworkviewing")});$("#item-contentblock img").each(function(){if($(this).data("order")==($("#item-contentblock img").length-1)){$(this).fadeIn().addClass("ourworkviewing")}})}else{var c=$(".ourworkviewing").data("order");$(".ourworkviewing").each(function(){$(this).removeClass("ourworkviewing")});$("#item-contentblock img").each(function(){if($(this).data("order")==(c-1)){$(this).fadeIn().addClass("ourworkviewing")}})}return false});$(".rightarrow a").click(function(){$("#item-contentblock img").css("display","none");if($(".ourworkviewing").data("order")==($("#item-contentblock img").length-1)){$(".ourworkviewing").each(function(){$(this).removeClass("ourworkviewing")});$("#item-contentblock img").each(function(){if($(this).data("order")==0){$(this).fadeIn().addClass("ourworkviewing")}})}else{var c=$(".ourworkviewing").data("order");$(".ourworkviewing").each(function(){$(this).removeClass("ourworkviewing")});$("#item-contentblock img").each(function(){if($(this).data("order")==(c+1)){$(this).fadeIn().addClass("ourworkviewing")}})}return false})}},gmap:function(e){var d=new GMap2($(e).get(0));var c=new GLatLng(51.521535,-0.109413);var b=new GMarker(c);d.setCenter(c,14);d.setUIToDefault();d.addOverlay(b);$("#emailaddress").html('<a href="mailto:iwant@better-things.co.uk">iwant@better-things.co.uk</a>');$("#contactform").submit(function(){var f=false;if($("#name").val()==""){$("#name").css({"background-color":"#ffffdd"}).focus()}else{if(!$("#email").val().match(/([\w\d\-\._%]+)@([\w\d\-\.]+)\.\w{2,8}$/i)){$("#name").css({"background-color":"#ffffff"});$("#email").css({color:"#ff0000","background-color":"#ffffdd"}).focus()}else{if($("#message").val()==""){$("#name").css({"background-color":"#ffffff"});$("#email").css({"background-color":"#ffffff",color:"#888888"});$("#message").css({"background-color":"#ffffdd"}).focus()}else{f=true}}}return f})},twitify:function(c){var b=c.replace(/(http|https)(:\/\/)([^ ]+)/ig,'<a href="$1$2$3">$1$2$3</a>');b=b.replace(/@([^ ]+)/gi,'<a href="http://twitter.com/$1">@$1</a>');b=b.replace(/#([^ ]+)/gi,'<a href="http://search.twitter.com/search?q=%23$1">#$1</a>');return b}};window.antanova=new a()})();