rotator.restartDelay = 500;
rotator.col=[];
rotator.ready=true;

function rotator(name,speed,path,tgt)
{
	this.name=name;
	this.speed=speed||4500;
	this.path=path||"";
	this.tgt=tgt;
	this.ctr=0;
	this.timer=0;
	this.imgs=[];
	this.actions=[];
	this.index=rotator.col.length;
	rotator.col[this.index]=this;
	this.animString="rotator.col["+this.index+"]";
};
rotator.prototype.addImages=function()
{
	var img;
	for(var i=0;arguments[i];i++)
	{
		img=new Image();
		img.src=this.path+arguments[i];
		this.imgs[this.imgs.length]=img;
	}
};
rotator.prototype.addActions=function()
{
	var len=arguments.length;
	for(var i=0;i<len;i++)
	this.actions[this.actions.length]=arguments[i];
};
rotator.prototype.rotate=function()
{
	clearTimeout(this.timer);
	this.timer=null;
	if(this.ctr<this.imgs.length-1)
	this.ctr++;
	else 
	this.ctr=0;var imgObj=document.images[this.name];
	if(imgObj&&rotator.ready)
	{
		imgObj.src=this.imgs[this.ctr].src;
		this.timer=setTimeout(this.animString+".rotate()",this.speed);
	}
};
rotator.start=function()
{
	var len=rotator.col.length,obj;
	for(var i=0;i<len;i++)
	{
		obj=rotator.col[i];
		if(obj&&obj.name)
		obj.timer=setTimeout(obj.animString+".rotate()",obj.speed);
	}
};
rotator.doClick=function(n)
{
	var obj=rotator.col[n];
	if(!document.images||!obj)
	return true;
	if(obj.actions&&obj.actions[obj.ctr])
	{
		if(typeof obj.actions[obj.ctr]=="string")
		{
			if(obj.tgt)
			{
				var win=window.open(obj.actions[obj.ctr],obj.tgt);
				if(win&&!win.closed)win.focus();
			}
			else
			{
				window.location=obj.actions[obj.ctr];
			}
		}
		else{obj.actions[obj.ctr]();
	}
}
return false;
};
rotator.pause=function(n)
{
	rotator.clearTimers(n);
};
rotator.clearTimers=function(n)
{
	var obj=rotator.col[n];
	if(obj)
	{
		clearTimeout(obj.timer);
		obj.timer=null;
	}
};
rotator.resume=function(n)
{
	rotator.clearTimers(n);
	var obj=rotator.col[n];
	if(obj)
	{
		obj.timer=setTimeout(obj.animString+".rotate()",rotator.restartDelay);
	}
};

rndrotator.prototype=new rotator();

function rndrotator(sp,pt,bClickable,bMouse,tgt)
{
	this.num=rotator.col.length;
	this.name="RandRotateImg"+this.num;
	this.mouseEvs=bMouse;
	this.clickable=bClickable;
	this.rObj=rotator;
	this.rObj(this.name,sp,pt,tgt);
};

rndrotator.prototype.setUpImage=function(imgAr,w,h,bTrans)
{
	this.trans=bTrans;
	this.ctr=Math.floor(Math.random()*imgAr.length);
	var img=imgAr[this.ctr];
	var imgStr='<img name="'+this.name+'" src="'+this.path+img+'"';
	imgStr+=(typeof w=="number")?' width="'+w+'"':'';
	imgStr+=(typeof h=="number")?' height="'+h+'"':'';
	imgStr+=' alt="">';
	var str="";
	if(this.clickable)
	{
		str+='<a href="" onclick="return rotator.doClick('+this.num+')"';
		if(this.mouseEvs)
		{
			str+=' onmouseover="rotator.pause('+this.num+')"';
			str+=' onmouseout="rotator.resume('+this.num+')"';
		}
		str+=' onfocus="this.blur()">'+imgStr+'</a>';
	}
	else
	{
		str=imgStr;
	}
	document.write(str);
	document.close();
	for(var i=0;imgAr[i];i++)this.addImages(imgAr[i]);
};

rndrotator.prototype.rotate=function()
{
	clearTimeout(this.timer);
	this.timer=null;
	var ctr=Math.floor(Math.random()*this.imgs.length);
	var i=0;
	while(ctr==this.ctr&&i<6)
	{
		ctr=Math.floor(Math.random()*this.imgs.length);i++;
	}
	this.ctr=ctr;
	var imgObj=document.images[this.name];
	if(!imgObj||!rotator.ready)return;
	if(this.trans&&typeof imgObj.filters!="undefined")
	{
		imgObj.style.filter='blendTrans(duration=1)';
		if(imgObj.filters.blendTrans)imgObj.filters.blendTrans.Apply();
	}
	imgObj.src=this.imgs[this.ctr].src;
	if(this.trans&&typeof imgObj.filters!="undefined"&&imgObj.filters.blendTrans)imgObj.filters.blendTrans.Play();
	this.timer=setTimeout(this.animString+".rotate()",this.speed);
};
