$(document).ready(function(){

/*************************************************************************/
/******************** jQuery scrollTo + ajax load ************************/
		
	// jquery scrollTo variables
	var $scrollerWindow = $('#main');
	var $speed = 1500;
	var $easing = 'easeInOutCubic';
	
	
	// scroll to thumbnails
	function viewThumbs() {
		$scrollerWindow.stop().scrollTo( $('#container-thumbs'), $speed, {axis:'x', easing:$easing} );
		$('#main-outer').stop().animate({'background-position': '350px 0px'}, $speed, $easing);
		$('#container-detail').delay($speed).fadeOut('normal');
		$('.load').fadeOut('normal');
		
		// hide project description
		$('.description').animate({opacity: "0.0", top:0}, 600);
		$('.specializing').animate({opacity: "1.0", top:0}, 800);
		$('.areas').animate({opacity: "1.0", top:0}, 800);
		
		return false;
	}

	
	// ajax load project detail - check for existing deep linking on page load				   
	/*
	var hash = window.location.hash.substr(1);
	var href = $('.back a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-4)){
			var toLoad = hash+'.htm #container-detail';
			$('#container-detail').load(toLoad);
			
		}											
	}); */
	
	
	// scroll to project detail
	function viewDetail() {
		
		// ajax preloading
		var toLoad = $(this).attr('href') + '#container-detail';
		$('#container-detail').hide(300, loadContent);
		$('.load').remove();
		$(this).append('<div class="load"></div>');
		$('.load').fadeIn('normal');
		
		// append url and chop off .htm at end
		// window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);
		function loadContent() {
			$('#container-detail').load(toLoad,'', showNewContent());
		}
		
		// display new content and scroll over to it
		function showNewContent() {
			$('#container-detail').show(0,'normal', scrollToPage);
		}
		
		// jquery scrolling container + background: scroll to top, then move to right
		function scrollToPage() {
			$.scrollTo( '#subheader', $speed-800, {queue:true, axis:'y', easing:$easing, onAfter:function(){
				$scrollerWindow.stop().scrollTo( '#container-detail', $speed, {axis:'x', easing:$easing} );
				$('#main-outer').stop().animate({'background-position': '-350px 0px'}, $speed, $easing);
		 }});
		}
		
		// show project description
		$('.specializing').animate({opacity: "0.0", top:15}, 600);
		$('.areas').animate({opacity: "0.0", top:15}, 600);
		$('.description').animate({opacity: "1.0", top:20}, 800).text(this.title);
		
		return false;
	}
	
	
	// scroll to contact info
	function viewContact() {
		$.scrollTo( $('#footer-outer'), $speed, {axis:'xy', easing:$easing} );
		return false;
	}
	
    
	$('a.view-thumbs').live("click", viewThumbs);
	$('a.view-detail').live("click", viewDetail);
	$('a.view-contact').live("click", viewContact);


/*************************************************************************/
/************ project thumb hover support for touch devices **************/

	$('.card').hover(function(){
		$(this).addClass('flip');
	},
	function(){
		$(this).removeClass('flip');
	});

/*************************************************************************/
/*************************************************************************/

});


