PromoSlider = function()
{
	var i, c, ns;
	if (arguments.length)
	{
		this.items = arguments[0].css("display", "none");
		this.navs = (ns = arguments[1]);
		this.navOnClass = arguments[2] ? arguments[2] : "nav_item_selected";
		this.onclick = arguments[3] ? arguments[3] : function() { return true; };
		for (i = 0, c = ns.length; i < c; i++)
		{
			jQuery("a", ns.eq(i)).click(this.anonNavClick(this, i));
		}
		this.count = this.items.length;
		this.select(0);
	}
}
new PromoSlider();

PromoSlider.hasFocus = true;

PromoSlider.prototype =
{
	"count": null,
	"ind": null,
	"timeoutMs": 10000,
	"timeoutId": null,
	"lastIter": 0,
	"items": null,
	"navs": null,
	"anonNavClick": function(obj, i)
	{
		var f = function()
		{
			return obj.select(i);
		};
		return f;
	},
	"select": function(ind)
	{
		var nextInd, obj = this, items = this.items, navs = this.navs;

		if (!this.onclick(ind))
		{
			return false;
		}

		if (this.timeoutId)
		{
			clearTimeout(this.timeoutId);
		}
try
{
	if (window.location.search.match(/cat=fud/))
	{
		jQuery("body").prepend("Too fast:"+Math.floor(((new Date()).getTime() - this.lastIter) / 1000)+"s ("+PromoSlider.hasFocus+")<br/>");
	}
}
catch (e)
{
	// no hagas nada
}
		if (!PromoSlider.hasFocus)
		{
			this.timeoutId = setTimeout(function() { obj.select(ind); }, this.timeoutMs);
			return false;
		}

		if (this.ind !== null)
		{
			items.eq(this.ind).fadeOut("slow");
			navs.eq(this.ind).removeClass(this.navOnClass);
		}
		items.eq(ind).fadeIn("slow");
		navs.eq(ind).addClass(this.navOnClass);

		this.ind = ind;

		nextInd = ind + 1;
		if (nextInd == this.count)
		{
			nextInd = 0;
		}

		this.lastIter = (new Date()).getTime();
		this.timeoutId = setTimeout(function() { obj.select(nextInd); }, this.timeoutMs);
		return false;
	}
};

jQuery
(
	function()
	{
		jQuery(window).focus(function() {
				PromoSlider.hasFocus = true;
		});

		jQuery(window).blur(function() {
				PromoSlider.hasFocus = false;
		});
	}
);


