/*
Author: Emil Olsson
HTTP: http://emilolsson.com
Twitter: http://twitter.com/emilolsson
*/
var imgList=[];$.extend({preload:function(v,K){var w=$.extend({init:function(){},loaded:function(){},loaded_all:function(){}},K),s=v.length,t=0;w.init(0,s);for(i=0;i<v.length;i++)imgList.push($("<img />").load(function(){t++;w.loaded(this,t,s);t==s&&w.loaded_all(t,s)}).attr("src",v[i]))}});
$(document).ready(function(){function v(){typeof window.history.pushState=="function"?$.ajax({url:f,cache:true,success:function(a){$("#belowInfinity").empty();var b=$(a),a=b.find("#fullInner").html(),b=b.find("#belowInfinity").html();$("#fullInner").append(a).fadeTo(0,1,function(){L()});$("#belowInfinity").append(b);M()}}):window.location.href=f}function K(){var a={page:"1"};typeof window.history.pushState=="function"&&history.pushState(a,"Title 1",f)}function w(){if(typeof window.history.pushState==
"function")f=document.location,ea(),$.ajax({url:""+f+"",cache:true,success:function(a){a=$(a);$("#full, #belowInfinity, #vertNavs, #footer").empty();var b=a.find("#full").html(),c=a.find("#belowInfinity").html(),d=a.find("#vertNavs").html(),e=a.find("#footer").html();y=a.find("#title").text();$("#full").append(b);$("#belowInfinity").append(c);$("#vertNavs").append(d);$("#footer").append(e);L();t();document.title=y}})}function s(){typeof window.history.pushState=="function"?(K(),ea(),$.ajax({url:f,
cache:true,success:function(a){a=$(a);$("#full, #belowInfinity, #vertNavs, #footer").empty();var b=a.find("#full").html(),c=a.find("#belowInfinity").html(),d=a.find("#vertNavs").html(),e=a.find("#footer").html();y=a.find("#title").text();$("#full").append(b);$("#belowInfinity").append(c);$("#vertNavs").append(d);$("#footer").append(e);L();t();document.title=y}})):window.location.href=f}function t(){N=true;e=$(window).height();g=$(window).width();c=0;O=$("#full .toggler:eq(0)").outerHeight();P();z();
fa();A();n=$("#fullInner").attr("name");k=$(".project").length;a=0;o=$(".projectSlideHolder:eq(0) .media").length;Q();R();ga();ha();qa();n=="page"?S():(S(),B());C();T();b=true;D();U();V();W()}function M(){k=$(".project").length;Q();h();P();z();A();R();b=true;D();infinityScroll==false?(a++,l()):(x(),u());U();V();W()}function ha(){n=="page"?$("#header").css({position:"absolute"}):$("#header").css({position:"fixed"})}function ia(){X=0;$(".projectSlideHolder:eq("+a+") .media").each(function(a){a<c&&a>
-1&&(ja[a]=$(this).width()+imagePadding,X+=ja[a])})}function P(){$(".gvideo").gVideo({})}function E(){$("video").each(function(){$(this).hasClass("play")&&$(this).parent().find(".ghinda-video-controls .ghinda-video-play").trigger("click")})}function V(){(function(a){a.fn.hasScrollBar=function(){return this.get(0).scrollHeight>this.height()}})(jQuery);$(".commentsBoxy").mouseover(function(){$(this).each(function(){$(this).hasScrollBar()==true?S():B()})});$(".commentsBoxy").mouseleave(function(){B()})}
function fa(){$("video").each(function(){e=$(window).height();g=$(window).width();$(this).width();$(this).height();ka=$(this).attr("name");d=e-paddingFix-menuPadding>=maxHeight?maxHeight:e-paddingFix-menuPadding;myWidth=d*ka;$(this).height(d).width(myWidth)})}function z(){e-paddingFix-menuPadding-25>=maxHeight?(d=maxHeight,$(".media, .media img").height(d),$(".fallback").height(d-menuPadding*2),$(".projectInfo, .commentsBoxy").height(d),$(".projectBottom, .counter, .toggler, .projectEdit").css({"margin-top":""+
d-menuPadding*1-O-34+"px"}),$(".projectSeparator").width(g-menuPadding-menuPadding).css({"margin-top":""+(d+menuPadding+menuPadding)+"px","margin-left":""+menuPadding+"px"}),$("#headerInner").width(g-menuPadding-menuPadding),$(".projectSlideHolder, .project").width(g).height(maxHeight+menuPadding*4)):(d=e-paddingFix-25-menuPadding*1,$(".media, .media img").height(d),$(".fallback").height(d-menuPadding*2),$(".projectInfo, .commentsBoxy").height(d),$(".projectBottom, .counter, .toggler, .projectEdit").css({"margin-top":""+
d-menuPadding*1-O-34+"px"}),$(".projectSeparator").width(g-menuPadding-menuPadding).css({"margin-top":""+(d+menuPadding+menuPadding)+"px","margin-left":""+menuPadding+"px"}),$("#headerInner").width(g-menuPadding-menuPadding),$(".projectSlideHolder, .project").width(g).height(e-paddingFix+menuPadding*3));$("#page, #footerInner").width(g-menuPadding*2)}function la(){setSingleCount=$(".projectSlideHolder:eq("+a+")").attr("name");setSingleCount++;$(".counter:eq("+a+")").html(setSingleCount+"/"+o)}function R(){$(".project").each(function(){var a=
$(this).find(".media").length,b=$(this).find(".projectSlideHolder").attr("name"),b=parseInt(b);b++;$(this).find(".counter").html(""+b+"/"+a+"")})}function T(){$("#footer").css({position:"static"});footerPosition=$("#footer").position().top;e-menuPadding*4>footerPosition?$("#footer").css({position:"fixed",left:"0",bottom:"0","z-index":"6000"}):$("#footer").css({position:"static","margin-top":""+menuPadding*2+"px"})}function Q(){$(".project").each(function(a){$(this).attr("id","project_"+a+"")})}function Y(){$(document).bind("keydown",
function(a){if(a.keyCode==40||a.keyCode==39||a.keyCode==38||a.keyCode==37)a.preventDefault(),a.keyCode==40?b==true&&F():a.keyCode==39?b==true&&(h(),m==true?G():l()):a.keyCode==38?b==true&&Z():a.keyCode==37&&b==true&&ma()});$(document).bind("keydown",function(a){(a.keyCode==40||a.keyCode==38||a.keyCode==39||a.keyCode==37)&&a.preventDefault()})}function na(){$(document).unbind("keyup");$(document).unbind("keydown")}function W(){n=="journal"&&$(".projectInfo").removeClass("off").addClass("on");n=="singeljournal"&&
$(".projectInfo").removeClass("off").addClass("on");A()}function ra(){var a=$("#overview"),b=a.find(".visual");firstTime=true;$(window).smartresize(function(){var c=a.width(),d=c/Math.floor(c/220);b.each(function(){var a=$(this),b=a.data("fool");a.css({width:Math.floor(d*b)},{queue:false})});a.imagesLoaded(function(){a.masonry({itemSelector:".visual",isResizable:false,columnWidth:d,isAnimated:false,animationOptions:{duration:250,easing:"easeInOutSine",queue:false}})});firstTime=false}).smartresize()}
function A(){$(".projectInfo").each(function(b){$(this).hasClass("on")?(p=$(this).parent().find(".toggler").outerWidth(),q=$(this).parent().find(".counter").outerWidth(),$(this).parent().find(".projectEdit").outerWidth(),$(this).parent().find(".projectInfo").animate({left:0},0,transitionEase,function(){}),$(this).parent().find(".toggler").html("&#9664; Info").animate({left:menuModulWidth*2+imagePadding*1-p},0,transitionEase,function(){}),$(this).parent().find(".counter").animate({left:menuModulWidth*
2+menuPadding*2+imagePadding},0,transitionEase,function(){}),$(this).parent().find(".projectEdit").animate({left:menuPadding},0,transitionEase,function(){}),$(this).parent().find(".commentsBoxy").hasClass("on")?$(".projectSlideHolderInner:eq("+b+")").animate({paddingLeft:(menuModulWidth*2+imagePadding)*2},0,transitionEase,function(){}):$(".projectSlideHolderInner:eq("+b+")").animate({paddingLeft:menuModulWidth*2+imagePadding},0,transitionEase,function(){})):(p=$(this).parent().find(".toggler").outerWidth(),
q=$(this).parent().find(".counter").outerWidth(),$(this).parent().find(".projectEdit").outerWidth(),fixSpeed=$(".commentsBoxy:eq("+a+")").hasClass("on")?horizontalTransitionSpeed:0,$(this).parent().find(".commentsBoxy").animate({left:-(imagePadding+menuModulWidth*3)},fixSpeed,transitionEase,function(){$(this).parent().find(".projectInfo,").animate({left:-(imagePadding+menuModulWidth*2)},fixSpeed,transitionEase,function(){});$(this).parent().find(".toggler").html("Info &#9654;").animate({left:q+menuPadding*
3},fixSpeed,transitionEase,function(){});$(this).parent().find(".counter").animate({left:menuPadding*2},fixSpeed,transitionEase,function(){});$(this).parent().find(".projectEdit").animate({left:menuPadding*4+p+q},fixSpeed,transitionEase,function(){});$(".projectSlideHolderInner:eq("+b+")").animate({paddingLeft:0},0,transitionEase,function(){})}))})}function sa(){p=$(".project:eq("+a+")").find(".toggler").outerWidth();q=$(".project:eq("+a+")").find(".counter").outerWidth();$(".project:eq("+a+")").find(".projectEdit").outerWidth();
fixSpeed=$(".commentsBoxy:eq("+a+")").hasClass("on")?horizontalTransitionSpeed:0;$(".project:eq("+a+")").find(".projectInfo").removeClass("on");$(".project:eq("+a+")").find(".projectInfo").addClass("off");$(".project:eq("+a+")").find(".commentsBoxy").animate({left:0},fixSpeed,transitionEase,function(){$(".project:eq("+a+")").find(".projectInfo,").animate({left:-(imagePadding+menuModulWidth*2)},horizontalTransitionSpeed,transitionEase,function(){});$(".project:eq("+a+")").find(".toggler").html("Info &#9654;").animate({left:q+
menuPadding*3},horizontalTransitionSpeed,transitionEase,function(){});$(".project:eq("+a+")").find(".counter").animate({left:menuPadding*2},horizontalTransitionSpeed,transitionEase,function(){});$(".project:eq("+a+")").find(".projectEdit").animate({left:menuPadding*4+p+q},horizontalTransitionSpeed,transitionEase,function(){});$(".projectSlideHolderInner:eq("+a+")").animate({paddingLeft:0},horizontalTransitionSpeed,transitionEase,function(){})});$(".commentsBoxy:eq("+a+")").hasClass("on")&&($(".project:eq("+
a+")").find(".commentsBoxy").removeClass("on"),$(".project:eq("+a+")").find(".commentsBoxy").addClass("off"),$(".projectSlideHolderInner:eq("+a+")").animate({paddingLeft:menuModulWidth*2+imagePadding},fixSpeed,transitionEase,function(){}));$(".commentsBoxy:eq("+a+")").animate({left:-(imagePadding+menuModulWidth*2)},0,transitionEase,function(){})}function ta(){p=$(".project:eq("+a+")").find(".toggler").outerWidth();q=$(".project:eq("+a+")").find(".counter").outerWidth();$(".project:eq("+a+")").find(".projectEdit").outerWidth();
$(".project:eq("+a+")").find(".projectInfo").removeClass("off");$(".project:eq("+a+")").find(".projectInfo").addClass("on");$(".project:eq("+a+")").find(".projectInfo").animate({left:0},horizontalTransitionSpeed,transitionEase,function(){});$(".project:eq("+a+")").find(".toggler").html("&#9664; Info").animate({left:menuModulWidth*2+imagePadding*1-p},horizontalTransitionSpeed,transitionEase,function(){});$(".project:eq("+a+")").find(".counter").animate({left:menuModulWidth*2+menuPadding*2+imagePadding},
horizontalTransitionSpeed,transitionEase,function(){});$(".project:eq("+a+")").find(".projectEdit").animate({left:menuPadding},horizontalTransitionSpeed,transitionEase,function(){});$(".projectSlideHolderInner:eq("+a+")").animate({paddingLeft:menuModulWidth*2+imagePadding},horizontalTransitionSpeed,transitionEase,function(){})}function ua(){$(".commentsBoxy:eq("+a+")").removeClass("off");$(".commentsBoxy:eq("+a+")").addClass("on");$(".projectInfo:eq("+a+")").hasClass("on")&&($(".project:eq("+a+")").find(".commentsBoxy").animate({left:0},
0,transitionEase,function(){}),$(".project:eq("+a+")").find(".commentsBoxy").animate({left:menuModulWidth*2+menuPadding+imagePadding},horizontalTransitionSpeed,transitionEase,function(){}));$(".projectSlideHolderInner:eq("+a+")").animate({paddingLeft:(imagePadding+menuModulWidth*2)*2},horizontalTransitionSpeed,transitionEase,function(){})}function va(){$(".commentsBoxy:eq("+a+")").removeClass("on");$(".commentsBoxy:eq("+a+")").addClass("off");$(".project:eq("+a+")").find(".commentsBoxy").animate({left:-menuPadding},
horizontalTransitionSpeed,transitionEase,function(){});$(".projectSlideHolderInner:eq("+a+")").animate({paddingLeft:imagePadding+menuModulWidth*2},horizontalTransitionSpeed,transitionEase,function(){})}function wa(){$("#loader").fadeTo(verticalTransitionSpeed,0,transitionEase,function(){$(this).hide()})}function xa(){$("#loaderIcon").fadeTo(verticalTransitionSpeed,0,transitionEase,function(){$(this).remove()})}function L(){$("#blocker").fadeTo(verticalTransitionSpeed/2,0,function(){$("#blocker").hide()})}
function ea(){$("#blocker").fadeTo(verticalTransitionSpeed/2,1,function(){})}function oa(){a<k&&a>-1&&b==true&&(b=false,E(),j=$(".projectSlideHolder:eq("+a+")").height(),$(window).scrollTo(".project:eq("+a+")",whenFinishedBodyScrollSpeed,{easing:"easeInOutExpo",offset:-(headerInnerHeight+menuPadding+menuPadding),axis:"y",onAfter:function(){b=true;x();u()}}))}function H(){a<k&&a>-1&&b==true&&(b=false,E(),j=$(".projectSlideHolder:eq("+a+")").height(),$(window).scrollTo(".project:eq("+a+")",verticalTransitionSpeed,
{easing:"easeInOutExpo",offset:-(headerInnerHeight+menuPadding+menuPadding),axis:"y",onAfter:function(){b=true;x();u()}}))}function ya(){a<k&&a>-1&&b==true&&(b=false,$(window).scrollTo(".project:eq("+a+")",0,{easing:"easeInOutExpo",offset:-(headerInnerHeight+menuPadding+menuPadding),axis:"y",onAfter:function(){b=true;x();u()}}))}function Z(){a<k&&a>0&&b==true?(aa==true?aa=false:a--,H()):a<k&&a>-1&&b==true&&H()}function F(){a<k-1&&a>-1&&b==true?(a++,H()):b==true&&za()}function l(){b==true&&H()}function za(){b=
false;$("html, body").animate({scrollTop:$(document).height()-$(window).height()},verticalTransitionSpeed,function(){aa=b=true})}function Aa(){b=false;E();$("html, body").animate({scrollTop:0},verticalTransitionSpeed,transitionEase,function(){b=true;C()})}function qa(){b=false;$("html, body").animate({scrollTop:0},0,transitionEase,function(){b=true;C()})}function I(){if(b==true)b=false,J==true?fifty=moveSpeed=0:(ba==true?(moveSpeed=horizontalTransitionSpeed*1.5,ba=false):moveSpeed=horizontalTransitionSpeed,
fifty=150),o=$(".projectSlideHolder:eq("+a+") .media").length,c=$(".projectSlideHolder:eq("+a+")").attr("name"),$(".projectSlideHolder:eq("+a+")").attr("name",""+c+""),$(".projectInfo:eq("+a+")").hasClass("on")&&(thisOffset=-(menuModulWidth*2+imagePadding)),$(".projectInfo:eq("+a+")").hasClass("off")&&(thisOffset=0),$(".commentsBoxy:eq("+a+")").hasClass("on")&&(thisOffset=-(menuModulWidth*2+imagePadding)*2),E(),la(),ia(),moveIt=X,$("#delay").fadeTo(0,0).fadeTo(fifty,1,function(){$(".projectSlideHolder:eq("+
a+")").animate({scrollLeft:moveIt+"px"},moveSpeed,transitionEase,function(){b=true;J=false;ca==true&&afterLastSlide=="next"&&(F(),ca=false)})})}function D(){var b=$(".projectSlideHolder").length;tempIndex=a;$(".projectSlideHolder").each(function(c){a=c;J=true;I();c==b-1&&(a=tempIndex,J=false)})}function ma(){c=$(".projectSlideHolder:eq("+a+")").attr("name");o=$(".projectSlideHolder:eq("+a+") .media").length;c<o&&c>0&&b==true&&(c--,$(".projectSlideHolder:eq("+a+")").attr("name",""+c+""),h(),m==true?
(I(),Ba()):l())}function G(){c=$(".projectSlideHolder:eq("+a+")").attr("name");o=$(".projectSlideHolder:eq("+a+") .media").length;c<o-1&&c>-1?b==true&&(c++,$(".projectSlideHolder:eq("+a+")").attr("name",""+c+""),h(),m==true?(I(),Ca()):l()):b==true&&(c=0,ba=true,$(".projectSlideHolder:eq("+a+")").attr("name",""+c+""),ca=true,h(),m==true?(I(),Da()):l())}function Da(){var b=$(".project:eq("+a+")").find(".active"),c=$(".project:eq("+a+")").find(".projectSlide:first");setTimeout(function(){b.fadeTo(250,
0.25);b.removeClass("active");c.addClass("active");c.fadeTo(250,1)},moveSpeed+100)}function Ba(){var b=$(".project:eq("+a+")").find(".active");setTimeout(function(){b.fadeTo(250,0.25);b.prev().fadeTo(250,1);b.prev().addClass("active");b.removeClass("active")},moveSpeed+100)}function Ca(){var b=$(".project:eq("+a+")").find(".active");setTimeout(function(){b.fadeTo(250,0.25);b.next().fadeTo(250,1);b.next().addClass("active");b.removeClass("active")},moveSpeed+100)}function U(){$(".project .projectSlideHolderInner").each(function(){$(".projectSlide",
this).css({opacity:"0.2"});$(".projectSlide:first",this).addClass("active");$(".active",this).css({opacity:"1"})})}function B(){bindMouseWheel==true&&$("body").bind("mousewheel",function(a,b,c,d){a.preventDefault();d>0?Z():d<0&&F();return false})}function S(){$("body").unbind("mousewheel")}function u(){whenFinishedBodyScroll=="adjust"&&bindMouseWheel==false&&$(window).bind("scrollstop",function(){x();b==true&&(indexFix=a==0?1:a,da==k-1?r>0&&r<j*indexFix?oa():u():r>0&&r-j/2<j*indexFix?oa():u())})}
function x(){whenFinishedBodyScroll=="adjust"&&bindMouseWheel==false&&$(window).unbind("scrollstop")}function C(){j=$(".project:eq("+a+")").height();r=$(window).scrollTop();a=(r+e/2)/j;a=Math.floor(a);da=r/j;da=Math.floor(a);o=$(".projectSlideHolder:eq("+a+") .media").length;n=="page"?$(".goUp").hide():a==0?$(".goUp").hide():$(".goUp").show()}function h(){j=$(".projectSlideHolder:eq("+a+")").height();isScrollAligned=r/j;var b=Math.round(isScrollAligned);m=isScrollAligned==b?true:false}function ga(){infinityScroll==
true&&$("#fullInner").infinitescroll({navSelector:"#nav",nextSelector:"#navHidden a:first",itemSelector:"#fullInner div.project, #fullInner #overview .visual",debug:false,loadingImg:""+stylesheetDir+"/images/ajjax-loader.gif",loadingText:"",loadingMsgRevealSpeed:0,animate:false,extraScrollPx:0,donetext:"",bufferPx:e/2,errorCallback:function(){M()},localMode:true},function(){M()})}function pa(){e=$(window).height();g=$(window).width();h();z();T();b==true&&ya()}var n=$("#fullInner").attr("name"),e=
$(window).height(),g=$(window).width(),d=0,c=0,o=$(".projectSlideHolder:eq(0) .media").length,k=$(".project").length,a=0,da=0,J=false,f="";$(".projectSlide:eq(0) img").width();$.getScrollbarWidth();var O=$("#full .toggler:eq(0)").outerHeight(),ca=false,p=$(".toggler:eq(0)").outerWidth(),q=$(".counter:eq(0)").outerWidth();$(".projectEdit:eq(0)").outerWidth();$("#footer").height();var j=$(".project:eq(0)").height();$(".image img").each(function(){$(this).attr("src")});var b=false,y="",N=false;window.onpopstate=
function(){N==true&&w();N=true};ha();var ja=[],X=0;ia();P();V();var ka=0;z();la();R();T();Q();Y();$("input, textarea, select").live("focus",function(){na()});$("input, textarea, select").live("blur",function(){Y()});W();n=="page"&&ra();A();$(".tt-dropdown").change(function(a){a.preventDefault();f=$(this).val();s();$(this).find("option:selected").removeAttr("selected");$(this).find("option:eq(0)").attr("selected","selected")});$("a.history, .dropdown-layers-drop a, .projectCats a, .projectTags a").live("click",
function(a){a.preventDefault();f=$(this).attr("href");s()});$(".dropdown-layers-drop").hide();$(".dropdown-layers").live("mouseover mouseout",function(a){a.type=="mouseout"?$(this).find(".dropdown-layers-drop").hide():$(this).find(".dropdown-layers-drop").show()});$("#navInnerForward").live("click",function(){$("#navHidden a").trigger("click")});$("#navHidden a").live("click",function(a){a.preventDefault();$("#navInnerForward").html("Loading...");f=$("#navHidden a").attr("href");v()});$(".image").live("click",
function(){var b=$(this).parent().parent().parent().attr("id");a=b=b.substr(8);h();m==true?G():l()});$(".cvideo").live("click",function(){var b=$(this).parent().parent().parent().parent().parent().attr("id");a=b=b.substr(8);h();m==true?G():l()});$("#fullInner .slideRight").live("click",function(){a=$("#fullInner .slideRight").index(this);h();m==true?G():l()});$("#fullInner .slideLeft").live("click",function(){a=$("#fullInner .slideLeft").index(this);h();m==true?ma():l()});$("#fullInner .toggler").live("click",
function(){a=$("#fullInner .toggler").index(this);c=$(".projectSlideHolder:eq("+a+")").attr("name");$(this).parent().find(".projectInfo").hasClass("on")?sa():ta()});$("#fullInner .commentsTrigger").live("click",function(){a=$("#fullInner .commentsTrigger").index(this);$(".commentsBoxy:eq("+a+")").hasClass("off")?ua():va()});$("#slideUp").live("click",function(){Z()});$("#slideDown").live("click",function(){F()});$(".goUp").live("click",function(){Aa()});var aa=false,ba=false;U();n!="page"&&B();u();
var r=$(window).scrollTop(),m=true;(function(){$(window).bind("scroll",function(){C()})})();ga();$(document).ajaxStart(function(){b=false;na();$(document).bind("keydown",function(a){(a.keyCode==40||a.keyCode==38||a.keyCode==39||a.keyCode==37)&&a.preventDefault()})});$(document).ajaxStop(function(){b=true;Y()});$(window).resize(function(){pa();fa();D()});$(window).load(function(){pa();wa();xa();b=true;D()})});
