<!--

function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 } 



swapmode = new Object;
swapmode.content = 1;
swapmode.bg = 2;
swapmode.vis = 3;
swapmode.opacity = 4;
swapmode.imgsrc = 5;

swapdefaults = new Object;
swapdefaults.o = 85;
swapdefaults.timing = 8;


function SwapEntry(s,i,m,p,t) {
	/*
		target is a valid id for document.GetElementById(target);
		mode is an integer valid in the following list:
			mode:1 = content replacement, i.e. document.getElementById(target).innerHTML = document.getElementById(param1).innerHTML
			mode:2 = background replacement, i.e. document.getElementById(target).style.backgroundImage = "url(" + param1 + ")"
			mode:3 = make visible / unswap makes invisible again
			etc... (see above)
		param is dependent on mode
	*/
	//i = new Object;
	this.set = s;
	this.idx = i;
	this.mode = m;
	this.param = p;
	this.target = t;
}
SwapEntry.prototype.resolveTarget = function() {
	if (this.target) return this.target;
	if (this.set.targets[this.idx]) return this.set.targets[this.idx];
	if (this.set.mgr.targets[this.idx]) return this.set.mgr.targets[this.idx];
	return "";
}
SwapEntry.prototype.resolveMode = function() {
	if (this.mode) return this.mode;
	if (this.set.modes[this.idx]) return this.set.modes[this.idx];
	if (this.set.mgr.modes[this.idx]) return this.set.mgr.modes[this.idx];
	return "";
}
SwapEntry.prototype.unswap = function() {
	var t = this.resolveTarget();
	var m = this.resolveMode();
	switch (m) {
		case swapmode.vis:
			t = document.getElementById(t);
			t.style.visibility = "hidden";
		default:
			break;
	}
}
SwapEntry.prototype.doswap = function() {
	var t = this.resolveTarget();
	var m = this.resolveMode();
	switch (m) {
		case swapmode.content:
			t = document.getElementById(t);
			var s = document.getElementById(this.param);
			if ((t) && (s)) t.innerHTML = s.innerHTML;
			break;
		case swapmode.bg:
			t = document.getElementById(t);
			bg = "url(" + this.param + ")";
			if (t) t.style.backgroundImage = bg;
			break;
		case swapmode.vis:
			t = document.getElementById(t);
			t.style.visibility = "visible";
			break;
		case swapmode.opacity:
			t = document.getElementById(t);
			if (t) t.style.opacity = this.param / 100;
			if (t) t.style.filter = "alpha(opacity=" + this.param + ");";
			break;
		case swapmode.imgsrc:
			t = document.getElementById(t);
			if (t) t.src = this.param;
			break;
		default:
			break;
	}
}


function SwapSet(m) {
	this.targets = new Array();
	this.modes = new Array();
	this.mgr = m;
	this.swaps = new Array();
}
SwapSet.prototype.AddTarget = function(name,mode) {
	this.targets.push(name);
	this.modes.push(mode);
}
SwapSet.prototype.swap = function() {
	if (this.mgr.current) this.mgr.current.unswap();
	this.mgr.current = this;
	for (var i = 0; i < this.swaps.length; i++) {
		this.swaps[i].doswap();
	}
}
SwapSet.prototype.unswap = function() {
	for (var i = 0; i < this.swaps.length; i++) {
		this.swaps[i].unswap();
	}
}
SwapSet.prototype.AddSwapEntry = function(param,target,mode) {
	var j = new SwapEntry(this,this.swaps.length,mode,param,target);
	this.swaps.push(j);
}


function SwapManager() {
	this.swaps = new Array();
	this.targets = new Array();
	this.modes = new Array();
	this.timing = swapdefaults.timing;
	this.idx = 999;
	this.countdown = 0;
	this.rotategvarname = "";
	this.current = 0;
}
SwapManager.prototype.AddTarget = function(name,mode) {
	this.targets.push(name);
	this.modes.push(mode);
}
SwapManager.prototype.AddSwapSet = function() {
	var j = new SwapSet(this);
	this.swaps.push(j);
	return j;
}
SwapManager.prototype.AddNamedSwapSet = function(name) {
	var j = new SwapSet(this);
	this.swaps[name] = j;
	return j;
}
SwapManager.prototype.Display = function(i) {
	var j = this.swaps[i];
	if (j) {
		j.swap();
		this.idx = i;
	}
	return false;
}
SwapManager.prototype.Next = function() {
	this.idx++;
	if (this.idx >= this.swaps.length) this.idx = 0;
	this.Display(this.idx);
	return false;
}

SwapManager.prototype.Previous = function() {
	this.idx--;
	if (this.idx < 0) this.idx = this.swaps.length-1;
	this.Display(this.idx);
	return false;
}

SwapManager.prototype.rotate = function() {
    this.idx++;  if (this.idx >= this.swaps.length) this.idx = 0;
	this.Display(this.idx);
}
SwapManager.prototype.timedRotate = function() {
	
	if (this.timing == 999) return;
	if (this.countdown<=0) {
		this.rotate();
		this.countdown = this.timing;
	}
	else
	{
		this.countdown--;
	}
	setTimeout(this.rotategvarname + ".timedRotate()",1000);
}
SwapManager.prototype.doTimedRotate = function(gv) {
	this.rotategvarname = gv;
	this.timedRotate();
}
SwapManager.prototype.StopTimedRotate = function() {
	this.timing = 999;
}



// -->
