
$(document).ready(function(){$work_results_container=$('#work-results-container');$work_results=$('#work-results');setup_interactive_developer();setup_tints();setup_footer_links();set_defaults();$(window).resize(on_window_resize);on_window_resize();setup_blog_scroll();setup_blog_slideshows();setup_featured_projects();setup_project_list();setup_project_filter();setup_project_slides();setup_tyler_over();});var header_left;var header_half_width;var header_offset;var sidebar_left;var sidebar_offset;function set_defaults(){header_left=parseInt($('header').css('left'));header_half_width=Math.ceil((parseInt($('header').css('width'))*.5));if($('body').hasClass('home')){header_offset=-39;sidebar_offset=638;}else{header_offset=118;sidebar_offset=654;}
if($('#side-bar').length){sidebar_offset=$('#side-bar').position().left;}}
function on_window_resize(){var content_left=$('#content').offset().left;var win_width=$(window).width();if(win_width<960){$('header').css({'left':header_left,'position':'absolute'});if($('#side-bar').length){$('#side-bar').css({'left':sidebar_offset,'position':'absolute'});}}else{$('header').css({'left':(win_width*.5-header_half_width+header_offset),'position':'fixed'});if($('#side-bar').length){$('#side-bar').css({'left':content_left+sidebar_offset,'position':'fixed'});}}}
function setup_interactive_developer(){var interactive=$('<a href="javascript:;" id="interactive"></a>');$('header').append(interactive);$(interactive).click(function(){$('html,body').animate({scrollTop:0},1000);});}
function setup_footer_links(){$('footer a').click(function(){window.open(this.href);return false;});}
function setup_tints(){$('img.tint').each(function(){var wrapper=$('<div class="tint_wrapper"></div>');wrapper.css('height',$(this).height());wrapper.css('width',$(this).width());wrapper.css('top',$(this).position().top);wrapper.css('left',$(this).position().left);wrapper.css('opacity',.5);$(wrapper).insertBefore($(this));});$('.highlight').each(function(){$(this).css('background','none');var wrapper=$('<div class="highlight_wrapper"></div>');wrapper.css('height',$(this).outerHeight());wrapper.css('width',$(this).outerWidth());wrapper.css('opacity',.2);$(this).mouseover(function(){$(this).stop().animate({color:"#000"},200);$(this).find('a').stop().animate({color:"#000"},200);$(this).find('.highlight_wrapper').stop().animate({opacity:.6},200);$(this).find('.tint_wrapper').stop().animate({opacity:0},200);});$(this).mouseout(function(){$(this).stop().animate({color:"#d8d7c6"},200);$(this).find('a').stop().animate({color:"#9db351"},200);$(this).find('a.meta').stop().animate({color:"#d8d7c6"},200);$(this).find('.highlight_wrapper').stop().animate({opacity:.2},200);$(this).find('.tint_wrapper').stop().animate({opacity:.5},200);});$(this).prepend(wrapper);});}
function setup_blog_scroll(){if($('body').hasClass('blog')&&!$('body').hasClass('post')){$('#blog-posts').infinitescroll({navSelector:"div.prevnext",nextSelector:".prevnext .comments a",itemSelector:"div.post",loadingText:'Loading more posts...',donetext:' '},infinitescroll_complete);}}
function infinitescroll_complete(){setup_blog_slideshows();}
function setup_blog_slideshows(){$('.slideshow').each(function(){if(!$(this).hasClass('scripted')){$(this).addClass('scripted');var max_height=0;var children=$(this).children('img');if(children.length){children.each(function(){$(this).fadeOut(0);$(this).addClass('off');var this_height=parseInt($(this).css('height'));max_height=(this_height>max_height)?this_height:max_height;$(this).click(advance_slideshow);});$(children[0]).fadeIn('slow');$(children[0]).removeClass('off');$(children[0]).addClass('on');$(this).css('height',max_height);var controls=$('<div class="slideshow_controls"><a class="previous" href="javascript:;">Previous</a> / <a class="next" href="javascript:;">Next image</a> <span class="count">(1 of '+children.length+')</span></div>');$(this).append(controls);var previous=$(this).find('.previous');$(previous).click(reverse_slideshow);var next=$(this).find('.next');$(next).click(advance_slideshow);}}});}
function reverse_slideshow(){update_slideshow($(this),'reverse');}
function advance_slideshow(){update_slideshow($(this),'forward');}
function update_slideshow(slide,direction){var slideshow=$(slide).parents('.slideshow');var slides=$(slideshow).children('img');var count=$(slideshow).find('.count');var current_slide=0;var length=slides.length;for(var i=0;i<length;i++){if($(slides[i]).hasClass('on')){current_slide=i;}};$(slides[current_slide]).stop().fadeOut('slow');$(slides[current_slide]).removeClass('on');$(slides[current_slide]).addClass('off');if(direction=='forward'){current_slide++;if(current_slide==length){current_slide=0;}}else{current_slide--;if(current_slide==-1){current_slide=length-1;}}
$(slides[current_slide]).stop().fadeIn('slow');$(slides[current_slide]).removeClass('off');$(slides[current_slide]).addClass('on');count_number=current_slide+1;$(count[0]).text('('+count_number+' of '+length+')');}
var featured_projects_animate=true;var featured_project_active_item=1;function setup_featured_projects(){var $featured_projects=$('#featured-projects');if($featured_projects.length){$border=$('<span class="border"></span>');$featured_projects.append($border);$active_highlight=$('<span class="active-highlight"></span>');$featured_projects.append($active_highlight);var projects=$('#featured-projects .project');var project_links=$('#featured-projects ol li a');projects.hide();kick_start_featured_projects_animation();project_links.click(function(){featured_projects_animate=false;$('#featured-projects .border').stop();var id=$(this).attr('id').substr(13);go_to_featured_project(id);});project_links.mouseover(function(){$(this).stop().animate({'color':"#fff"},500);});project_links.mouseout(function(){var id=$(this).attr('id').substr(13);if(featured_project_active_item!=id){$(this).stop().animate({'color':"#000"},500);}});}}
function kick_start_featured_projects_animation(){go_to_featured_project(1);$border=$('#featured-projects .border');$border.animate({width:'831px'},{duration:40000,easing:'linear',complete:function(){kick_start_featured_projects_animation();},step:function(){var w=$(this).width();if(w>=209&&featured_project_active_item==1){go_to_featured_project(2);}else if(w>=418&&featured_project_active_item==2){go_to_featured_project(3);}else if(w>=627&&featured_project_active_item==3){go_to_featured_project(4);}}});}
function go_to_featured_project(n){var $featured_projects=$('#featured-projects .project');var $featured_project_links=$('#featured-projects ol li a');switch(n){case 1:case"1":featured_project_active_item=1;if(!featured_projects_animate){$('#featured-projects .border').stop().animate({width:0},250);}else{$('#featured-projects .border').width(0);}
$('#featured-projects .active-highlight').animate({left:0},250);$featured_projects.stop().fadeOut();$($featured_projects[0]).stop().fadeIn();$featured_project_links.stop().animate({'color':"#000"},500);$($featured_project_links[0]).stop().animate({'color':"#fff"},500);break;case 2:case"2":featured_project_active_item=2;if(!featured_projects_animate){$('#featured-projects .border').stop().animate({width:209},250);}
$('#featured-projects .active-highlight').animate({left:209},250);$featured_projects.stop().fadeOut();$($featured_projects[1]).stop().fadeIn();$featured_project_links.stop().animate({'color':"#000"},500);$($featured_project_links[1]).stop().animate({'color':"#fff"},500);break;case 3:case"3":featured_project_active_item=3;if(!featured_projects_animate){$('#featured-projects .border').stop().animate({width:418},250);}
$('#featured-projects .active-highlight').animate({left:418},250);$featured_projects.stop().fadeOut();$($featured_projects[2]).stop().fadeIn();$featured_project_links.stop().animate({'color':"#000"},500);$($featured_project_links[2]).stop().animate({'color':"#fff"},500);break;case 4:case"4":featured_project_active_item=4;if(!featured_projects_animate){$('#featured-projects .border').stop().animate({width:627},250);}
$('#featured-projects .active-highlight').animate({left:627},250);$featured_projects.stop().fadeOut();$($featured_projects[3]).stop().fadeIn();$featured_project_links.stop().animate({'color':"#000"},500);$($featured_project_links[3]).stop().animate({'color':"#fff"},500);break;}}
function setup_project_list(){if($.browser.msie){if(parseInt($.browser.version,10)<9){$('.highlight.project-thumb:nth-child(4n)').css('margin-right',0);}}}
var category_dropdown;function setup_project_filter(){if($('body').hasClass('project-index')){$('#view-all').click(viewAllProjects);category_dropdown=$('select').selectbox({callBack:onSelectChange});}}
function viewAllProjects(){$('#view-all').addClass('active');$.ajax({url:"/lib/fpo/filtered-projects.html",success:function(data){$('#work-results').html(data);setup_tints();}});}
function onSelectChange(id){if(id!=0){$.address.value(id);}else{$.address.value('/');}}
function setup_project_slides(){if($('#project-slideshow').length){var max_height=0;var children=$('#project-slideshow').find('.slide');children.each(function(){$(this).fadeOut(0);$(this).addClass('off');var this_height=parseInt($(this).css('height'));max_height=(this_height>max_height)?this_height:max_height;$(this).children('img').click(advance_project_slideshow);});$('#project-slideshow').height(max_height);$(children[0]).fadeIn('slow');$(children[0]).removeClass('off');$(children[0]).addClass('on');$(children[0]).children('.note').delay(1500).fadeIn();var controls=$('<div class="slideshow_controls"><a class="previous" href="javascript:;">Previous</a> / <a class="next" href="javascript:;">Next image</a> <span class="count">(1 of '+children.length+')</span></div>');$('#project-slideshow').append(controls);var previous=$('#project-slideshow').find('.previous');$(previous).click(reverse_project_slideshow);var next=$('#project-slideshow').find('.next');$(next).click(advance_project_slideshow);$('.note a').click(function(){var parent=$(this).parents('.note');$(parent).fadeOut().remove();});}}
function reverse_project_slideshow(){update_project_slideshow($(this),'reverse');}
function advance_project_slideshow(){update_project_slideshow($(this),'forward');}
function update_project_slideshow(slide,direction){var slideshow=$(slide).parents('#project-slideshow');var slides=$(slideshow).children('.slide');var count=$(slideshow).find('.count');var current_slide=0;var length=slides.length;for(var i=0;i<length;i++){if($(slides[i]).hasClass('on')){current_slide=i;}};$(slides[current_slide]).stop().fadeOut('slow');$(slides[current_slide]).find('.note').stop().fadeOut('slow');$(slides[current_slide]).removeClass('on');$(slides[current_slide]).addClass('off');if(direction=='forward'){current_slide++;if(current_slide==length){current_slide=0;}}else{current_slide--;if(current_slide==-1){current_slide=length-1;}}
$(slides[current_slide]).stop().fadeIn('slow');$(slides[current_slide]).find('.note').stop().delay(1500).fadeIn('slow');$(slides[current_slide]).removeClass('off');$(slides[current_slide]).addClass('on');count_number=current_slide+1;$(count[0]).text('('+count_number+' of '+length+')');}
function setup_tyler_over(){if(!$('body').hasClass('home')){$('h3#tyler-craft a').mouseover(function(){$(this).stop().animate({'opacity':.5,'duration':250});});$('h3#tyler-craft a').mouseout(function(){$(this).stop().animate({'opacity':1,'duration':250});});}}
var current_address_value='/';var $work_results_container;var $work_results;$.address.change(function(event){if(current_address_value!=event.value){$work_results_container.height($work_results.height());$work_results.fadeOut()
$.ajax({url:"/projects/?cat="+event.value,context:document.body,success:function(data){$work_results.stop(true,true).hide().html(data);$work_results_container.stop(true,true).animate({'height':$work_results.height()},500);$work_results.stop(true,true).fadeIn('fast');$('html,body').animate({scrollTop:$work_results_container.position().top},1000);setup_tints();}});current_address_value=event.value;}});
