$(document).ready(function(){						   	

	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});

	$('#delivery_address_same').click(function(){
		var container = $('#delivery_address_container');
		
		if($(this).attr('checked')){
			$(container).slideUp();
		}
		else{
			$(container).slideDown();
			console.log('sliding down...');
		}
		
	});
	
	// Contact form
	$('#enquiry_form').submit(function(e){
		e.preventDefault();
		
		var form = $(this);
		
		var data = {
			name: $('#name').val(),
			email: $('#email').val(),
			telephone: $('#telephone').val(),
			enquiry: $('#enquiry').val()
		};
		
		$.ajax({
			url: '/tools/send_contact_form',
			type: 'POST',
			data: data,
			beforeSend: function(){
				$('.ajax_loader').show();
			},
			success: function(response){
				if (response == '')
				{
					form.slideUp(600, function(){
						$('#enquiry_sent').slideDown(600);
					});				
				}
				else
				{
					alert('Please check the details entered. You must provide a Name, valid Email Address and details of your enquiry.');
				}
			},
			complete: function(){
				$('.ajax_loader').hide();
			}
		});
	});

});
