jQuery.noConflict();
(function($) {
$(function() {
	$(".price p").each(function() {
		var $this = $(this);
		if ( $this.text().indexOf(".") > 0 ) {
			$this.text($this.text().split(".")[0])
		}
	});

	$("#product-addtocart").click(function(e) {
		e.preventDefault();
		$("#product-form").submit();
	});
	
	$("#update_cart, .update_cart").click(function(e) {
		e.preventDefault();
		$("#cart-form").submit();
	});
	
	$("#contact-submit").click(function(e) {
		e.preventDefault();
		$("#contact-form").submit();
	});
	
	/*
		Products page: set all products to the larget height
	*/
   var height = [];
   var products = $("#products .product");
   for (var i = 0; i < products.length; i++) {
       height.push($(products[i]).outerHeight());
   };
   var largest = Math.max.apply(Math, height);
   $("#products .product").css({
       height: largest
   });
	
	/*
		Product detail slideshow
	*/
	$("#photos #detail img:eq(0)").fadeIn(300, function() {
		$("#photos #detail").css({
			height: $("#photos #detail img:eq(0)").height() + 20
		});
	}).addClass("current");

  $("#photos #thumbnails a").bind("click", function (e) {
      e.preventDefault();
			var total = $("#photos #detail img").length;
      if (total < 2) {
				return false;
			}
			var selectedIndex = ($(this).data("image")*1) - 1;
      var $next = $("#photos #detail img:eq(" + selectedIndex + ")");
			
			$("#photos #detail .current").css({
          zIndex: 0,
          display: "none"
      }).removeClass("current");
			
      $next.css({
          zIndex: 100
      }).stop().fadeIn(300, function () {
					$("#photos #detail").animate({
						height: $("#photos #detail img:eq(" + selectedIndex + ")").height() + 20
					}, 180);

          $next.css({
              zIndex: 0
          }).addClass("current");
      });
  });

	$("#subscribe").click(function(e) {
		e.preventDefault();
		$("#mc-embedded-subscribe-form").submit();
	});
	
	$(".remove-item").click(function(e) {
		e.preventDefault();
		$(this).parents("tr").find(".item-qty input").val(0)
    $("#cart-form").submit();
	});
});
})(jQuery);
