$(document).ready(function() {
	$('.header-right > p').append('&nbsp;&nbsp;<a href="#" class="button" id="showPort">Check it out &rArr;</a>');
	$('#gallery1link').addClass('selected');
	$('.navItem').hover(function() {
		$(this).next('.navBack').animate({marginTop:"-10px"},100,"easeOutBack");
	},
	function() {
		$(this).next('.navBack').animate({marginTop:"0px"},100);
	});
	$('.navItem:not(#portfolio)').click(function() {
		//update nav bg
		$('.navBack').removeClass('selected');
		$(this).next('.navBack').addClass('selected');
		$('.navBack').css({"-moz-box-shadow":"none", "-webkit-box-shadow":"none"});
		$(this).next('.navBack').css({"-moz-box-shadow":"2px 2px 18px #555", "-webkit-box-shadow":"2px 2px 18px #555"});
		
		//fade in the right div
		var mainDiv = $('.frntpg, .portfolio, .contact, .about');
		var curNav = $(this).attr('id');
		$(mainDiv).fadeOut()
		$('.'+curNav).fadeIn()
	});
	var showPort = $('#portfolio, #showPort'); 
	var curImg = $('#gal1-Photo1').attr('id');
	$(showPort).click(function() {
		//update nav bg
		$('.navBack').removeClass('selected');
		$('#portfolio').next('.navBack').addClass('selected');
		$('.navBack').css({"-moz-box-shadow":"none", "-webkit-box-shadow":"none"});
		$('#portfolio').next('.navBack').css({"-moz-box-shadow":"2px 2px 18px #555", "-webkit-box-shadow":"2px 2px 18px #555"});
		
		//fade in the right div
		var mainDiv = $('.frntpg, .portfolio, .contact, .about');
		$(mainDiv).fadeOut();
		$('.portfolio').fadeIn();
		$('.portphoto, .galleryHolder').fadeOut();
		$('#gallery1, .thumbHolder').fadeIn();
		$('#gallery1 > .photoHolder > img:first').fadeIn();
		$('.thumbWrapper').removeClass('current');
		$('#gal1-Thumb1').addClass('current');
		$('.linkItem').removeClass('selected');
		$('#gallery1link').addClass('selected');
		curImg = $('#gal1-Photo1').attr('id');
	});
	
	
	$('.thumbWrapper').click(function() {
		var curID = $(this).attr('id').replace('Thumb','Photo');
		$('#'+curImg).fadeOut('500',function() {
			$('#'+curID).fadeIn('slow');
			curImg = curID; 
		});
		$('.thumbWrapper').removeClass('current');
		$(this).addClass('current');
	});
	$('.thumbWrapper').hover(function() {
		$(this).animate({opacity:1},300);
	  },
	  function() {
	  	$(this).animate({opacity:".4"});
	  });
	$('.portNav > .linkItem').click(function() {
		$('.portphoto').fadeOut();
		var curID = $(this).attr('id').replace('link','');
		curImg = $('#'+curID+' > .photoHolder > img:first').attr('id');
		//selected state for link
		$('.portNav > .linkItem').removeClass('selected');
		$(this).addClass('selected');
		$('.portNav').animate({opacity:1});
		//show the right gallery
		$('.galleryHolder, .thumbHolder').fadeOut();
		$('.thumbWrapper').removeClass('current');
		$('#'+curID).fadeIn();
		$('#'+curID+' > .thumbHolder').fadeIn();
		$('#'+curID+' > .photoHolder > img:first').fadeIn();
		$('#'+curID+' > .thumbHolder > div:first').addClass('current');
	});
	$('.portNav > .linkItem').hover(function() {
		$(this).addClass('hover');
	  },
	  function() {
	  	$(this).removeClass('hover');
	  });
	
	$('.thumbInner1').mousemove(function(e) {
		var s_top = parseInt($('.thumbInner1').offset().top);		
		var s_bottom = parseInt($('.thumbInner1').height() + s_top);
		var mheight = parseInt(70 * ($('#holder1 > .thumbWrapper').length / 7));	
		var top_value = Math.round(( (s_top - e.pageY) /100) * mheight / 2);
		$('.thumbInner1').animate({top: top_value}, { queue:false, duration:500});
	});  
	$('.thumbInner2').mousemove(function(e) {
		var s_top = parseInt($('.thumbInner2').offset().top);		
		var s_bottom = parseInt($('.thumbInner2').height() + s_top);
		var mheight = parseInt(70 * ($('#holder2 > .thumbWrapper').length / 7));	
		var top_value = Math.round(( (s_top - e.pageY) /100) * mheight / 5);
		$('.thumbInner2').animate({top: top_value}, { queue:false, duration:500});
	}); 
	$('.thumbInner3').mousemove(function(e) {
		var s_top = parseInt($('.thumbInner3').offset().top);		
		var s_bottom = parseInt($('.thumbInner3').height() + s_top);
		var mheight = parseInt(70 * ($('#holder3 > .thumbWrapper').length / 7));	
		var top_value = Math.round(( (s_top - e.pageY) /100) * mheight / 5);
		$('.thumbInner3').animate({top: top_value}, { queue:false, duration:500});
	}); 
	$('.thumbInner4').mousemove(function(e) {
		var s_top = parseInt($('.thumbInner4').offset().top);		
		var s_bottom = parseInt($('.thumbInner4').height() + s_top);
		var mheight = parseInt(70 * ($('#holder4 > .thumbWrapper').length / 7));	
		var top_value = Math.round(( (s_top - e.pageY) /100) * mheight / 4);
		$('.thumbInner4').animate({top: top_value}, { queue:false, duration:500});
	}); 
	
	$('#sendMail').click(function() {
		var name = $('input[name=name]').val(),
		email = $('input[name=email]').val(),
		phone = $('input[name=phone]').val(),
		comments = $('textarea[name=comments]').val();
		
		if(name!='' && email!='' && comments !='') {
		
			var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&comments=' + comments;
			
			$.ajax({
			  type: "POST",
			  url: "sendmail.php",
			  data: dataString,
			  success: function(data) {
				$('.contact > .subContent').text(data);
			  }
			 });
		}
		
		else {
			alert("Please fill out all required fields");
		}
	return false;
			});
});


