﻿var HighlightedProductSlider = function(pId) {
	var thisObj = new Object({
		
		id: pId,
		name: eval('"hps_' + pId + '"'),
		items: $("#inreach_"+pId).find("div.inreach_productWidget_item"),
		delay: 10000,
		animationTransition: 750,
		index: 0,

		initialize: function() {
			var maxHeight = 0;
			var lockedSize = $("#inreach_" + pId + " div.inreach_productWidget_lockedSize");
			$(this.items).each(function(intIndex) {
				$(this).width($(lockedSize).width());
				if ($(this).height() > maxHeight)
					maxHeight = $(this).height();
				$(this).find("input.inreach_productWidget_addToCart").attr("src", "/content/images/productWidget/btn_add_to_cart.png");
			});
			$(lockedSize).height(maxHeight);
			$(this.items).each(function(intIndex) {
				if ($(this).height() < maxHeight) {
					var navWrapper = $(this).find("div.inreach_productWidget_navWrapper");
					var offset = maxHeight - $(this).height();
					var sliverOfLight = $(this).find("div.inreach_productWidget_sliverOfLight")[1];
					$(navWrapper).css("margin-top", offset + "px");
					$(sliverOfLight).css("margin-top", parseInt($(sliverOfLight).css("margin-top")) + offset);
					$(this).height(maxHeight);
				}
				$(this).css("margin-top", -maxHeight);
			});

			<!-- Fix for DE1582 -->
			this.show(0);

			this.start();
		},

		show: function(x) {
			this.stop();
			this.hide();
			$(this.items[x]).fadeIn(this.animationTransition, function() { }, "easing");
			this.index = x;
			this.start();
		},

		hide: function() {
			if (this.index >= 0)
				$(this.items[this.index]).fadeOut(this.animationTransition, function() { }, "easing");
		},

		next: function() {
			if (this.index == this.items.length - 1) {
				this.hide(this.index);
				this.index = -1;
			}
			this.show(this.index + 1);
		},

		start: function() {
			this.interval = setInterval(this.name + ".next()", this.delay);
		},

		stop: function() {
			clearInterval(this.interval);
		}

	});

	thisObj.initialize();

	return thisObj;
}
