// JavaScript Document

$(document).ready(function() {
						   
	$("table#customer_details input").unbind();

	var do_copy = function(id, value) {
		var rep = id.replace(/customer/, "delivery");
		var current = $("#"+ rep + ":visible");
		if($(current).length > 0) { $(current).val(value); }
	}

	$("#copyaddress").change(function() {
		if($(this).is(":checked")) {
			$("table#customer_details input").each(function() { if($(this).attr("id") != "customerCountry") { do_copy($(this).attr("id"), $(this).val()); } });
		} else {
			$("table#delivery_details input:not('#deliveryCountry')").each(function() { $(this).val(""); });
		}
	});

	$("#customer_details").unbind().validate("#info_message p");


	// Payment and Delivery tabs. 

	$("#product_tabs a").click(function() {
	
		$("#tab_payment,#tab_delivery").hide();
		
		$("#"+$(this).attr("rel")).fadeIn();
		
		return false;
	
	});
	
	$(".close_button").click(function() {
	
		$("#tab_payment,#tab_delivery").fadeOut();
		
		return false;
	
	});
	
	
	
	
	// Remove text in input fields.
	
	var $t = new Array()
	$t["newsletter_name"] = $("input[name=newsletter_name]").val();
	$t["newsletter_email"] = $("input[name=newsletter_email]").val();
	$t["qs"] = $("input[name=qs]").val();
	
	var $c = new Array();
	$c["newsletter_name"] = $("input[name=newsletter_name]").css("color");
	$c["newsletter_email"] = $("input[name=newsletter_email]").css("color");
	$c["qs"] = $("input[name=qs]").css("color");

	$("input[name=newsletter_name], input[name=newsletter_email], input[name=qs]").focus(function() {
		
		if($(this).val() == $t[$(this).attr("name")]) { $(this).val("").css({"color": "#333"}); }
		
	}).blur(function() {
		
		if($(this).val() == "") { $(this).val($t[$(this).attr("name")]).css({"color": $c[$(this).attr("name")]}); }
		
	});



	// Top sliding banner. 

    $("#slide_holder").cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	
	
	// Carousel. 
	
	$("#logos ul").jcarousel({
        auto: 5,
        wrap: "circular",
		scroll: 6,
		animation: "slow"
    });
	
	
	
	// Brand selection.
	
	$("#productnav li").hover(function() {
		$("ul:first",this).show();
		$("ul:first",this).css("z-index", "100000");
	}, function() {
		$("ul:first",this).hide();
		$("ul:first",this).css("z-index", "");
	});
	
	$("#searchbox ul li").click(function() {
		if($("ul:first",this).is(":hidden")) {
			$("ul:first",this).stop(true, true).slideToggle();
			$("ul:first",this).css("z-index", "200");
		} else {
			$("ul:first",this).stop(true, true).slideToggle();
			$("ul:first",this).css("z-index", "");
		}
	});

});
