
function bsPubRotator(container, objectName){
	
	this.pubs 				= new Array();
	this.position			= 0;
	this.container  	= jQuery('#' + container)[0];
	this.objectName  	= objectName;
	var date          = new Date().getTime();
	this.divName			= 'pub_' + date;
	this.clickBanner  = 'clickBanner_' + date;
	
	this.addPub  = function(pub)
	{
		this.pubs.push(pub);
	}
	
	
	this.launch  = function()
	{
		this.display();
		var timer = this.pubs[this.position++]['timer'] * 1000;
		if (timer == 0) timer = 5000;
		window.setTimeout(this.objectName + '.launch()', timer);
	}
	
	this.display  = function()
	{
		if ((this.position == this.pubs.length) ||
			this.pubs.length == 0) this.position = 0;
		
		var link   	  = this.pubs[this.position]['link'];
		var aElt			= document.createElement('a');
		var spanElt   = document.createElement('span');
		var data			= this.rendererContent();
		
		spanElt.id    = this.clickBanner;
		spanElt.setAttribute('onclick', 'window.location="'+link+'"');
		aElt.id				= this.divName;
		aElt.href			= link;
		aElt.innerHTML		= data;
		
		if (!jQuery('#' + this.divName)[0]){
		  this.container.appendChild(spanElt);
			this.container.appendChild(aElt);
		}else{
		  this.container.replaceChild(spanElt, jQuery('#' + this.clickBanner)[0]);
			this.container.replaceChild(aElt, jQuery('#' + this.divName)[0]);
		}
	}
	
	this.rendererContent = function ()
	{
		var type 			= this.pubs[this.position]['type'];
		var source 			= this.pubs[this.position]['src'];
		
		if (type == 'image')
		{
			return '<img src="' + source + '" height="' + this.container.clientHeight +
				   '" width="' + this.container.clientWidth + '" />'
		}
		if (type == 'flash')
		{
			return '<object width="' + this.container.clientWidth + '" height="' + this.container.clientHeight + '">' +
				   '<param name="movie" value="'+source+'"><param name="wmode" value="transparent">'+
				   '<embed src="' + source + '" width="' + this.container.clientWidth + '" height="' + 
				   this.container.clientHeight + '" wmode="transparent"></embed></object>';
		}
	}
}


