// JavaScript Document

$(document).ready(function() {

	$("#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;
	
	});
	
	
	
	// New checkout functionality.
	

	
	
	
	// 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")]}); }
		
	});
	
	
	
	// Train marquee.
	
	$("#banner_scroll, #banner_soldier, #banner_train").hide();
	
	$("#banner_scroll").fadeIn(1000);
	setTimeout(function() { $("#banner_train").css({"left": -520}).show().animate({left: '+=520'}, 5000); }, 1000);
	setTimeout(function() { $("#banner_soldier").css({"right": -91}).show().animate({right: '+=91'}, 1000); }, 6000);



	// Top sliding banner. 

    $("#slide_holder").cycle({ fx: "fade" });
	
	
	
	// 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", "");
		}
	});
	
});
