
function BrRotator(){
this.cookieName="lastShowedBanerNr"
this.queue=new Array()
this.addBaner=function(url,target,type,graphicsParams,flashvars){
	var ob=new Object()
	ob.url=url
	ob.target=target
	ob.type=type
	ob.graphicsParams=graphicsParams
	ob.flashvars=flashvars
	this.queue[this.queue.length]=ob
}
	this.readCookie=function(name){
	    var search = name + "=";
	    var ret=null;
	    if (document.cookie && document.cookie.length > 0) {
		    var offset = document.cookie.indexOf(search);
		    if (offset != -1) {
			    offset += search.length;
			    var end = document.cookie.indexOf(";", offset);
			    if (end == -1)
				    end = document.cookie.length;
			    ret= unescape(document.cookie.substring(offset, end))   ;
			    };
		    };
	    return ret;
	 };
	this.setCookie=function (cookieName,cookieValue,nDays) {
		 var today = new Date();
		 var expire = new Date();
		 if (nDays==null || nDays==0) nDays=1;
		 expire.setTime(today.getTime() + 3600000*24*nDays);
		 document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString()+" ;path=/";              
	}
	this.setHTML=function(nr,htmlId){
	var asOb=this.queue[nr]
	if(asOb.type=="flash"){
		try{
			var emb=new PluginEmbeder()
			}catch(e){
			alert("Required plugin - embeder")
		}
			try{
			for(var el in asOb.graphicsParams){
				emb.addAttribute(el,asOb.graphicsParams[el])
			}
			if(typeof(asOb.flashvars)=="object"){
				for(var el in asOb.flashvars){
				emb.addVariable(el,asOb.flashvars[el])
			}
			}
			emb.addVariable("targeturl",asOb.url)
			emb.addVariable("target",asOb.target)
			emb.assignToElement(htmlId)
		}catch(e){
			
		}
	}
	}
	this.assign=function(htmlId){
	var lastShowed;
	 var showNr;
	 var randomBaner=false
	 this.setCookie("testCookie","ok",1);
	 if(this.readCookie("testCookie")!="ok"){
	 	randomBaner=true
	 }else{
		  lastShowed=this.readCookie(this.cookieName)
		  if(lastShowed===null){
		 	 randomBaner=true
		  }else{
			  showNr=parseInt(lastShowed)+1
			  if(showNr>=this.queue.length){
			  	showNr=0
			  }
		  }	  
	  }
	  if(randomBaner){
	  	showNr=Math.round((this.queue.length-1)*Math.random())
	  }
	  this.setCookie(this.cookieName,showNr,1)
	  this.setHTML(showNr,htmlId)
	  }
}
