$(document).ready(function(){
	
	//preload images
	$.preload_imagelist = new Array();
	$.preload_imagelist[0] = new Image();
	$.preload_imagelist[0].src = "/images/banner/banner2.png";
	$.preload_imagelist[1] = new Image();
	$.preload_imagelist[1].src = "/images/banner/banner1.png";
	$.preload_imagelist[2] = new Image();
	$.preload_imagelist[2].src = "/images/banner/banner4.png";
	$.preload_imagelist[3] = new Image();
	$.preload_imagelist[3].src = "/images/banner/banner3.png";
	$.preload_imagelist[4] = new Image();
	$.preload_imagelist[4].src = "/images/banner/banner5.png";

//change image
$(".catalogueitemdump > li").each(function(i){
  $(this).bind("mouseover", {index:i}, function(e){
    $("#banner").attr("src", $.preload_imagelist[e.data.index].src);
  });
});

//catelog highlight
var currentURL = window.location.href;
var URLParts = currentURL.split("/");
var Cat = "/"+URLParts[3]+"/";
$(".catalogueitemdump > li").each(function(i){
$(this).find("a").each(function(){
var isMatch = $(this).attr("href").search(Cat);
if(isMatch != -1){
$(this).css("color","#ff7d40");
}else{
$(this).css("color","#fff");
}
});
});

//pop-up box
$(".small-product-img").each(function(i){
 $(this).bind("mouseover", function(e){
  var left = $(this).position().left;
  var top = $(this).position().top;
  $("#intro_box").css("left",left+20);
  $("#intro_box").css("top",top-109);
  $("#intro_box").html($(this).find(".hidden_info").html());
  $("#intro_box").fadeIn("fast");
 });
 $(this).bind("mouseout", function(e){
  $("#intro_box").css("display","none");
  $("#intro_box").empty();
 });
});

//remove blank image
$("img").each(function(i){
  if ($(this).attr("src")==""){
   $(this).remove();
  }
});


fixCartlink();

showAddSampleBtn();

});

function fixCartlink() {
	$(".cartSummaryItem").css({
	'position': 'relative',
	'z-index': '200'
	});
}

function showAddSampleBtn(){
	//add sample to cart
	if($(".productSelectInput").children().size()>1){
		$("#BtnAddSampleToCart").show();
	}else{
		$("#BtnAddSampleToCart").hide();
	}
}

function add_sample_to_cart() {
	
	old_quantity=$("input[name='AddToCart_Amount']").val();
	
	if($(".productSelectInput").children().size()>1){
		$(".productSelectInput option").each(function(obj){
			this.selected=false;
		});
		$(".productSelectInput option:last").attr("selected", "selected");
	}
	$("select[id^='Grouping']").trigger('change');
	$("input[name='AddToCart_Amount']").val(old_quantity);
	$("input[name='AddToCart_Submit']").trigger('click');

	if($(".productSelectInput").children().size()>1){
		$(".productSelectInput option").each(function(obj){
			this.selected=false;
		});
		$(".productSelectInput option:first").attr("selected", "selected");
	}
	$("select[id^='Grouping']").trigger('change');
	$("input[name='AddToCart_Amount']").val(old_quantity);
	
	showAddSampleBtn();
	extraImg();
	return false;
}

function add_product_to_cart() {
	
	if($(".productSelectInput").get(0)){
		$(".productSelectInput option").each(function(obj){
			this.selected=false;
		});
		$(".productSelectInput option:first").attr("selected", "selected");
	}
	old_quantity=$("input[name='AddToCart_Amount']").val();
	$("select[id^='Grouping']").trigger('change');
	$("input[name='AddToCart_Amount']").val(old_quantity);
	$("input[name='AddToCart_Submit']").trigger('click');
	
	showAddSampleBtn();
	extraImg();
	return false;
}
