$(document).ready(function()
{
	var options = {
		success: function()
		{
			$('#formsuccess').html('Thanks for taking the time to contact me. I\'ll be sure to respond as soon as I can.');
			
			$('#formsuccess').fadeIn();
		}
	}
	
	$('a[rel="scroll"]').click(function()
	{
		if(location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname)
		{
			var $target = $(this.hash);
			
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			
			if($target.length)
			{
				var targetOffset = $target.offset().top - 130;
				
				$('html, body').animate({scrollTop: targetOffset}, 800);
				
				return false;
			}
		}
	})
	
	/*$("#contactform").validate({
		rules: {
			name: {
				required: true,
				minlength: 4
			},
			email: {
				required: true,
				email: true
			},
			message: {required: true},
			human: {required: true}
		},
		messages: {
			name: {
				required: "Please provide your first and last name.",
				minlength: "Your first and last name needs to be longer than 4 characters."
			},
			email: {
				required: "Please provide your email address.",
				email: "Your email needs to be a valid email address."
			},
			message: { required: "You need to type some kind of message to me." }
		},
		submitHandler: function(form)
		{
			$(form).ajaxSubmit(options);
		}
	})*/
	
	// TODO Clean this up
	
	var ben = '<li><a href="http://benmillsdesigns.com/">Ben Mills</a></li>';
	var eric = '<li><a href="http://ejboyer.com/">Eric Boyer</a></li>';
	var jon = '<li><a href="http://greenethumb.com/">Jon Greene</a></li>';
	var jonathan = '<li><a href="http://motionsuggests.com/">Jonathan Taylor</a></li>';
	var lorenzo = '<li><a href="http://lorenzosorice.com">Lorenzo Sorice</a></li>';
	var matt = '<li><a href="http://www.mattephraim.com/">Matthew Ephraim</a></li>';
	var shaun = '<li><a href="http://shauncrittenden.com">Shaun Crittenden</a></li>';
	var thane = '<li><a href="http://thanewoidan.com/">Thane Woiden</a></li>';
	var walker = '<li><a href="http://walkerhamilton.com/">Walker Hamilton</a></li>';
	
	var friendlist = '<ul style="display: none;">' + ben + eric + jon + jonathan + lorenzo + matt + shaun + thane + walker + '</ul>';
	var friendlink = '<li><a href="javascript:void(0);" class="friends"><span class="distext">Friends</span></a>' + friendlist + '</li>';
	
	$('.validlist').prepend(friendlink);
	
	$('.friends').parent().hover(function(){
		$('.friends').parent().children('ul').show();
	},
	function(){
		$('.friends').parent().children('ul').hide();
	});
	
	projectPreviewModal();
})

function projectPreviewModal()
{
	$('#project-preview').dialog({
		autoOpen: false,
		draggable: false,
		modal: true,
		position: 'center',
		resizable: false,
		width: 652
	}).parents(".ui-dialog:first").find(".ui-dialog-titlebar").hide();
	
	$('#close-modal').click(function(e)
	{
		e.preventDefault();
		
		$('#project-preview').dialog('close');
		$('#slideshow > img').attr('src', '').css('margin', 0);
		$('#slideshow-controls > li > a').parent().removeClass('current');
		$('#slideshow-controls > li > a:first').parent().addClass('current');
	});
	
	$('.preview-link').click(function(e)
	{
		e.preventDefault();
		
		var href = $(this).attr('href');
		
		$('#slideshow > img').attr('src', href);
		$('#project-preview').dialog({ position: 'center' });
		$('#project-preview').dialog('open');
	});
	
	$('#slideshow-controls > li > a').click(function(e)
	{
		e.preventDefault();
		
		var class = $(this).attr('class');
		
		switch(class)
		{
			case 'one':
				$('#slideshow > img').animate({ marginLeft: 0 }, 1000);
				$('#slideshow-controls > li > a').parent().removeClass('current');
				$(this).parent().addClass('current');
				break;
			
			case 'two':
				$('#slideshow > img').animate({ marginLeft: -650 }, 1000);
				$('#slideshow-controls > li > a').parent().removeClass('current');
				$(this).parent().addClass('current');
				break;
			
			case 'three':
				$('#slideshow > img').animate({ marginLeft: -1300 }, 1000);
				$('#slideshow-controls > li > a').parent().removeClass('current');
				$(this).parent().addClass('current');
				break;
			
			case 'four':
				$('#slideshow > img').animate({ marginLeft: -1950 }, 1000);
				$('#slideshow-controls > li > a').parent().removeClass('current');
				$(this).parent().addClass('current');
				break;
			
			case 'five':
				$('#slideshow > img').animate({ marginLeft: -2600 }, 1000);
				$('#slideshow-controls > li > a').parent().removeClass('current');
				$(this).parent().addClass('current');
				break;
		}
	});
}