// Tooltip "help" function
$(function() {
	$('.bubbleInfo').each(function() {
		var time = 250;
		var hideDelay = 500;
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;
		var trigger = $('.trigger', this);
		var popup = $('.help-popup', this).css('opacity', 0);

		$([trigger.get(0), popup.get(0)]).mouseover(function() {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;
				popup.css({
					top: -11,
					left: -11,
					display: 'block'
				})
        .animate({ opacity: 1 }, time, 'swing', function() {
        	beingShown = false;
        	shown = true;
        });
			}
		}).mouseout(function() {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function() {
				hideDelayTimer = null;
				popup.animate({ opacity: 0 }, time, 'swing', function() {
					shown = false;
					popup.css('display', 'none');
				});
			}, hideDelay);
		});
	});
});

function SetCurrentlyActiveTopNavItem() {

	$("#main-nav").find("li").each(function() {
		var menuPath = $(this).attr("title");

		// remove the title
		$(this).attr("title", "");

		var curPath = location.pathname.toLowerCase()

		if (curPath.indexOf("/" + menuPath) >= 0) {
			$("body").attr("id", $(this).attr("class"));
			return false;
		}
	});
}
$(document).ready(function() {
	$(".trigger").live("mouseover", function() {
		var time = 2500;
		var hideDelay = 500;
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;


		//var popup = $('.colours-box-wrapper', this).css('opacity', 0);
		var popup = $(this).next().css('opacity', 0);
		if (hideDelayTimer) clearTimeout(hideDelayTimer);
		if (beingShown || shown) {
			return;
		}
		else {
			beingShown = true;

			popup.css({
				top: 9,
				right: -7,
				display: 'block'
			})

            .animate({ opacity: 1 }, time, 'swing', function() {
            	beingShown = false;
            	shown = true;
            });
		}


	});

	$(".trigger").live("mouseout", function() {

		var time = 0;
		var hideDelay = 250;
		var hideDelayTimer = null;

		var shown = true;
		var popup = $(this).next().css('opacity', 1);

		if (hideDelayTimer) clearTimeout(hideDelayTimer);

		hideDelayTimer = setTimeout(
          function() {
          	hideDelayTimer = null;
          	popup.animate({ opacity: 0 }, time, 'easing', function() {
          		shown = false;
          		popup.css('display', 'none');
          	});

          }, hideDelay);
	});


	// Tooltip on thumbnails in Shadowbox
	$(".iconbar li a").hover(
		function() {

			var iconName = $(this).find("img").attr("src");
			$(this).next("span").attr({
				"style": 'display:inline'
			});
			$(this).next("span").stop().show();
		},
		function() {
			var iconName = $(this).find("img").attr("src");
			$(this).next("span").attr({
				"style": 'display:none'
			});
			$(this).next("span").stop().hide();
		});

	$(".iconbar li span").hover(
		function() {
			$(this).attr({
				"style": 'display:block'
			});
			$(this).show();
		},
		function() {
			$(this).attr({
				"style": 'display:none'
			});
			$(this).hide();
		});

	$(".iconbar li span span").hover(
		function() {
			$(this).attr({
				"style": 'display:block'
			});
			$(this).show();
		},
		function() {
			$(this).animate({ opacity: 1 }, { queue: false, duration: 0 }, "linear",
				function() {
					$(this).attr({ "style": 'display:block' });
				});
		});



	// Tooltip on images in product details 

	$(".image-display-img-wrapper a").hover(
		function() {
			var iconName = $(this).find("img").attr("src");
			$(this).next("span").attr({
				"style": 'display:block'
			});
			$(this).next("span").stop().show();
		},
		function() {
			var iconName = $(this).find("img").attr("src");
			$(this).next("span").attr({
				"style": 'display:none'
			});
			$(this).next("span").stop().hide();
			
			//$(this).next("span").animate({ opacity: 0 }, { queue: false, duration: 0 }, "linear",
			//	function() {
			//		$(this).next("span").attr({ "style": 'display:none' });
			//	});
		});

	$(".image-display-img-wrapper span.image-tooltip").hover(
		function() {
			$(this).attr({
				"style": 'display:block'
			});
			$(this).show();
			
		},
		function() {
			$(this).animate({ opacity: 1 }, { queue: false, duration: 0 }, "linear",
				function() {
					$(this).attr({ "style": 'display:none' });
				});
		});


	$(".image-display-img-wrapper span span").hover(
		function() {
			$(this).attr({
				"style": 'display:block'
			});
			$(this).show();
		},
		function() {
			$(this).animate({ opacity: 1 }, { queue: false, duration: 0 }, "linear",
				function() {
					$(this).attr({ "style": 'display:block' });
				});
		});



	// Subnav styling related to parents of current item 

	$("#subnav a.current").parent("li").addClass("current-parent");
	$("#subnav li.current-parent").parent().parent().addClass("current-parent");
	$("#subnav ul li.current-parent").parent().parent().addClass("current-parent");

	$("#subnav a.current").each(function() {
		if ($(this).siblings().length < 1)
			$(this).parent("li").removeClass("current-parent")
	});


	// Green highlight box fadeout and disappear	

	$(".highlight a").click(function() {
		$(this).parents(".highlight").animate({ opacity: "hide" }, "slow");
	});

	// Red error message box fadeout and disappear	

	$(".error-msg a").click(function() {
		$(this).parents(".error-msg").animate({ opacity: "hide" }, "slow");
	});

	// Show/hide functionality for Detailed Technical Specifications table	

	$(".specifications-detailed table").hide();
	$(".btn-slide-hide").hide();

	$(".btn-slide-show").click(function() {
		$(".specifications-detailed table").slideDown("slow");
		$(this).hide();
		$(".btn-slide-hide").show();

	});

	$(".btn-slide-hide").click(function() {
		$(".specifications-detailed table").slideUp("fast");
		$(this).hide();
		$(".btn-slide-show").show();

	});

	// NZ map image map	

	$('.nz-map-blank area').mouseover(function() {
		var hoverAlt = $(this).attr("alt");
		$("#nz-map-overlay").removeClass();
		$("#nz-map-overlay").addClass(hoverAlt);
	});

	// Australia map image map	

	$('.aus-map-blank area').mouseover(function() {
		var hoverAlt = $(this).attr("alt");
		$("#aus-map-overlay").removeClass();
		$("#aus-map-overlay").addClass(hoverAlt);
	});

	//BBJ - clear search box on click
	$('.search-input').click(function() {
		$('.search-input').val('');
	});

	$('#jumpMenuGo').click(function() {

		var s = $('#jumpMenu').val();

		if (s != "")
			window.location = "/tools/search-products/product-details.aspx?code=" + s;
	});
});

function BindCartDropDown() {

	$(".cartbutton").hide();
	$(".thumbnail-block").css("display", "none");
	$("#imgSampletype").css("padding-left","50");
	$("#imgSampletype").hide();

	$(".CartDropDown").bind("change", function(e) {

	    var val = $(".CartDropDown").find('option').filter(':selected').attr("value");
	    

	    switch (val) {
	        case "1":
	            $(".cartbutton").show();
	            $(".CartMessage").css("display", "none");
	            $(".thumbnail-block").css("display", "none");
	            //Product_Card_Sample_Order.jpg
	            $("#imgSampletype").attr("src", "/resources/img/Product_Card_Sample_Order.jpg")
	            $("#imgSampletype").show();
	            break;

	        case "2":
	            $(".cartbutton").show();
	            $(".CartMessage").css("display", "none");
	            $(".thumbnail-block").css("display", "block");
	            //Colour_Sample.jpg
	            $("#imgSampletype").attr("src", "/resources/img/Colour_Sample.jpg")
	            $("#imgSampletype").show();
	            break;

	        default:
	            $(".cartbutton").hide();
	            $("#imgSampletype").hide();
	            break;
	    }

	});
}
	
	
