function Pane(
		url,		// image source url
		ix,			// central x coord
		iy,			// central y coord
		iw,			// image width at 100% zoom
		ih			// image height at 100% zoom
	) {
	
	if ((ua=="ie")||(ua=="ie7")||(ua=="ie8")) url = url.substring(0,url.lastIndexOf("."))+".gif";
	this.url =		url;
	this.img = 		new Image();
	this.img.src =	this.url;

	this.pw = vpw/100;
	this.ph = vph/100;
	this.ix = ix * this.pw;
	this.iy = iy * this.ph;
	this.iw = iw;
	this.ih = ih;

	if (this.iw+this.ih==0) {
		alert("At least one Width or Height must be specified to create a Pane");
	} else if (ih==0) {
		this.iw *= this.pw;
		this.ih = (this.iw/this.img.width) * this.img.height;
	} else if (iw==0) {
		this.ih *= this.ph;
		this.iw = (this.ih/this.img.height) * this.img.width;
	}

	this.orientation = 0;	// 0 = slices spread along X axis. 1 = slices spread along Y axis. -1 = no slices at all
	this.zoom =		Math.sqrt((iw*iw)+(ih*ih));
	this.iz = 		this.zoom;
	this.icx=		Math.floor(this.iw / 2);
	this.icy=		Math.floor(this.ih / 2);
	this.xpiv =		0;		// 0 = center pivot, 1 = top edge pivot, 2 = bottom edge pivot
	this.xrot = 	0;
	this.ypiv =		0;		// 0 = center pivot, 1 = left edge pivot, 2 = right edge pivot
	this.yrot = 	0;
	this.ebod =		document.getElementById("core");
	this.dive =		[null];
	this.imge =		[null];
	this.queue = 	[null];
	this.stable =	false;
	this.zfactor =	2;
	this.uid = 		Math.floor(Math.random()*10000000);
	this.reverse =	false;
	this.prepared = false;
	this.opacity =	1.0;
	this.click = 	null;
}
function pane_getClass() { return "Pane"; }
function pane_setup() {
	var division = 10;
	
	this.numslices = Math.floor(this.iw/division);
	while ((this.numslices*division!=this.iw) && (division!=1)) {
		division-=1;
		this.numslices =Math.floor(this.iw/division);
	}
	this.half = Math.floor(this.numslices/2);

	var i = -1;
	while (++i < this.numslices) {
		this.dive[i] = document.createElement("div");
		this.dive[i].id = "dive"+this.uid+"_"+i;
		this.dive[i].style.position = "absolute";
		this.dive[i].style.left = ""+Math.floor(-9999+((160/this.numslices)*i))+"px";
		this.dive[i].style.top = "64px";
		this.dive[i].style.width = "2px"
		this.dive[i].style.height = "120px";
		this.dive[i].style.overflow = "hidden";
		this.dive[i].style.backgroundColor = "transparent";
		this.dive[i].className = "pane";

		this.imge[i] = document.createElement("img");
		this.imge[i].src = this.img.src;
		this.imge[i].style.position = "relative";
		this.imge[i].style.left = ""+(-(160/this.numslices)*i)+"px";
		this.imge[i].style.top = "0px";
		this.imge[i].style.height = "100%";
		this.imge[i].style.backgroundColor = "transparent";

		this.dive[i].appendChild( this.imge[i] );
		this.ebod.appendChild( this.dive[i] );
	}
	this.prepared = true;
}

