var currentImage = ("#image-a");
var currentThumb = ("#a img");
var d = new Date();

$(document).ready(function() {
	$("#image-a, #image-b, #image-c, #image-d, #image-e, #multi-fin-fab, .preview, #a, #b, #c, #d, #e, #popup-box-container").css("display","block");
	$("#image-b, #image-c, #image-d, #image-e, #multi-fin-fab, .preview, #popup-box-container").hide();
	$("#b img, #c img, #d img, #e img").css("opacity","0.4").css("filter","alpha(opacity=40)");
	$("#slider-box").css("display","block");
	$("#nav").css("display","block");
	$("#slide-spacer").css("height","310px");
	$("#slideshow").click(function() {
		
	});
	$('#slideshow').after('<div id="nav">').cycle({
				fx: 'scrollLeft',
				next: '#slideshow',
				easing: 'backinout',
				timeout: '3000',
				pager: '#nav'
				});
	$('#pause').click(function() { 
		$('#slideshow').cycle('pause'); 
	});
	$('#play').click(function() { 
		$('#slideshow').cycle('resume'); 
	});
	
//quantity validation
	$("#checkoutForm").submit(function() {
		var x = $(".quantity").val();
		
		if (x == 0)
		{
			$(".form-instruction").css('color','#ff0000','font-weight','bold');
			$(".form-instruction").effect("highlight", {color: "#ff0000"}, 1000);		
			return false
		}
		else
		{
		
		}
		
		if (x % quantitySubmit == 0) 
		{
			$(".form-instruction").css('color','#777777','font-weight','bold');
		}
		else
		{
			$(".form-instruction").css('color','#ff0000','font-weight','bold');
			$(".form-instruction").effect("highlight", {color: "#ff0000"}, 1000);
			return false
		}
	});
	
	$(".qty").focusout(function() {
		var x = $(".qty").val();
		if (x == quantitySubmit)
		{
			$(".form-instruction").css("color","#6A5952");
		}
		else
		{
			$(".form-instruction").css("color","red");
		}
	});

});


$(function() {
	
//about shipping rates {
	$(".shipping-rates").click(function() {
		$(".shipping-rates-info").css("display","block");
	});
	$(".shipping-rates-close").click(function() {
		$(".shipping-rates-info").css("display","none");
	});
		
	
//Image Inset Toggle	
	$("#a").click(function() {
		if(("#a img") == currentThumb) {}
		else {
			$(currentThumb).css("opacity","0.4").css("filter","alpha(opacity=40)");
			$(currentImage).fadeOut("normal");
			$("#a img").css("opacity","1").css("filter","alpha(opacity=100)");
			$("#image-a").fadeIn("normal", function() {		
				currentImage = ("#image-a");
				currentThumb = ("#a img");
			});
		}
	});
	
	$("#b").click(function() {
		if(("#b img") == currentThumb) {
			
		}
		else {
			$(currentThumb).css("opacity","0.4").css("filter","alpha(opacity=40)");
			$(currentImage).fadeOut("normal");
			$("#b img").css("opacity","1").css("filter","alpha(opacity=100)");
			$("#image-b").fadeIn("normal", function() {
				currentImage = ("#image-b");
				currentThumb = ("#b img");
			});
		}
	});
	
	$("#c").click(function() {
		if(("#c img") == currentThumb) {
			
		}
		else {
			$(currentThumb).css("opacity","0.4").css("filter","alpha(opacity=40)");
			$(currentImage).fadeOut("normal");
			$("#c img").css("opacity","1").css("filter","alpha(opacity=100)");
			$("#image-c").fadeIn("normal", function() {
				currentImage = ("#image-c");
				currentThumb = ("#c img");
			});
		}
	});
	
	$("#d").click(function() {
		if(("#d img") == currentThumb) {
			
		}
		else {
			$(currentThumb).css("opacity","0.4").css("filter","alpha(opacity=40)");
			$(currentImage).fadeOut("normal");
			$("#d img").css("opacity","1").css("filter","alpha(opacity=100)");
			$("#image-d").fadeIn("normal", function() {
				currentImage = ("#image-d");
				currentThumb = ("#d img");
			});
		}
	});
	
	$("#e").click(function() {
		if(("#e img") == currentThumb) {
			
		}
		else {
			$(currentThumb).css("opacity","0.4").css("filter","alpha(opacity=40)");
			$(currentImage).fadeOut("normal");
			$("#e img").css("opacity","1").css("filter","alpha(opacity=100)");
			$("#image-e").fadeIn("normal", function() {
				currentImage = ("#image-e");
				currentThumb = ("#e img");
			});
		}
	});
	
//Popup controls
	$(".open-popup").click(function() {
		$("#popup-box-container").fadeIn("fast");
	});
	
	$(".close-popup").click(function() {
		$("#popup-box-container").fadeOut("fast");
	});	
	
//Mouseover Cursor Change
	$("#a, #b, #c, #d, #e, .carousel-div, .search-submit").mouseover(function() {
		$(this).css("cursor","pointer");
	});
	$("#a, #b, #c, #d, #e, .carousel-div, .search-submit").mouseout(function() {
		$(this).css("cursor","auto");
	});
	
	$('#image-box img').mouseover(function() {
		$('#enlarge').css("background-position","0 -19px");
	});
	
	$('#image-box img').mouseout(function() {
		$('#enlarge').css("background-position","0 0");
	});

});
