/* Eight Square Studio 
 * Thomas Cowell
 * tcowell@eightsquarestudio.com
 * http://eightsquarestudio.com
 * Copyright Eight Square Studio 2009 
 * Sept 14, 2009 23:07:43 +0100
*/
/**************************************************************************************************/
var useajax=jQuery.browser.msie?false:true;if(location.pathname.length>1&&useajax){location.replace("/#"+location.pathname+location.hash.replace(/^\#\/?/,""));}esq={lastMenu:new Object(),initializeJS:function(){$("link[name=no_js]").attr("disabled","disabled ");if(useajax){esq.redirectToCorrect();}esq.attachEvents();$('.contact.email').updateEmail(); $("#logo_portfolio .swapper").each(function(){$(this).trigger("mouseout");});esq.updateContainer(true);},attachEvents:function(){$("#logo_portfolio a.swapper").hover(function(){$("#"+$(this).attr("id").replace("logo","list")).find("a:first").addClass("hover");$(this).animate({opacity:1},600);},function(){$("#"+$(this).attr("id").replace("logo","list")).find("a:first").removeClass("hover");$(this).animate({opacity:0},600);});$(".menuBar .button").click(function(){if(!$(this).hasClass("current")){esq.lastMenu=$(".menuBar .button.current").removeClass("current");$(this).addClass("current");esq.checkURL($(this).parent("a").attr("href"));}if(useajax){return false;}});esq.repeatedAttachedEvents();$('#sidebar a:not(.noajax), #blogContent a:not(.noajax)').live("click",function(){esq.checkURL($(this).attr("href"));if(useajax){return false;}});},repeatedAttachedEvents:function(){$(".lightbox").lightbox();$("#portlist ul li").hover(function(){$("#logo_portfolio #"+$(this).attr("id").replace("list","logo")).trigger("mouseenter");},function(){$("#logo_portfolio #"+$(this).attr("id").replace("list","logo")).trigger("mouseleave");});},getLinkViaAjax:function(a){$("#busy_icon").fadeIn("slow");var b=location.hash;jQuery.ajax({type:"GET",url:a,error:function(c,d,f){esq.timedError("There was a problem communicating with the server");},success:function(c){pageTracker._trackPageview(a);location.hash=a;if((/blog|search/).test(a)){if(!(/images\/blog/).test($("#header .fltrgt img").attr("src"))){$("#header .fltrgt img").fadeOut("slow",function(){$(this).attr("src","/images/blog/name.png");$(this).fadeIn("slow");});}esq.blogReplaceContent(c,b);}else{if(/images\/blog/.test($("#header .fltrgt img").attr("src"))){$("#header .fltrgt img").fadeOut("slow",function(){$(this).attr("src","/images/name.png");$(this).fadeIn("slow");});}esq.replaceMainContent(c,b);}}});return false;},timedError:function(a){$("#error_message").html(a);$("#error_message").fadeIn(500);setTimeout("$('#error_message').fadeOut(1000);",3000);$(esq.lastMenu).addClass("current");$("#busy_icon").fadeOut("slow");},replaceMainContent:function(b,a){$(".lightbox").unbind("click");$("#portlist ul li").unbind("hover");if(/blog|search/.test(a)){$("#sidebar, #blogContent div").slideUp(2000,function(){$("#blogContent").hide();$("#mainContent").replaceWith($(b).find("#mainContent"));$('#mainContent').find('.contact.email').updateEmail();esq.repeatedAttachedEvents();$("#logo").show();$("#logo").children().slideDown(1000);$("#mainContent").slideDown(1000,function(){esq.updateContainer(true);$("#busy_icon").fadeOut("slow");});});}else{$("#mainContent").fadeOut(200,function(){$("#mainContent").replaceWith($(b).find("#mainContent"));$('#mainContent').find('.contact.email').updateEmail();esq.repeatedAttachedEvents();$("#mainContent").fadeIn(200,function(){$("#busy_icon").fadeOut("slow");});});}},blogReplaceContent:function(b,a){if(/blog|search/.test(a)&&$("#blogContent").length==1){$("#blogContent").fadeOut(200,function(){$("#container").animate({top:"10px"},500);$("#blogContent").replaceWith($(b).find("#blogContent"));$("#blogContent").fadeIn(200);});}else{$("#logo").children().slideUp(1000,function(){$("#logo").hide();});$("#mainContent").slideUp(1000,function(){if($("#sidebar").length==0){$("<div/>").attr({id:"sidebar",style:"display:none;"}).insertAfter("#mainContent");}if($("#blogContent").length==0){$("<div/>").attr({id:"blogContent",style:"display:none;"}).insertAfter("#sidebar");}$("#sidebar").replaceWith($(b).find("#sidebar"));$("#blogContent").replaceWith($(b).find("#blogContent"));$("#container").animate({top:"10px"},500);$("#sidebar, #blogContent div").slideDown(1000);});}$("#busy_icon").fadeOut("slow");},checkURL:function(a){if(!(/http:\/{2}w{0,3}\.\w+\.\w+/).test(a)){if(a!=null&&useajax){esq.getLinkViaAjax(a);}return true;}},redirectToCorrect:function(){if(location.hash.length>2){$(".button.current").removeClass("current");$(".menuBar a:not(:last)").each(function(){test=new RegExp($(this).attr("href").replace(/\//g,""));if(test.test(location.hash)){$(this).children(".button").addClass("current");}});if($(".button.current").length==0){$(".button:last").addClass("current");}$(document.body).show();esq.checkURL(location.hash.replace(/\#/,""));}else{$(document.body).show();$("#mainContent").fadeIn(800);$("#busy_icon").fadeOut("slow");}},updateContainer:function(a){$("#container").centerInWindow(a);}};jQuery.fn.timedHeight=function(){var a=$(this).outerHeight()*3.2;return a;};jQuery.fn.findOrCreateById=function(a,b){if($(this).find("#"+a).length==0){$("<div/>").attr("id",a).appendTo(this);if(typeof(b)=="function"){b();}}};jQuery.fn.centerInWindow=function(a){var d=Math.floor(Math.max(((($(window).height()-$(this).outerHeight())/2)-$(this).offset().top),0));var c=Math.floor(Math.max(((($(window).width()-$(this).outerWidth())/2)-$(this).offset().left),0));var b=useajax?500:1;if(a){$(this).animate({top:d+"px",left:c+"px"},b);}else{$(this).css({top:d+"px",left:c+"px"});}};jQuery.fn.updateEmail=function(){var email=[ 'mail','eightsquarestudio{dot}com' ];email=email.join('@');email=email.replace('{dot}','.');this.html(this.find('img'));this.append("<a href='mailto:"+email+"?subject=webquery' >"+email+"</a>");};$(document).ready(esq.initializeJS);$(window).resize(esq.updateContainer);