function pane_run3d() {
	if (!this.prepared) this.setup();
	
	var i = -1;
	while (++i < this.numslices) {
		var x=0;
		var y=0;
		var z=0;
		if (this.orientation==0) {
			if (this.ypiv==0) {
				x = (	(i-this.half)
					*	(this.iw/this.numslices)
					/	this.pw
					*	Math.cos(this.yrot));
				y = 	-this.icy/this.ph;
				z = 	this.iz
					+ 	(	(i-this.half)
						*	(this.iw/this.numslices)
						*	Math.sin(this.yrot)
						/	this.zfactor
						/	this.pw
						);
			} else if (this.ypiv==1) {
				x = (	-this.half
					*	(this.iw/this.numslices)
						)
					/	this.pw
					+ (	Math.cos(this.yrot)
					* 	(i*this.iw/this.numslices)
						);
				y = 	-this.icy/this.ph;
				z = 	this.iz
					+ 	(	i
						*	this.iw
						/	this.numslices
						*	Math.sin(this.yrot)
						/	this.zfactor
						/	this.pw
						);
			} else if (this.ypiv==2) {
				x = (	this.half
					/	this.pw
					*	(this.iw/this.numslices)
						)
					- 	(Math.cos(this.yrot) * ((this.numslices-i)*this.iw/this.numslices));
				y = 	-this.icy/this.ph;
				z = 	this.iz
					+ 	(	(this.numslices-i)
						*	this.iw
						/	this.numslices
						*	Math.sin(this.yrot)
						/	this.zfactor
						/	this.pw
						);
			}
			if (this.yrot!=0) {
				if (Math.cos(this.yrot)<0) {
					this.reverse = true;
				} else {
					this.reverse = false;
				}
			} else {
				this.reverse = false;
			}
		} else if (this.orientation==1) {
			if (this.xpiv==0) {
				x = 	-this.icx/this.pw;
				y = (	(i-this.half)
					/	this.ph
					*	(this.ih/this.numslices)
					*	Math.cos(this.xrot));
				z = 	this.iz
					+ 	(	(i-this.half)
						*	(this.ih/this.numslices)
						*	Math.sin(this.xrot)
						/	this.zfactor
						/	this.ph
						);
			} else if (this.xpiv==1) {
				x = 	-this.icx/this.pw;
				y = (	-this.half
					/	this.ph
					*	(this.ih/this.numslices)
						)
					+ (	Math.cos(this.xrot)
					* 	(i*this.ih/this.numslices)
						);
				z = 	this.iz
					+ 	(	i
						*	this.ih
						/	this.numslices
						*	Math.sin(this.xrot)
						/	this.zfactor
						/	this.ph
						);
			} else if (this.xpiv==2) {
				x = 	-this.icx/this.pw;
				y = (	this.half
					/	this.ph
					*	(this.ih/this.numslices)
						)
					- 	(Math.cos(this.xrot) * ((this.numslices-i)*this.ih/this.numslices));
				z = 	this.iz
					+ 	(	(this.numslices-i)
						*	this.ih
						/	this.numslices
						*	Math.sin(this.xrot)
						/	this.zfactor
						/	this.ph
						);
			}
		}
		this.setStrip(i,this.ix*this.pw,this.iy*this.ph, x, y, z );

		if (this.click) {
			if (this.dive[i].addEventListener) {
				this.dive[i].addEventListener('click', this.click, false)
			} else if (this.dive[i].attachEvent) {
				this.dive[i].attachEvent('onclick', this.click)
			} else {
				this.dive[i].onClick = this.click;
			}
			this.dive[i].style.cursor = "pointer";
		}
	}
	this.click = null;
	
	if ((this.queue!=null) && (this.queue[0]!=null)) {
		var finished = false;
		var i = -1;
		while (++i < this.queue.length) {
			if (this.queue[i] != null) {
				if (this.queue[i].getType()=="DelayTask") {
					if (i==0) {
						this.queue[i].finish();
					} else {
						i = this.queue.length;
					}
				} else if (this.queue[i].getType()=="WaitTask") {
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
					i = this.queue.length;
				} else if (this.queue[i].getType()=="XOrientationTask") {
					this.orientation = 1;
					this.queue[i].finish();
				} else if (this.queue[i].getType()=="YOrientationTask") {
					this.orientation = 0;
					this.queue[i].finish();
				} else if (this.queue[i].getType()=="MoveTask") {
					this.ix = this.queue[i].getX();
					this.iy = this.queue[i].getY();
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="FadeTask") {
					this.opacity = this.queue[i].getO();
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="HideTask") {
					this.opacity = 0;
					this.queue[i].finish();
					finished = true;
				} else if (this.queue[i].getType()=="JumpTask") {
					this.ix = this.queue[i].getX();
					this.iy = this.queue[i].getY();
					this.queue[i].finish();
					finished = true;
				} else if (this.queue[i].getType()=="LiftTask") {
					this.iz = this.queue[i].getZ();
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="ElevatedMoveTask") {
					this.ix = this.queue[i].getX();
					this.iy = this.queue[i].getY();
					this.iz = this.queue[i].getZ();
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="BounceTask") {
					this.iz = this.queue[i].getZ();
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="DropTask") {
					this.iz = this.queue[i].getZ();
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="YSpinTask") {
					this.yrot = this.queue[i].getRot();
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="XSpinTask") {
					this.xrot = this.queue[i].getRot();
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="XSpinReplaceTask") {
					this.xrot = this.queue[i].getRot();
					var newimg = this.queue[i].getImage();
					if (newimg!=null) {
						var j = -1; while (++j < this.imge.length) { this.imge[j].src = newimg.src; }
					}
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else if (this.queue[i].getType()=="YSpinReplaceTask") {
					this.yrot = this.queue[i].getRot();
					var newimg = this.queue[i].getImage();
					if (newimg!=null) {
						var j = -1; while (++j < this.imge.length) { this.imge[j].src = newimg.src; }
					}
					this.queue[i].advance();
					if (this.queue[i].isFinished()) finished = true;
				} else {
					this.queue[i].finish();
					finished = true;
				}
			}
		}
		if (finished) {
			i = -1;
			var n = 0;
			var q2 = [null];
			while (++i < this.queue.length) {
				if (!this.queue[i].isFinished()) q2[n++] = this.queue[i];
			}
			this.queue = q2;
		}
	} else {
		this.stable = true;
	}
}
function pane_offX(e) {
	var x = 0;
	while (e!=null) {
		x = x + e.offsetLeft;
		e = e.offsetParent;
	}
	return x;
}
function pane_offY(e) {
	var y = 0;
	while (e!=null) {
		y = y + e.offsetTop;
		e = e.offsetParent;
	}
	return y;
}
function pane_getScreenX(x,y,z) {
	return ( (x / z) * this.zoom) * this.pw;
}
function pane_getScreenY(x,y,z) {
	return ( (y / z) * this.zoom) * this.ph;
}
function pane_getScreenWidth(z) {
	if (typeof(z)=="undefined") z=1;
	if (this.orientation==0) {
		return ( ((this.iw/this.numslices) / z) * this.zoom);
	} else if (this.orientation==1) {
		return ( (this.iw/z) * this.zoom);
	} else {
		return iw;
	}
}
function pane_getScreenHeight(z) {
	if (typeof(z)=="undefined") z=1;
	if (this.orientation==0) {
		return ( (this.ih/z) * this.zoom);
	} else if (this.orientation==1) {
		return ( ((this.ih/this.numslices) / z) * this.zoom);
	} else {
		return this.ih;
	}
}
function pane_setStrip(i,basex,basey,x,y,z) {
	var e = this.dive[i];
	var sx = basex+this.getScreenX(x,y,z);
	var sy = basey+this.getScreenY(x,y,z);
	var sw = this.getScreenWidth( z );
	var sh = this.getScreenHeight( z );
	if (this.reverse) sx-=sw;
	e.style.top		= ""+sy+"px";
	e.style.left	= ""+sx+"px";
	e.style.width	= ""+sw+"px";
	e.style.height	= ""+sh+"px";
	e.style.zIndex	= ""+Math.floor( 50000-z );
	setOpacity(e,this.opacity*100);
	if (this.orientation==0) {
		e = this.imge[i];
		var io = -(i * sw);
		e.style.top = "0px";
		e.style.height = "100%";
		e.style.left = ""+io+"px";
		e.style.width = ""+(sw*this.numslices)+"px";
	} else {
		e = this.imge[i];
		var io = -(i * sh);
		e.style.left = "0px";
		e.style.width = "100%";
		e.style.top = ""+io+"px";
		e.style.height = ""+(sh*this.numslices)+"px";
	}
}
function pane_isStable() {
	return this.stable;
}
function pane_addTask(task) {
	if ((this.queue==null) || (this.queue[0]==null)) {
		this.queue[0] = task;
	} else {
		this.queue[this.queue.length] = task;
	}
}
function pane_runQueue() {
	if ((this.queue==null) || (this.queue[0]==null)) return;
	if (!this.prepared) this.setup();
	var i = -1;
	while (++i < this.queue.length) {
		this.queue[i].start();
	}
	this.stable = false;
}
function pane_getUID() {return this.uid; }
function pane_getBaseZ() {return this.zoom; }
function pane_getCurrentX() { return this.ix; }
function pane_getCurrentY() { return this.iy; }
function pane_getCurrentZ() { return this.iz; }
function pane_getCurrentOrientation() { return this.orientation; }
function pane_getOpacity() { return this.opacity; }
function pane_setOpacity(o) { this.opacity = o; }
function pane_centerPivot() { this.xpiv = 0; this.ypiv = 0; }
function pane_leftPivot() { this.ypiv = 1; }
function pane_rightPivot() { this.ypiv = 2; }
function pane_topPivot() { this.xpiv = 1; }
function pane_bottomPivot() { this.xpiv = 2; }
function pane_onClick( f ) { this.click = f; }
function pane_orient(o) {
	if (this.orientation==o) return;

	this.orientation = o;
}
function pane_rolloverX( src ) {
	this.orientation = 1;
	this.centerPivot();
	this.addTask( new XSpinReplaceTask(src,0) );
	this.runQueue();
}
function pane_getQueueLength() {
	return this.queue.length;
}

Pane.prototype.setup = pane_setup;
Pane.prototype.getClass = pane_getClass;
Pane.prototype.run = pane_run3d;
Pane.prototype.offX = pane_offX
Pane.prototype.offY = pane_offY
Pane.prototype.getScreenX = pane_getScreenX;
Pane.prototype.getScreenY = pane_getScreenY;
Pane.prototype.getScreenWidth = pane_getScreenWidth;
Pane.prototype.getScreenHeight = pane_getScreenHeight;
Pane.prototype.setStrip = pane_setStrip;
Pane.prototype.isStable =pane_isStable;
Pane.prototype.addTask = pane_addTask;
Pane.prototype.runQueue = pane_runQueue;
Pane.prototype.getUID = pane_getUID;
Pane.prototype.getBaseZ = pane_getBaseZ;
Pane.prototype.getCurrentX = pane_getCurrentX;
Pane.prototype.getCurrentY = pane_getCurrentY;
Pane.prototype.getCurrentZ = pane_getCurrentZ;
Pane.prototype.getOpacity = pane_getOpacity;
Pane.prototype.setOpacity = pane_setOpacity;
Pane.prototype.x = pane_getCurrentX;
Pane.prototype.y = pane_getCurrentY;
Pane.prototype.z = pane_getCurrentZ;
Pane.prototype.getCurrentOrientation = pane_getCurrentOrientation;
Pane.prototype.centerPivot = pane_centerPivot;
Pane.prototype.leftPivot = pane_leftPivot;
Pane.prototype.rightPivot = pane_rightPivot;
Pane.prototype.topPivot = pane_topPivot;
Pane.prototype.bottomPivot = pane_bottomPivot;
Pane.prototype.orient = pane_orient;
Pane.prototype.rolloverX = pane_rolloverX;
Pane.prototype.getQueueLength = pane_getQueueLength;
Pane.prototype.onClick = pane_onClick;
