// $Date: 2006/06/19 12:06:32 $
// $Name: ukrestart_v1_r5 $
// $Revision: 1.11 $
// $State: Exp $

/* ROTATOR CLASS - Version 3.1 */

function rotator(i,rI,u,n,rC,rP) {
	this.i = i;
	this.rI = rI;
	this.u = u;
	this.n = n;
	this.rC = rC;
	this.rP = rP;
	this.s = "initialising";
	this.c = 0;
	this.dC = 0;
	this.dI;
	this.dR;
	this.rflag = false;
		
	this.init = function(r) {
		this.oX = -999;
		this.oY = -999;
		this.f = Array();
		this.x = 0;
		this.y = 0;
		try {
		this.C = document.getElementById(this.rC);
		this.P = document.getElementById(this.rP);
		if(this.P.offsetParent) {
			var t = this.P;
			while(t.offsetParent) {
				this.x+=t.offsetLeft;this.y+=t.offsetTop;t=t.offsetParent;
			}
		}
		
		var tC = this.C.childNodes;
		for(var i=0;i<=tC.length-1;i++) {
			if(tC[i].nodeType==1) {
				if(tC[i].getAttribute("id").indexOf("r")==0) {
					this.f[this.f.length] = tC[i];
				}
			}
		}
		if(!this.rflag) {
			var tmp = this.f[0].innerHTML;	
			this.c = 0;
		} else {
			var tmp = this.f[this.c].innerHTML;
		}
		
		if(tmp!="") {
			this.P.innerHTML = "<div id='slide"+(this.c+1)+"'>"+tmp+"</div>";
		this.buildTools();
		}	
		this.rflag = false;
		} catch(e) { }
	};
	
	this.move = function(f) {
		try {
		if(!f) {
			this.c++;
			(this.c==this.f.length)?this.c=0:this.c;
		} else if(this.mode=="back") {
			this.c--;
			(this.c<0)?this.c = this.f.length-1:this.c;
		} else if(this.mode=="jump") {
			this.c = f-1;
		}
		if(this.f[this.c].innerHTML!="") {
			this.P.innerHTML = "<div id='slide"+(this.c+1)+"'>"+this.f[this.c].innerHTML+"</div>";
			this.buildTools();
		}
		} catch(e) {}
	};
	
	this.action = function(action,x) {
		clearTimeout(this.dI);
		if(!action) { action = this.mode; }
		if(this.rflag&&action!="refresh") { this.init(true); }
		switch(action) {
			case "pause":
				this.mode = "pause";
				break;
			case "play":
				this.mode = "play";
				this.move();
				this.rotate();
				break;
			case "back":
				this.mode = "back";
				this.move(true);
				break;			
			case "next":this.mode = "next";
				this.move();
				this.mode = "play";
				this.rotate();break;
			case "jump":
				this.mode= "jump";
				this.move(x);
				break;
			case "refresh":
				this.refresh();
				break;
		}
		return false;
	};
	
	this.rotate = function() {
		//this is the part I added
		if(this.f[this.c].getAttribute("promo")==0)
			this.dI = setTimeout(this.n+".action()",this.i);			
	};
	
	this.refresh = function () {
		try {
		clearTimeout(this.dI);
		if(!this.rflag) {
			this.rflag = true;
		}
		var hash = new Date().getTime();
		this.f[this.c].style.top = this.oY+"px";
		this.f[this.c].style.left = this.oX+"px";
		var req = new genericAjax(this.u+"&hash="+hash,"GET","TEXT",rotatorUpdateDisplay);
		this.dR = setTimeout(this.n+".action('refresh')",this.rI);
		} catch(e) {} 
	};
	
	this.asppImpression = function() {
	}
	
	this.buildTools = function() {
		var s = "<div class=\"rotator_nav\"><table class=\"defaulthead\" align=center width=100%> <tr><td><span id=\"rTL\"><a href=\"#\" onclick=\"return "+this.n+".action('back');\"><img border=\"0\" src=\"http://img.anxa.com/part/msn/previous.gif\"></td></a></span><td valign=\"middle\" align=center> <span id=\"rTT\">";
		for(var i=1;i<=this.f.length;i++) {
			if(i==(this.c+1)) { s += "<big class=current>" + i+"</big> "; } else { s += "<a href=\"#\" onclick=\"return "+this.n+".action('jump',"+i+");\">"+i+"</a> "; }
		}
		s += "</span></td><td align=right><span id=\"rTR\"><a href=\"#\" onclick=\"return " + this.n + ".action('next');\"> <img border=\"0\" src=\"http://img.anxa.com/part/msn/next.gif\"></a></span></td></tr></table></div>";
		try {
		document.getElementById("rT").innerHTML = s;	
		} catch(e) {}
	}

	this.init();this.mode="play";this.rotate();
	this.dR = setTimeout(this.n+".action('refresh')",this.rI);
}

