//menu animation
$(document).ready(function() {
$('#recentWork, #about').css({left: "-450px"});

$('.recentWorkText').toggle(function() {
  $('#recentWork').animate({left: '38px' }, 200);
}, 
function(){
	$('#recentWork').animate({left: '-450px' }, 200);
});



$('.aboutText').toggle(function() {
    $('#about').animate({left: '38px' }, 200);
}, 
function(){
	$('#about').animate({left: '-450px' }, 200);
});



$('.recentWorkText').click(function(){
		$('#about').css({left: "-450px"})							
});

$('.aboutText').click(function(){
		$('#recentWork').css({left: "-450px"})							
});




$('ul.sf-submenu').hover(function(){
	$(this).parents('.navItem').css({color: "#fff"});
	
	}, function(){
		$(this).parents('.navItem').css({color: "#000"});
	
});



$('.clientText').click(function() {
  
  $('#about').animate({left: '-450px' }, 200);
  $('#recentWork').animate({left: '-450px' }, 200);
  
       }); 

	
$("#contentWork img.fade, #contentWork img.fadetwo, #contentWork img.fadethree").fadeTo(0,0);


$('#aboutPage').click(
function() {
    $(this).unbind('click');
});
$('#aboutPage a').click(
function() {
    $(this).bind('click');
});

	   
}); 


$(window).load(function(){ 
	var introDelay = 11600;
	$('#overlay').delay(introDelay).fadeOut(1000, function() {
      	$(this).remove();
	});
	if( $.cookie('returningUser') == 'true' ) {	
		$('#overlay #horizon').html('<div class="ajax_loader"><div class="inside">Hold tight...</div></div>');
	} else {
	   	$('#overlay .loading').delay(200).fadeIn(1000);
	   	$('#overlay .loading .loadbar').animate( { width: '326px' }, introDelay - 100 );
	   	$.cookie( { 'returningUser' : 'true' } );
	}
	
	$('#overlay').css( { 'background-color':'transparent' } );
	
$("#contentWork img.fade").each(function(i) {
    $(this).delay(200*i).css({visibility: 'visible'}).fadeTo(400,1);
  });

$("#contentWork img.fadetwo").each(function(i) {
    $(this).delay(100*i).css({visibility: 'visible'}).fadeTo(400,1);
  });

$("#contentWork img.fadethree").each(function(i) {
    $(this).delay(100*i).css({visibility: 'visible'}).fadeTo(400,1);
  });



$(".boxgrid").each(function(i) {
    $(this).delay(400*i).fadeIn();
  });


});






$(document).ready(function(){
	  $(".img-swap").live('click', function() {
	    if ($(this).attr("class") == "img-swap") {
	      this.src = this.src.replace("_open","_close");
	    } else {
	      this.src = this.src.replace("_close","_open");
	    }
	    $(this).toggleClass("on");
	  });
	
	
	$('.boxgrid').hover(function(){
		$(this).find('.description').stop(true, true).fadeIn("fast");
		}, function(){
		$(this).find('.description').stop(true, true).fadeOut("fast");	
		});


  function windowSize() {  
  var contentwidth = $(window).width();  
  if ((contentwidth) < '650'){  
  $('#recentWork, #about, #client').hide();  
  } else {  
  $('.fluidimage').attr('src','big.jpg');  
  }  
  }  
   
  windowSize();//Triggers when document first loads      
   
  $(window).bind("resize", function(){//Adjusts image when browser resized  
  windowSize();  
  }); 
  
 

	});




	 
				
				
				
				
//stop menu items from jumping page to top with anchors			
$(document).ready(function() {
    $('.recentWorkText').click(function(e) {
        e.preventDefault();
    });
});


$(window).load(function(){   
$('#grid-content').masonry({
  columnWidth: 2, 
  animate: true,
  animationOptions: {
    duration: 500,
    easing: 'linear',
    queue: false
  }
});


});


/* ================================================================
 *  Code for deep-linking, button history and forced Fancybox
 * ================================================================
*/


// populate Fancybox with correct file to load and force click;
function forceFancybox( section ) {
	$(".fancybox_holder").fancybox({
				'width'				: '100%',
				'height'			: '100%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'scrolling'         : 'auto',
				'href'				: section,
				'autoDimensions'	: true, 
				'centerOnScroll'	: false,
				'hideOnContentClick' : true,
				'hideOnOverlayClick' : false,
			'overlayColor'		: '#000', 
			'overlayOpacity'	: 0.85, 
		'onStart'			: function() {
			
				$('body').css({'overflow':'hidden', 'overflow-y':'hidden'});
				$('html').css({'overflow':'hidden', 'overflow-y':'hidden'});
				$('#fancybox-frame').css({display: 'block', visibility: 'hidden'});
				
		},
		
		'onComplete' : function(){
                $.fancybox.resize();
				$('#fancybox-frame').delay(2000).css({visibility: "visible"}).fadeIn("slow");
			
				
        },
        
        'onCleanup' : function(){
				window.location.hash = '';
				
				
		},
		
		'onClosed' : function(){
				$('body').css({'overflow':'visible', 'overflow-y':'visible'});
				$('html').css({'overflow':'visible', 'overflow-y':'visible'});
				
				
		}


		}).trigger("click");

}

// add listener for hash change event;
$(window).bind( 'hashchange', function(event) {
	 	var section = unescape( window.location.hash.toString().substr( 1 ) );
	 	
	 	if( section == '' ) {
	 		if( !$('#overlay').length ) $.fancybox.close();
	 	}
	 	else {
	 		if( $('#overlay').length ) $('#overlay').remove();
	 		forceFancybox( section );
	 	}
 });


// capture clicks on .fancybox class and set hash;
$(document).ready(function(){
 	
		 $(".fancybox").click(function( event ) {
		 	event.preventDefault();
  			var hash = $(this).attr("href");
  			window.location.hash = hash;
		});
		
		$(window).trigger( 'hashchange' );
});
