
rotator.ready=true;
rotator.restartDelay = 500; // delay onmouseout before call to rotate
rotator.col=[];
function rotator(name,speed,path,width,height){
	
	this.name=name;
	this.speed=speed||4500;
	this.path=path||"";
	this.width=(width) ? ' width="'+width+'"' : '';
	this.height=(height) ? ' height="'+height+'"' : '';
	this.ctr=0;
	this.timer=0;
	this.imgs=[];
	this.index=rotator.col.length;
	rotator.col[this.index]=this;
	this.animString="rotator.col["+this.index+"]";
};
rotator.prototype.setItems=function(){
	for(var i=0;arguments[i];i++){
		this.imgs[this.imgs.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=fetch_object(this.name);
	if(imgObj&&rotator.ready){

		var matches = this.imgs[this.ctr].split('|');
		var imgSrc = this.path+matches[0];	
		var imgExt = matches[0].substr(-3);
		if(imgExt.toLowerCase() == 'swf'){
			imgObj.innerHTML = '<div ><object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0"'+this.width+this.height+'><param name="movie" value="'+imgSrc+'"><param name="quality" value="High"><param name="wmode" value="transparent"><embed src="'+imgSrc+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"'+this.width+this.height+' quality="High"></object></div>';
		}else{
		   var _str = (matches[1]) ? '<a href="'+ matches[1] +'" target="'+ matches[2] +'">' : '';
		   _str += '<img border="0" src="'+imgSrc+'"'+this.width+this.height+' alt="" />';
			_str += (matches[1]) ? '</a>' : '';
			imgObj.innerHTML= _str;
		}

		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.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);
	}
};

/*Usage this script
<div id="adv1"><img border="0" src="{SITE_URL}/upload/adv/logo/logo_vtn.gif"></div>
	<script src="{SITE_URL}/javascript/rotation.js"></script>
	<script type="text/javascript">

	function bannerRotation()
	{
		var rt = new rotator('adv1', 5000, "/upload/adv/banner/", 484, 70);
		rt.setItems("vpbank.gif|http://www.vpbs.com.vn|_blank","cttruyenthong.swf");
		rotator.start();  
	}
	onload = bannerRotation;
	</script>
*/