$(function() {
	$('#horizontalContent > li:first').attr('id', 'first').css('margin-top', '0px');
	$('#horizontalContent > li:last').attr('id', 'last');
	
	$('#container').serialScroll({
		items: 'li.slide',
		cycle: false,
		duration: 250,
		prev: '.prev',
		next: '.next',
		onAfter: function(el) {
			var currentView = $(el).attr('id');
			
			if(currentView == 'first') { $('#goPrev').fadeOut(); $('#goHome').fadeOut(); }
			else { $('#goPrev').fadeIn(); $('#goHome').fadeIn(); }
			
			if(currentView == 'last') { $('#goNext').fadeOut(); }
			else { $('#goNext').fadeIn(); }
			
		}
	});
	
	$('#goHome').click(function(e) {
		e.preventDefault();
		$('#container').trigger('goto', [0]);
	});
	
	$('.contactMe').click(function(e) {
		e.preventDefault();
		var lastSlide = $('li.slide').size() - 1;
		$('#container').trigger('goto', [lastSlide]);
	});
	
	$('form').submit(function() {
		$('form input[type="submit"]').attr('disabled', 'true').val('Sending message...');
		$.post($(this).attr('action'), $(this).serialize(), function(data) {
			$('#contactMessage').html(data);
			$('form input[type="submit"]').removeAttr('disabled').val('Send Message');
			$('form input[type="text"]').val('');
			$('form textarea').val('');
		});
		
		return false;
	});
	
	$('#twitter').tweet({
		username: 'tempelmeyer',
		count: 1,
		loading_text: 'Please wait while I retrieve my latest tweet.'
	});
});