$(document).ready(function() {
	
	var pathname = window.location.pathname;
	switch(pathname) {
		case "/pages/About-Us.html":
			$("#n17").addClass("active");
			break;
		case "/pages/Safe-Sex.html":
			$("#n15").addClass("active");
			break;
		case "/pages/Stockists.html":
			$("#n16").addClass("active");
			break;
		case "/pages/Video.html":
			$("#n18").addClass("active");
			break;
		case "/categories/Condoms/":
			$("#n12").addClass("active");
			$('#sidecat .Condoms').addClass("active");
			break;
			
		case "/products/Ribbed-Condoms.html":
			$("#n12").addClass("active");
			break;
		case "/products/The-Naughty-Pack.html":
			$("#n12").addClass("active");
			break;
		case "/products/Ultra-Thin-Condoms.html":
			$("#n12").addClass("active");
			break;
		case "/products/VIP-Pack.html":
			$("#n12").addClass("active");
			break;		
			
		case "/categories/Underwear/":
			$("#n13").addClass("active");
			$('#sidecat .Underwear').addClass("active");
			break;
		
		case "/categories/T%252dShirts/":
			$("#n13").addClass("active");
			break;
			
		case "/products/Grey-Goose.html":
			$("#n13").addClass("active");
			break;
		case "/products/Mellow-Yellow.html":
			$("#n13").addClass("active");
			break;
		case "/products/The-Darth.html":
			$("#n13").addClass("active");
			break;
		case "/products/The-Limey.html":
			$("#n13").addClass("active");
			break;
		case "/products/The-Whitey.html":
			$("#n13").addClass("active");
			break;
		case "/categories/Limited-Edition/":
			$("#n14").addClass("active");
			$('#sidecat .Limited').addClass("active");
			break;
			
		case "/products/Fluffy-Bunny.html":
			$("#n14").addClass("active");
			break;
		case "/products/Four-Girls.html":
			$("#n14").addClass("active");
			break;
		case "/products/The-Marilyn.html":
			$("#n14").addClass("active");
			break;
		default:
			break;	
	}


	/* hide inactive sizes */
	/* hide everything first, then display depending on whats available. */
	/* alternatively hide them all initiall using CSS */
	$("ul#SizeSelections li").each( function () {
		$(this).hide();	
	});
	$(":radio").each( function () {
		$("#SizeSelections_"+$(this).val()).show();	
	});

	/*
	this function maps the gui elements to the variatopn selection elements
	*/

	$("#SizeSelections li a").each(function(){
        $(this).bind('click', function(e){
			$("#SizeSelections li a").each(function(){
				$(this).parent().removeClass("active");			
			});
			$(this).parent().addClass("active");
			
			//alert($(this).parent().index()+1);
			var correctIndex = $(this).parent().index()+1; /* otherwise it concats the two as a string*/
			$(":radio[value=" + correctIndex + "]").attr("checked", true);
			$(".CartVariationId").val($(":radio[value=" + correctIndex + "]").val()); /* REQUIRED */
			//alert($(".CartVariationId").val());
    	});
	});

	/* hide manage account link if current userf firstname is blank */
	$('#manageaccount[class=""]').hide();



	/* deletes the empty paragraph interspire inserts above the form on the contact page */
	$("body#contact p > br").each(function(){
		$(this).parent().hide();	
	});
	/* removes the last / in the breadcrumbs that interspire create */
	$("body#product .nav-path li:last").css("backgroundImage","none");
	$("body#createaccount .nav-path li:last").css("backgroundImage","none");

	$("#searchform").submit(function() {
		return ($("#search_query").val() != $("#search_query").attr("defaultValue"));	
	});
	
	
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

});
