/* namespace Utils */
if (window.Utils == undefined)
{
	window.Utils = new Object();
}

if (Utils.apply == undefined)
{
		Utils.apply = function($this, method)
		{
			return function() { method.apply($this, arguments); };
		}
}

/* class Utils::ImageRotator consructor*/
/* string divID : what <div/> to rotate*/
Utils.ImageRotator = function(divID) 
{
	this._rotationQueue = new Array();
	this._intervalID = null;
	this._toggleSpeed = "slow";
	this._div = $("div#" + divID);

	// fill the rotation queue with images, contained in the div
	var $this = this;
	$("div#" + divID + " img").each(function(index){
		$this._rotationQueue.push(this);
	});
}

/* class Utils::ImageRotator */
Utils.ImageRotator.prototype = 
{
/*public:  */		
		startRotation: function(period, toggleSpeed)
		{
			this.stopRotation();
			
			if (toggleSpeed != undefined)
				this._toggleSpeed = toggleSpeed;
			this._intervalID = window.setInterval(Utils.apply(this, this._makeRotationStep), period);
		},
		stopRotation: function()
		{
			if (this._intervalID != null)
			{
				window.clearInterval(this._intervalID);
			}
		}, 

/*private:  */		
		_makeRotationStep: function() 
		{
			var toHide = this._rotationQueue.shift();
			var toShow = this._rotationQueue[0];
			this._toggle($(toHide), $(toShow));
			this._rotationQueue.push(toHide);
		}, 
		_toggle: function(jElemToHide, jElemToShow)
		{
			jElemToHide.fadeOut(this._toggleSpeed);
			jElemToShow.fadeIn(this._toggleSpeed);
		}
}