$(document).ready(function(){	
	$("#slider").easySlider({
		auto: true,
		continuous: true,
		controlsShow: false,
		pause: 5000,
		speed: 1200
	});
	$('[name="order"]').click(
		function()
		{
			go2();
		}
	)
	$('[name="next"]').click(
		function()
		{
			go3()
		}
	)
		$('[name="cancel"]').click(
		function()
		{
			go1();
		}
	)
		$('[name="cancel_2"]').click(
		function()
		{
			go2()
		}
	)
	$('[name="submit_order"]').click(
		function()
		{
			checkForm()
		}
	)
});

function go1()
{
	$('.qtip').qtip("destroy")
	$('#r_features').slideDown();
	$('.cost').hide();
	$('#r_spring').slideDown();
	$('#form_1:visible').slideUp();
	$('[name="cancel"]').hide()
	$('[name="order"]').show()
	$('#logo').fadeIn()
}

function go2()
{
	$('.qtip').qtip("destroy")
	$('#form_1').slideDown();
	$('#form_2:visible').slideUp();
	$('#r_features:visible').slideUp();
	$('.cost:visible').hide();
	$('#r_spring:visible').slideUp();
	$('[name="cancel_2"]').hide()
	$('[name="cancel"]').show()
	$('[name="order"]').hide()
	$('#logo').fadeOut()

}

function go3()
{
	$('.qtip').qtip("destroy")
	$('#form_1:visible').slideUp();
	$('#form_2').slideDown();
	$('[name="cancel"]').hide()
	$('[name="cancel_2"]').show()
}

function go4()
{
	$('#r_features').slideDown();
	$('.cost').show();
	$('#r_spring').slideDown();
	$('#logo').fadeIn()
	$('.qtip').qtip("destroy")
	$('#order-form').slideUp();
	$('[name="cancel_2"]').hide()
	$('#order-complete').slideDown();
}


function checkForm()
{
	$('.qtip').qtip("destroy")

	if( $('[name="name"]').val() == '' )
		inputNotify($('[name="name"]'), 'Please enter your name!', true);
	
	if( $('[name="email"]').val() == '' )
		inputNotify($('[name="email"]'), 'Please enter your email address!', true);
		
	if( $('[name="email"]').val() != $('[name="email2"]').val() )
	{
		$('[name="email2"]').val('')
		inputNotify($('[name="email2"]'), 'Your email addresses must match!', true);
		
	}
	
	if( $('.qtip').length == 0 )
		sendForm();
	
}

function sendForm()
{
	formData = $('#order_form').serialize();
	
	$.post(	'/include/ajax/order.ajax.php',
			formData,
			function(data)
			{
				if( data.result == 'success' )
					go4();

			}, 
			'json'
	)


}

function inputNotify(element, message, error)
{
	if(error == true)
	{
		color='red'
		hide = false;
	
	} else {
	
		color='dark';
		hide= { when: {event: 'unfocus'}}
	}
	
	element.qtip({
	content: message,
	style: { 
		name: color,
		tip: 'leftMiddle'
	},
	position: {
		corner: {
			target: 'rightMiddle',
			tooltip: 'leftMiddle'
		}
	},
	show: { ready: true },
	hide: false,
	api: {
			onHide: function(){ $(this).trigger('destroy') }
		}
	})

} //inputNotify