function Rotato(images)
{
	if(typeof(images) != 'object' || !images.length)
	{
		alert('The images must be specified as an array:\nnew Rotato( [\'image1.jpg\', \'image2.jpg\', \'image2.jpg\'] )');
		return false;
	}
	
	this.images=images;
	this.current=0;
	
	this.addEvent(window, 'load', function()
	{
		var preload=[];
		
		for(i=0; i < images.length; i++)
		{
			preload[i]=new Image();
			preload[i].src=images[i];
		}
	}.bind(this));
}

Rotato.prototype.getCurrent = function(sequential)
{
	var next;
	
	this.current=(this.current+1) % this.images.length;
	if(sequential!==true)
		this.current=Math.round(Math.random()*(this.images.length-1));
	return this.images[this.current];
}

Rotato.prototype.addEvent = function(obj, evt, fn)
{
	if (obj.addEventListener)
		obj.addEventListener(evt, fn, false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt, fn);
	else
		obj['on'+evt] = fn;
}

Function.prototype.bind = function(object /*, 0..n args */)
{
	var method = this;
	var args = Array.prototype.slice.apply(arguments).slice.apply(arguments, [1]); 
	return function()
	{
		return method.apply(object, args);
	}; 
}