$(function(){
	
	
	
///////////////////////////////////////////////////////////////// Portfolio Paging //////////////////////////
	
	
	
	$('#portfolio-index .portfolio-thumb:first-child, #portfolio-index .portfolio-thumb:nth-child(5n)').addClass("row-first");	
	$('#portfolio-index .portfolio-thumb:nth-child(4n)').addClass("row-last");
		
	$('.portfolio-item .img-gal .thumbs li:nth-child(4n)').addClass("row-last");
	$('.portfolio-item .img-gal .thumbs li:nth-child(5n)').addClass("row-first");
	
	$('#home-work .thumb:first-child').addClass("row-first");	
	$('#home-work .thumb:nth-child(5n)').addClass("row-last");	
	
	


	$('.portfolio-item .img-gal .thumbs li img').click(function(){
		var thumbsrc = $(this).attr('src');
		$(this).closest('.img-gal').find('img.primary').attr('src', thumbsrc);
	});















	
	
	
	$('.portfolio-thumb').click(function(){
		var postnumber = $(this).attr("data-postnumber");
		$('#portfolio-index').animate({left: '-1200',}, 800, 'linear', function() {    });	
		$('.portfolio-item[data-postnumber='+postnumber+']').animate({left: '0',}, 800, 'linear', function() {    });
		top.location.hash = "#" + postnumber;	
	});
	
	
	
	$('.portfolio-item .back-to').click(function(){
		$('#portfolio-index').animate({left: '0',}, 800, function() {    });	
		$(this).closest('.portfolio-item').animate({left: '1200',}, 800, function() {    });	
		top.location.hash = "all";
		var yScroll=document.body.scrollTop;
		document.body.scrollTop=yScroll;
	});
	
	
	
	
	// If url contains a hash
	if (window.location.hash) {
		 var posthash = window.location.hash.substring(1);
		// If the portfolio item exists that matches the hash
		if( $('.portfolio-item[data-postnumber='+posthash+']').length > 0   ){
			$('#portfolio-index').css("left", "-1200px");
			$('.portfolio-item[data-postnumber='+posthash+']').css("left", "0");
		} 		
	} 
	
	
	$(window).bind('hashchange', function () {
	
	});
	
	
	
	
});
