/* Rotator B */
function Rotator (name, w, h, d, x, y, c, s, p, obj) {
	this.NAME = name;
	this.WIDTH = w;
	this.HEIGHT= h;
	this.DIRECTION = d;
	this.X = x;
	this.Y = y;
	this.COUNT = c;
	this.SPEED = s;
	this.PAUSE = p;
	this.OBJ_ID = obj;
	
	this.DX = 0;
	this.DY = 0;
	this.TimerID = 0;
	this.STOPonPAUSE = false;
	this.AX = new Array(this.COUNT);
	this.AY = new Array(this.COUNT);
	
	this.on = rotator_on;
	this.off = rotator_off;
	this.rotuj = rotator_rotuj;
	this.setdirection = rotator_setdirection;
	this.stoponpause = rotator_stoponpause;
	this.prev = rotator_prev;
	this.next = rotator_next;
	
	if (this.DIRECTION=="up") { this.DY = -1; }
	if (this.DIRECTION=="down") { this.DY = 1; }
	if (this.DIRECTION=="left") { this.DX = -1; }
	if (this.DIRECTION=="right") { this.DX = 1; }
	
	this.AX1 = this.DX * this.WIDTH;
	this.AY1 = this.DY * this.HEIGHT;
	
	for (var i=0; i < this.COUNT; i++) {
		this.AX[i] = this.DX*i*this.WIDTH*(-1);
		this.AY[i] = this.DY*i*this.HEIGHT*(-1);
	}
	
	if (((w==x)&&(this.DX)) || ((h==y)&&(this.DY))) {
		this.TimerID = setTimeout(this.NAME + ".rotuj()", 1);
	} else {
		this.TimerID = setTimeout(this.NAME + ".rotuj()", this.PAUSE);
	}
}

function rotator_on() {
	this.STOPonPAUSE = false;
	clearTimeout(this.TimerID);
	this.TimerID = setTimeout(this.NAME + ".rotuj()", this.SPEED);
}

function rotator_off() {
	clearTimeout(this.TimerID);
}

function rotator_stoponpause() {
	this.STOPonPAUSE = true;
}

function rotator_setdirection(d) {
	if (this.DIRECTION != d) {
		this.DIRECTION = d;
		this.DX = 0;
		this.DY = 0;
		if (this.DIRECTION=="up") { this.DY = -1; }
		if (this.DIRECTION=="down") { this.DY = 1; }
		if (this.DIRECTION=="left") { this.DX = -1; }
		if (this.DIRECTION=="right") { this.DX = 1; }
		this.AX1 += (this.DX * this.WIDTH * this.COUNT);
		this.AY1 += (this.DY * this.HEIGHT * this.COUNT);
		clearTimeout(this.TimerID);
		this.firstCall = true;
	}
}

function rotator_prev() {
	for (i=0; i < this.COUNT; i++) {
		if (this.DX) {
			this.AX[i] -= (this.DX * this.WIDTH);
			if ( ( (this.AX[i] >= (-this.DX * this.WIDTH * this.COUNT))&&(this.DX < 0) ) || ( (this.AX[i] <= (-this.DX * this.WIDTH * this.COUNT))&&(this.DX > 0) ) ) {
				if (this.AX[i] != this.AX1) this.AX[i] = this.AX1;
				this.AX[i] -= (this.DX * this.WIDTH);
			}
			document.getElementById(this.OBJ_ID + i).style.left = this.AX[i]+"px";
		}
		if (this.DY) {
			this.AY[i] -= (this.DY * this.HEIGHT);
			if ( ( (this.AY[i] >= (-this.DY * this.HEIGHT * this.COUNT))&&(this.DY < 0) ) || ( (this.AY[i] <= (-this.DY * this.HEIGHT * this.COUNT))&&(this.DY > 0) ) ) {
				if (this.AY[i] != this.AY1) this.AY[i] = this.AY1;
				this.AY[i] -= (this.DY * this.HEIGHT);
			}
			document.getElementById(this.OBJ_ID + i).style.top = this.AY[i]+"px";
		}
	}
}

function rotator_next() {
	for (i=0; i < this.COUNT; i++) {
		if (this.DX) {
			this.AX[i] += (this.DX * this.WIDTH);
			if ( ( (this.AX[i] <= this.AX1)&&(this.DX < 0) ) || ( (this.AX[i] >= this.AX1)&&(this.DX > 0) ) ) {
				if (this.AX[i] != this.AX1) this.AX[i] = this.AX1;
				this.AX[i] -= (this.DX * this.WIDTH * this.COUNT);
			}
			document.getElementById(this.OBJ_ID + i).style.left = this.AX[i]+"px";
		}
		if (this.DY) {
			this.AY[i] += (this.DY * this.HEIGHT);
			if ( ( (this.AY[i] <= this.AY1)&&(this.DY < 0) ) || ( (this.AY[i] >= this.AY1)&&(this.DY > 0) ) ) {
				if (this.AY[i] != this.AY1) this.AY[i] = this.AY1;
				this.AY[i] -= (this.DY * this.HEIGHT * this.COUNT);
			}
			document.getElementById(this.OBJ_ID + i).style.top = this.AY[i]+"px";
		}
	}
}

function rotator_rotuj() {
	var next = this.SPEED;
	var paus = false;
	
	for (var i=0; i < this.COUNT; i++) {
		if (this.DX) {
			if ( ( (this.AX[i] <= this.AX1)&&(this.DX < 0) ) || ( (this.AX[i] >= this.AX1)&&(this.DX > 0) ) ) {
				if (this.AX[i] != this.AX1) this.AX[i] = this.AX1;
				this.AX[i] += (this.DX * this.WIDTH * (-1) * this.COUNT); next = this.PAUSE; paus = true;
			}
		}
		if (this.DY) {
			if ( ( (this.AY[i] <= this.AY1)&&(this.DY < 0) ) || ( (this.AY[i] >= this.AY1)&&(this.DY > 0) ) ) {
				if (this.AY[i] != this.AY1) this.AY[i] = this.AY1;
				this.AY[i] += (this.DY * this.HEIGHT * (-1) * this.COUNT); next = this.PAUSE; paus = true;
			}
		}
	}

	if (!paus) {
		for (i=0; i < this.COUNT; i++) {
			if (this.DX) {
				this.AX[i] += (this.DX * this.X);
				document.getElementById(this.OBJ_ID + i).style.left = this.AX[i]+"px";
			}
			if (this.DY) {
				this.AY[i] += (this.DY * this.Y);
				document.getElementById(this.OBJ_ID + i).style.top = this.AY[i]+"px";
			}
		}
	}
	
	this.TimerID = setTimeout(this.NAME + ".rotuj()", next);
	
	if (this.STOPonPAUSE && paus && !this.firstCall) clearTimeout(this.TimerID);
	this.firstCall = false;
}
/* Rotator E */

