﻿jQuery(document).ready(function() {
	jQuery(".IR_container").each(function(i) {
		var interval = 5;

		if (this.className && this.className.indexOf("interval_") != -1 && this.className.indexOf("fixed") == -1)
		{
			var classNames = this.className.split(" ");
			for (var j = 0, jj = classNames.length; j < jj; j++)
			{
				var cName = classNames[j];
				if (cName.indexOf("interval_") == 0)
				{
					interval = cName.substring(cName.lastIndexOf("_") + 1);
					break;
				}
			}
		}

		jQuery(this).addClass("fixed");
		if (!this.id)
			this.id = "wpImageRotator_" + i;

		if (jQuery(this).children().length > 1)
		{
			setInterval(function(that) {
				return function() {
					var current = (jQuery("#" + that.id + " .show") ? jQuery("#" + that.id + " .show") : jQuery("#" + that.id + " :first"));
					var next = ((current.next().length) ? ((current.next().hasClass("show")) ? jQuery("#" + that.id + " :first") : current.next()) : jQuery("#" + that.id + " :first"));

					if (that.style.minHeight && that.style.minHeight.length > 0)
					{
						var minHeight = parseInt(that.style.minHeight, 10);
						var currentHeight = parseInt(current.height(), 10);
						if (minHeight < currentHeight)
							that.style.minHeight = currentHeight + "px";
					}
					else
					{
						that.style.minHeight = current.height() + "px";
					}

					current.removeClass("show").fadeOut("slow");
					next.fadeIn("slow").addClass("show");
				}
			}(this), (interval * 1000));
		}

		//alert(jQuery(this).children().length);
	});
});
