(function($) {
	$.fn.promobox = function(repeat, sec) {
		var rand = Math.floor(Math.random() * 4) + 1;
	 	var timer = setInterval(function() {nextPromo()}, sec * 1000);
		var main = this;
	  function nextPromo() {
	    if (main.find("> div:visible").attr("id") != "promo-4") {
		  	main.find("> div:visible").hide().next().show();
				main.find(".ui-state-active").removeClass("ui-state-active").next().addClass("ui-state-active");
			}
			else {
	    	main.find("> div:visible").hide();
				main.find("> div:first").show();
				main.find(".ui-state-active").removeClass("ui-state-active");
				main.find("li:first").addClass("ui-state-active");
			}
			if (!repeat)
				if (main.find(".ui-state-active").find("a").attr("rel") == rand)
			  	clearInterval(timer);
		}
		this.find("> div").hide();
		this.find("#promo-"+rand).show();
		this.find("a[rel="+rand+"]").parent().addClass("ui-state-active");
 		this.find("li").mouseenter(function() {
			clearInterval(timer);
			main.find(".ui-state-active").removeClass("ui-state-active");
			$(this).addClass("ui-state-active");
			main.find("> div").hide();
			main.find("#promo-"+jQuery(this).find("a").attr("rel")).show();
		});
		return this;
	};
})(jQuery);