// JavaScript Document	

$(document).ready(function() {	
	//banner initialise
	$("#chained").scrollable({circular: true, mousewheel: true}).navigator().autoscroll({
		interval: 6000		
	});	
	
	//thumb descriptions
	$('#thumb_list').find('span').hide();
	$('#thumb_list').find('li').hover(
      function () {
        $(this).find('span').stop(true,true).slideDown('medium')
      },
      function () {
        $('#thumb_list').find('span').stop(true,true).slideUp('medium')
      }
    );
	
	//newsletter signup val
	var mailVal = $('#mailinglist_form #email')
	
	$(mailVal).focus(function() {
		if ($(this).val() == 'Email address') {
			$(this).val('')
			}
	});
	
	$(mailVal).blur(function() {
		if ($(this).val() == '') {
			$(this).val('Email address')
			}
	});
	
	
	//t-shirt hover
	if ( $.browser.msie ) {
	 } else {
		var $prodThumbs = $('#product_list li')
		$prodThumbs.hover(function() {
			
			$prodThumbs.not($(this)).stop().animate({opacity: 0.6, duration: 8000});
			}, function() {
			
			$prodThumbs.stop().animate({opacity: 1, duration: 8000});
		});
	 }
	
	
	//product section tabs
	$('#product_info, #shipping_info, #returns_info').hide();
	$('#product_info').show();
	
	$('#prodInfoBtn').click(function() {
			if ($('#product_info').is(':hidden')) {
					$('#prodInfoBtn').addClass('active');
					$('#shipInfoBtn, #returnInfoBtn').removeClass('active');
					$('#shipping_info, #returns_info').css('display', 'none');
						$('#product_info').css('display', 'block');
				} else {}
				return false;
		});
	$('#shipInfoBtn').click(function() {
			if ($('#shipping_info').is(':hidden')) {
					$('#shipInfoBtn').addClass('active');
					$('#prodInfoBtn, #returnInfoBtn').removeClass('active');
					$('#product_info, #returns_info').css('display', 'none');
						$('#shipping_info').css('display', 'block');
				} else {}
				return false;
		});
	$('#returnInfoBtn').click(function() {
			if ($('#returns_info').is(':hidden')) {
					$('#returnInfoBtn').addClass('active');
					$('#shipInfoBtn, #prodInfoBtn').removeClass('active');
					$('#product_info, #shipping_info').css('display', 'none')
						$('#returns_info').css('display', 'block');
				} else {}
				return false;
		});
		
	//product gallery
	function prodImgHide() {
		$('#product_img01, #product_img02, #product_img03').css("display", "none");
	};
	$('#thumb01_btn').click(function() {
		prodImgHide();
		$('#product_img01').css("display", "block");
		return false;
	});
	$('#thumb02_btn').click(function() {
		prodImgHide();
		$('#product_img02').css("display", "block");
		return false;
	});
	$('#thumb03_btn').click(function() {
		prodImgHide();
		$('#product_img03').css("display", "block");
		return false;
	});

	//validate forms
    $("#contactForm").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			message: "required"			
		},
		messages: {
			name: {
				required: "Please enter your name."
			},
			email: {
				required: "Please enter your email.",
				email: "Please enter a valid email."
			},
			message: {
			    required: "Please enter a message."	
			}			
		},
		errorClass: "error",
		submitHandler: function(form) {
			contactFormSubmit(form);
		}
	});
	
	// Submit form via AJAX
	function contactFormSubmit(form) {
		$(form).ajaxSubmit({ 
			target:".ajax_form_result", 
			beforeSubmit:function() {
				$("#form_hide").css('display', 'none');
			    $(".ajax_form_result").html('<h3><em>Contact us</em></h3><p>Sending message...</p>');
			},
			success:function(response) {
				$(form).resetForm();
				$(".ajax_form_result").html('<h3><em>Thank you!</em></h3><p>Your message has been sent. Someone from our team will get back to you as soon as possible.</p><p><a href="{site_url}contact" class="gen_btn">Send another message</a></p>');
			}
		});
	
	return false;		
}	
	 
	function sizeVal() {
		$("#requestForm").validate({
			rules: {
				name: "required",
				email: {
					required: true,
					email: true
				},
				request: "required"			
			},
			messages: {
				name: {
					required: "Please enter your name."
				},
				email: {
					required: "Please enter your email.",
					email: "Please enter a valid email."
				},
				request: {
					required: "Please enter a message."	
				}			
			},
			errorClass: "error"
		});	
		
	};	
	
	$("#compForm").validate({
		rules: {
			name: "required",
			email: {
				required: true,
				email: true
			},
			answer: "required"			
		},
		messages: {
			name: {
				required: "Please enter your name."
			},
			email: {
				required: "Please enter your email.",
				email: "Please enter a valid email."
			},
			answer: {
			    required: "You haven't given an answer!"	
			}			
		},
		errorClass: "error",
		submitHandler: function(form) {
			compFormSubmit(form);
		}
	});
	
	function compFormSubmit(form) {
		$(form).ajaxSubmit({ 
			target:".ajax_form_result", 
			beforeSubmit:function() {
				$("#compForm").css('display', 'none');
			    $(".ajax_form_result").html('<p>Sending your answer...</p>');
			},
			success:function(response) {
				$(form).resetForm();
				$(".ajax_form_result").html('<p>Your answer has been sent. Keep checking back to see if you are this months winner!</p>');
			}
		});
		return false;		
	}	
	
	$("#billForm").validate({
		rules: {
			email_address: {
				required: true,
				email: true
			}	
		},
		messages: {
			email_address: {
				required: "Please enter your email.",
				email: "Please enter a valid email."
			}		
		},
		errorClass: "error"
	});
	
	//shipping show hide
	$('#shipping_details').hide();
	
	if ($('#ship2bill').attr("checked")) {
			$('#shipping_details').hide();
	} else {
			$('#shipping_details').show();
	}
	
	
	$('input#ship2bill').change(function () {
		if ($(this).attr("checked")) {
			$('#shipping_details').slideUp('fast');
			$('#shipping_first_name, #shipping_last_name, #shipping_address, #shipping_city, #shipping_zip').removeClass('required');
			return;
		}
		$('#shipping_details').slideDown('fast');
		$('#shipping_first_name, #shipping_last_name, #shipping_address, #shipping_city, #shipping_zip').addClass('required');
		
	});
	
	$('#requestForm .inputBtn').click(function() {
		sizeVal();
		
		window.setTimeout(function() {
			$.colorbox.resize('inner_height');
		}, 1);
	})
	
	
	
});


