/* Author: 

*/

$(document).ready(function() {
	$('.slideshow').cycle({
		fx: 'fade',
		speed: '1000',
		timeout: '4000',
		prev:"#prev",
		next:'#next'
	});
	
	$("#buy_form").submit(function(e) {
		e.preventDefault();
		var postdata = $(this).serialize();
		if(!$("#name").val() || !$("#email").val()) {
			alert('Please make sure the Name and Email fields are filled out and try again.');
		}
		else {
			$.ajax({
				data: postdata,
				url: base_url + '/ajax/mail.php',
	 			success: function( data ) {
	 				if(data == 'success') {
	 					$("#buy_form, #buy_cntr .copy").fadeOut();
						$("#thankyou").fadeIn();
	 				}
	 				else {
	 					alert("We're sorry there has been an error. Please try your request again.");
	 				}
	    		}
			});

		}				
	});
	
	$("#close").click(function() {
		$("#buy_cntr").fadeOut('fast');
	});
	
	$(".bottle_button").click(function(e) {
		e.preventDefault();
		var type = $(this).attr('id').substr(7);
		$("#"+type).val(1);
		$("#buy_cntr").fadeIn('fast');
	});
	
	if($('body').hasClass('home')) {
		$("#mermaid_cntr").delay(500).fadeIn('slow', function() {
			$("#mermaid1").delay(700).fadeOut('slow');
			$("#bg1").delay(700).fadeOut('slow');
			$("#bg2").delay(500).fadeIn('slow');
			$("#mermaid2").delay(500).fadeIn('slow', function() {
				$("#bg2").delay(700).fadeOut('slow');
				$("#bg3").delay(500).fadeIn('slow');
				$("#mermaid2").delay(700).fadeOut('slow');
				$("#mermaid3").delay(500).fadeIn('slow', function() {
					$("#bg3").delay(700).fadeOut('slow');
					$("#background-image").delay(500).fadeIn('slow');
					$("#mermaid3").delay(700).fadeOut('slow');
					$("#mermaid4").delay(500).fadeIn('slow', function() {
						$("#mermaid4").delay(1000).animate({
							height: 200,
							top: 10,
							left: 416
						}, 1000);
						$("#bimg").delay(2000).fadeIn('slow', function() {
							$("#bquote").fadeIn('slow', function() {
								$("#bquote").delay(4500).fadeOut('slow');
								$("#onebottle").delay(4500).fadeIn('slow');
								$("#threebottle").delay(5500).fadeIn('slow');
								$("#fivebottle").delay(6500).fadeIn('slow', function() {
									$("#mermaid_cntr, #border").delay(2500).fadeOut('slow', function() {
										$("header, #main, footer").fadeIn('slow');
									});
								});
							});
						});
						/*$("#mermaid_cntr").delay(1000).fadeOut('slow', function() {
							
							$("#border").fadeIn('slow');		
									
									//$("header, #main, footer").fadeIn('slow');
									
									
						});*/
					});
				});
			});
		});
	
	}
	
	$("#home_bottle").click(function() {
		$(this).fadeOut();
		$("#home_words").fadeIn();
	});
	
	$("#home_words").click(function() {
		$(this).fadeOut();
		$("#home_bottle").fadeIn();
	});
});
