$(document).ready(function() {
	
	// Cyclebox
	$("#cyclebox").cycle({	
	timeout:       6000,  // milliseconds between slide transitions (0 to disable auto advance)
	random:           1, // It's random now! 
    speed:         2000  // speed of the transition (any valid fx speed value) 			
	});	
	
	// Setup Lightbox
	$("a[rel='lightbox']").lightBox();

	
	// Hide Loading and Output Elements
	$("#loading").hide();
	$("#age").hide();
	
	// Setup Form Submit Options
	var options = {
		beforeSubmit: function() {
		$('#loading').fadeIn(50);
		},
		dataType: 'json',
		success: processJson
		}
	
	// Form Submit Function
	function processJson(data) {
		var status = data.status;
		$('#loading').fadeOut(300);		
				
		// If Fields are Empty
		if(status == 1) {$('#output').hide().empty().fadeIn(150).append("<p class='alert'>You must fill in all required fields.</p>");}
		
		// If Name is Wrong
		if(status == 2) {$('#output').hide().empty().fadeIn(150).append("<p class='alert'>Your name must be between 3 and 30 characters.</p>");}								
		
		// If Spam Bot
		if(status == 3) {$('#output').hide().empty().fadeIn(150).append("<p class='alert'>Leave the spam field blank please.</p>");}
		
		// If Fields are Empty
		if(status == 4) {$('#output').hide().empty().fadeIn(150).append("<p class='alert'>Your email address was not valid.</p>");}
		
		// If Probems
		if(status == 6) {$('#output').hide().empty().fadeIn(150).append("<p class='alert'>There was a problem sending the form.</p>");}
		
		// If Message Sent
		if(status == 5) {
						
			$('#quick-contact #output').hide(50);								
			$('#quick-contact form').slideUp(600);	
			$('#quick-contact #thankyou').hide().append("<h6>Thank You.</h6><p>Your message has been sent.</p>").slideDown(600);														
			$('#loader').fadeOut(500);
			return false;						
		
		}// End of Status 5
						
	} 
	// End of processJson
	

	$('#quick-contact form').ajaxForm(options);	

});