/*! Author: Roger Sullivan & some copy/paste from the Internet :) */

$(".sliderWrapper").ready(function() {
	$(".sliderWrapper").animate({opacity:1},1000); // Fade in homepage slider when it's good and ready
	$("#slider").anythingSlider();  //call AnythingSlider plugin
});
$(".headerImage").ready(function() {$(".headerImage").animate({opacity:1},1000);}); // Fade in subpage header when it's good and ready
$("#testimonials").ready(function() {$("#testimonials").animate({opacity:1},1000);}); // Fade in testimonial rotator when it's good and ready
$("#testimonials").jshowoff(); //Call testimonial rotator
$(".saltBadge").ready(function() { //add a link to the bath salt div if the right one exists
	$(".saltBadge_1").append("<a href='/enfusia-bath-line/bath/bulk-salt' class='bathSaltBadgeLink'>Buy Bulk Salt In Stores</a>");
});  
$("document").ready(function() {  // View Bath link stuff
	$("a.cartSummaryLink").html("View Bath"); //Change "View Cart text to "View Bath on button
	var cart = $("table.cartSummaryTable tr").find("td:first").html(); //find the contents of the cartSummaryTable
	var emptyCart = "Quote cart is empty."; // we don't want to see this
	if(cart === emptyCart) { // check if the cartSummary table is what we don't want
		$("td.cartSummaryItem").css("opacity", 0);// if we don't want it hide it
		$(".viewBath").html("<a class='emptyBathLink' href='/products.htm'>Empty Bath</a>"); //but we still want to see the empty bath icon, so I just made one... Boom!
	}
	else { //but now I do want to see the cart if there's stuff in there
		$("td.cartSummaryItem").css("opacity", 1);//show it!
	}
	$(".cartSummaryTable").animate({opacity:1},300); // now show it all... smoothly
});
$(".productsCatalogue").ready(function() { //add dashed lines to the porduct cataloge pages
	$("ul.catalogueList li.catalogueItemLast").after("<div class='shopCatalogueBorderBottom'></div>");
	$("ul.productList li.productItemLast").after("<div class='shopCatalogueBorderBottom'></div>");
});
$("document").ready(function() { //parse contact page hash on page load to select correct contact form
	$(".contactFormItem").hide();
	$(".always").show();
	$("#CAT_Custom_295863_0").click(function(){
		window.location.hash = "#comments"
	});
	$("#CAT_Custom_295863_1").click(function(){
		window.location.hash = "#testimonial"
	});
	$("#CAT_Custom_295863_2").click(function(){
		window.location.hash = "#general"
	});
	$("#CAT_Custom_295863_3").click(function(){
		window.location.hash = "#wholesale"
	});
	$(window).hashchange(function() {
		var hash = location.hash;
		if(hash == ""){
			return;
		}else if(hash === "#comments"){
			$(".both").show("slow");
			$(".wholesale").hide("slow");
			$("input#CAT_Custom_295863_0").attr("checked", true);
		}else if(hash === "#testimonial"){
			$(".both").show("slow");
			$(".wholesale").hide("slow");
			$("input#CAT_Custom_295863_1").attr("checked", true);
		}else if(hash === "#general"){
			$(".both").show("slow");
			$(".wholesale").hide("slow");
			$("input#CAT_Custom_295863_2").attr("checked", true);
		}else if(hash === "#wholesale"){
			$(".both").show("slow");
			$(".wholesale").show("slow");
			$("input#CAT_Custom_295863_3").attr("checked", true);
		}else{
			return;
		}
	});
$(window).trigger( 'hashchange' );
});
$("#galleryWrapper").ready(function() {	// Our Story gallery						
	$("#galleryWrapper").animate({opacity:1},1000); // Fade in our story gallery when it's good and ready
	$("#slides").cycle({ // Enfusia in Stores gallery call
		fx:     "fade", 
		timeout: 7000, 
		delay: 5000,
		pager:  "#slideThumbs",
		prev: "#os-prev",
		next: "#os-next",
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return "#slideThumbs a:eq(" + idx + ")"; 
		}
	});
	$("#slidesProcess").cycle({ // Facilities and Process gallery call
		fx:     "fade", 
		timeout: 7000, 
		delay: 5000,
		pager:  "#slideThumbsProcess",
		prev: "#os-prev",
		next: "#os-next",
		pagerAnchorBuilder: function(idx, slide) { 
			// return selector string for existing anchor 
			return "#slideThumbsProcess a:eq(" + idx + ")"; 
		}
	});
	$("#galleryWrapper").hover(
		function () {
			$("#os-prev, #os-next").animate({opacity: ".5"}, 500);
		}, 
		function () {
			$("#os-prev, #os-next").animate({opacity: "0"}, 500);
		}
	);
	$("#os-prev, #os-next").hover(
		function () {
			$(this).animate({opacity: "1"}, 200);
		}, 
		function () {
			$(this).animate({opacity: ".5"}, 200);
		}
	);
});
function AddProductExtras(){document.location.reload(true);} //reload page after adding an item to the cart so that the DOM will reload for the View Bath trickery
