function BannerAd(id,graphic,displaytime)
{
	this.id = id;
	this.hyperlink = 'CountAd.asp?ID=' + this.id;
	this.graphic = graphic;
	this.displaytime = displaytime * 1000;
}

function BannerAdRotator(element) 
{
	// Private members
	var _currentAd = 0;
	var _timer     = null;
	var _Ads       = new Array();
	var _e         = element;
	var _a         = null;
	var _img       = null;

	// Public Members
	this.construct = construct;
	this.add = add;
	this.rotate = rotate;
	this.display = display;
	this.timer = timer;
	this.pause = pause;
	this.resume = resume;
	this.theLink = theLink;

	// Instantialize a few values here
	construct();

	// Method definitions
	function construct()
	{
		_a   = _e.firstChild;
		_img = _a.firstChild;
	}

	function add(anAd)
	{
		_Ads.push(anAd);
	}
	
	function rotate()
	{
		_currentAd = _currentAd + 1;
		if (_currentAd >= _Ads.length)
		{
			_currentAd = 0;
		}
		
		var closed = this;
		closed.display();
	}
	
	function display()
	{
		var closed = this;
		var ad     = _Ads[_currentAd];
		
		if (ad.graphic != null && ad.graphic != "")
		{
			_a.href = ad.hyperlink;
			_img.src = ad.graphic;
			
			_e.style.display = 'block';
		}
		else
		{
			_e.style.display = 'none';
		}
		
		if (ad.displaytime > 0)
		{
			_timer = setTimeout(function() {closed.rotate();}, ad.displaytime);
		}
	}

	function timer()
	{
		return _timer;
	}
	
	function pause()
	{
		clearTimeout(_timer);
	}
	
	function resume()
	{
		var closed = this;
		var ad     = _Ads[_currentAd];
		clearTimeout(_timer);
		_timer = setTimeout(function() {closed.rotate();}, ad.displaytime);
	}
	
	function theLink()
	{
		return _a;
	}
}		

