$(document).ready(function(){

	/* SLIDER FUNCTIONS */
	$('.sliderToggle').live('click', function(){
		var slider = $(this).attr('href').split('#')[1];
		$('.slider:not(#' + slider + ')').hide();
		$('#' + slider).slideToggle('fast');
		return false;
	});
	/* end SLIDER FUNCTIONS */

	/* GALLERY FUNCTIONS */
	$('#gallerySlider a').click(function(){
		if ( $('#feature').length == 0 )
		{
			$('<div id="feature"><img /></div><!-- feature -->')
			.insertAfter('#galleryWrapper');
		};
		$('#feature img').attr('src', $(this).attr('href') );
		
		return false;
	});
	
	$('<a href="#gallerySlider" class="sliderToggle">Hide the Portfolio</a>')
	.insertBefore('#galleryWrapper');

	/* end GALLERY FUNCTIONS */
	
	/* CONTACTFORM FUNCTIONS */
	$('.contactForm').submit(function(){
		$('.error', this).removeClass('error');
		$('.alert', this).hide();
		$(':input, textarea', this).each(function(){
			if ( '' == $(this).val() )
			{
				$(this).addClass('error');
			}
		});
		
		if ( $('.error', this).length > 0 ) 
		{
			$('.alert', this).show();
			return false;
		}

		var thisForm = this;

		$.ajax({
			type: 'POST',
			url: 'email.php',
			data: $(this).serialize(),
			dataType: 'html',
			success: function(html)
			{
				$(thisForm).html(html);
			},
			error: function()
			{
				$(thisForm).html( $('<p class="success">Sorry, something went wrong. Please contact me directly.</p>') );
			}
		});
		
		return false;
	});
	/* end CONTACTFORM FUNCTIONS */
	
	
	/* GENERAL FUNCTIONS */
	$(':text, :textarea, :select')
	.focus(function(){
		$(this).addClass('focus');
	})
	.blur(function(){
		$(this).removeClass('focus');
	});
});