
new ShufflerController($("#Shufflers"), 1500, 5000);

function ShufflerController (jqo, FadeTime, Delay)
{
	var me = this;
	this.jqo = jqo;
	this.w = this.jqo.width();
	
	this.Shuffle = function () {
		me.childDivs.fadeOut(FadeTime, me.ShuffleElement).fadeIn(FadeTime);
		setTimeout(me.Shuffle, FadeTime + FadeTime + Delay);
	}
	
	this.ShuffleElement = function () {
		var jqo = $(this); // context of the element
		var wrange = me.w - jqo.data("w");
		var newx = Math.random() * wrange;
		jqo.css("left", Math.round(newx) + "px");
	};

	this.childDivs = this.jqo.children("div");
	this.childDivs.each(
		function () { 
			var jqo = $(this);
			jqo.css("float", "left");
			var w = jqo.width();
			jqo.data("w", w);
			jqo.css( { width: w + "px", cssFloat: "none", position: "relative" } );
		}
	).each(me.ShuffleElement);

	setTimeout(me.Shuffle, Delay);
}

