function AdvertisementChanger(containerId, handleName, width, height, interval)
{
	this.timer = null;
	this.timerEnabled = false;
	
	this.index = 0;
	this.width = width;
	this.height = height;
	this.interval = interval;
	this.handleName = handleName;
	this.containerId = containerId;
	this.advertisements = new Array();
	
	this.Add = Add;
	this.Start = Start;
	this.Stop = Stop;
	this.TimerTick = TimerTick;
}

function Add(newAdvertisement)
{
	this.advertisements.push(newAdvertisement);
}

function Start()
{
	if (!this.timerEnabled)
	{
		this.index = 0;
		this.TimerTick();
		this.timerEnabled = true;
	}
}

function Stop()
{
	if (this.timerEnabled)
	{
		clearTimeout(this.timer);
		this.timerEnabled = false;
	}
}

function TimerTick()
{
	var nextAdvertisement = 
		this.advertisements[this.index % this.advertisements.length];
	switch (nextAdvertisement[0])
	{
		case 0:  //obrazek
		{
			if (nextAdvertisement[2].length > 0)
			{
				document.getElementById(this.containerId).innerHTML =
					'<a href="' + nextAdvertisement[2] + '" target="_blank"><img style="border-style:none; width: ' + 
					this.width + 'px; height:' + this.height + 'px;" src="' + nextAdvertisement[1] + '" /></a>';
			}
			else
			{
				document.getElementById(this.containerId).innerHTML =
					'<img style="width: ' + this.width + 'px; height:' + 
					this.height + 'px;" src="' + nextAdvertisement[1] + '" />';
			}
		}; break;
		case 1:  //flash
		{
			document.getElementById(this.containerId).innerHTML =
				'<object width="' + this.width + '" height="' + this.height + '" ' +
				'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' +
				'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">' +
				'<param name="wmode" value="transparent"><param name="movie" value="' + nextAdvertisement[1] + '">' +
				'<param name=quality value=high><param name=bgcolor value=#FFFFFF>' +
				'<embed type="application/x-shockwave-flash" src="' + nextAdvertisement[1] + 
				'" width="' + this.width + '" height="' + this.height + '" ' +
				'pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
		}; break;
	}
	if (this.interval > 0)
	{
		this.timer = setTimeout(this.handleName + ".TimerTick()", this.interval * 1000);
		this.index++;
	}
}
