$(document).ready(function() {
	var isSharedPage = (window.location.pathname == '/' 
						|| window.location.pathname == '/contact' 
						|| window.location.pathname == '/resume');
						
	$('ul.portfolio li:nth-child(3n+3)').css({'margin-right':'0'});
	
	var projectNum = $("div.thumbs ul li").size();
	var ulWidth = projectNum*98;
	//alert(projectNum);
	$('div.thumbs ul').css({'width':ulWidth+'px'});
	$('.horz-scroll').jScrollPane();
	
	$('div.thumbs ul li a img').hover (
		function() {
			$(this).css({'top':'-80px'})
			$(this).parent().parent().css({'border':'1px solid #999'});
		},
		function() {
			$(this).css({'top':'0'})
			$(this).parent().parent().css({'border':'1px solid #e2e2e2'});
		}
	);
	
	/**** home page horizontal navigation *****/
	$('ul.top-nav li#nav-resume a, div.arrow-to-resume, div.footer ul li a.resume').click(function(e){
		if(isSharedPage) {
			e.preventDefault();
			
			animateToResume();
			
			if(window.history && window.history.pushState && window.location.pathname != '/resume') {
				window.history.pushState(null, null, '/resume');
			}
		}
	});
	
	$('ul.top-nav li#nav-contact a, div.arrow-to-contact, div.footer ul li a.contact').click(function(e) {
		if(isSharedPage) {
			e.preventDefault();
			
			animateToContact();
			
			if(window.history && window.history.pushState && window.location.pathname != '/contact') {
				window.history.pushState(null, null, '/contact');
			}
		}
	});
	
	$('div.arrow-to-home, a.logo, div.footer ul li a.home').click(function(e){
		if(isSharedPage) {
			e.preventDefault();
			
			animateToHome();
			
			if(window.history && window.history.pushState && window.location.pathname != '/') {
				window.history.pushState(null, null, '/');
			}
		}
	});
	
	function animateToHome() {
		$('ul.top-nav li a').removeClass('active');
		$('div.home-container').animate({
			left: '0'
		}, 300);
	}
	
	function animateToResume() {
		$('ul.top-nav li a').removeClass('active');
		$('div.home-container').animate({
			left: '-960'
		}, 300);
		$('ul.top-nav li#nav-resume a').addClass('active');
	}
	
	function animateToContact() {
		$('ul.top-nav li a').removeClass('active');
		$('div.home-container').animate({
			left: '-1920'
		}, 300);
		$('ul.top-nav li#nav-contact a').addClass('active');
		$('div.success-msg, div.fail-msg').hide();
	}
	
	window.onpopstate = function(event) {
		var currentPath = document.location.pathname;
		if(currentPath == '/') {
			animateToHome();
		}
		else if(currentPath == '/resume') {
			animateToResume();
		}
		else if(currentPath == '/contact') {
			animateToContact();
		}
	}; 
	
	$('div.arrow-to-contact').hover (
		function() {
			$('div', this).css({'background-position':'0 -72px'})
		},
		function() {
			$('div', this).css({'background-position':'0 0'})
		}
	);
	
	$('div.arrow-to-home').hover (
		function() {
			$('div', this).css({'background-position':'0 -66px'})
		},
		function() {
			$('div', this).css({'background-position':'0 0'})
		}
	);
	
	$('div.home div.arrow-to-resume').hover (
		function() {
			$('div', this).css({'background-position':'0 -90px'})
		},
		function() {
			$('div', this).css({'background-position':'0 0'})
		}
	);
	
	$('div.contact div.arrow-to-resume').hover (
		function() {
			$('div', this).css({'background-position':'0 -90px'})
		},
		function() {
			$('div', this).css({'background-position':'0 0'})
		}
	);
	
	/**** contact form *****/
	$('input[type="text"], textarea').addClass("idle");
	
    $('input[type="text"], textarea').focus(function() {  
        $(this).removeClass("idle").addClass("focus");
		if($(this).val() == $(this).attr('placeholder')) {
			$(this).val('');
		}
    }); 
    $('input[type="text"], textarea').blur(function() {  
        $(this).removeClass("focus").addClass("idle");  
		if($.trim($(this).val()) == '') {
			$(this).val($(this).attr('placeholder'));
		}
    });
	
	/****** miscellaneous cycle *******/
	function joshuaTree(curr,next,opts) {
		var caption = (opts.currSlide + 1) + ' of ' + opts.slideCount;
		$('div.pagination').html(caption);
	}
	
	$('div.photo-cycle').cycle({ 
		fx:     'fade', 
		speed:  500, 
		timeout: 5000, 
		next:   'ul.controls li a.next', 
		prev:   '#ul.controls li a.prev',
		after: joshuaTree
	});
});
/*
$('.slideshow-seascape').cycle({
			next: '#next-button-seascape',
			prev: '#prev-button-seascape',
			after: onAfterseascape,
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});*/


