if (!Function.prototype.bind)
{
	Function.prototype.bind = function (instance)
	{
		var method = this;
		return function () { method.apply (instance, arguments); }
	}
}

// ------------------------------------------------------------------

if (!Function.prototype.apply)
{
	Function.prototype.apply = function (object, parameters)
	{
		var retval, method = '____apply', aparameters = [];

		if (!object) object = window;
		if (!parameters) parameters = [];
	
		for (var i=0; i<parameters.length; i++)
		{
			aparameters[i] = 'parameters[' + i + ']';
		}
	
		object[method] = this;
		retval = eval ('object[method] (' + aparameters.join (', ') + ')');
		delete object[method];
		return retval;
	}
}

// ------------------------------------------------------------------

function BannerRotator (img, href, delay, fade)
{
	if (typeof img == 'string')
	{
		img = document.getElementById (img);
	}

	if (typeof href == 'string')
	{
		href = document.getElementById (href);
	}
	
	this.img		= img;
	this.href		= href;
	this.delay		= (typeof delay == 'undefined') ? 5000 : delay;
	this.fade		= (typeof fade == 'undefined') ? true : fade;
	this.banners	= [];
	this.rotation	= 0;
	this.handler	= undefined;

	this.addBanner = function (uri, img)
	{
		this.banners[this.banners.length] = {uri:uri, img:img};
	}

	this.start = function ()
	{
		this.rotate ();
		this.handler = setInterval
		((
			function ()
			{
				this.rotate ();
			}
		).bind (this), this.delay);
	}

	this.stop = function ()
	{
		clearInterval (this.handler);
		this.handler = undefined;
	}

	this.rotate = function ()
	{
		if (this.fade && document.all)
		{
			this.img.style['filter'] = 'blendTrans(duration=2)';
			this.img.filters.blendTrans.Apply();
		}

		this.img.src	= this.banners[this.rotation].img;
		this.href.href	= this.banners[this.rotation].uri;
		
		if (this.rotation + 1 >= this.banners.length)
		{
			this.rotation = 0;
		} else 
		{
			this.rotation++;
		}

		
		if (this.fade && document.all)
		{
			this.img.filters.blendTrans.Play();
		}
	}
}