function FlatPane(
		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;
	ix *= this.pw;
	iy *= this.ph;

	if (iw+ih==0) {
		alert("At least one Width or Height must be specified to create a Pane");
	} else if (iw>0) {
		iw *= this.pw;
		ih = (iw/this.img.width) * this.img.height;
	} else if (ih>0) {
		ih *= this.ph;
		iw = (ih/this.img.height) * this.img.width;
	}
	
	this.orientation = -1;
	this.zoom =		Math.sqrt((iw*iw)+(ih*ih));
	this.ix =		ix;
	this.iy = 		iy;
	this.iz = 		this.zoom;
	this.iw = 		iw;
	this.ih =		ih;
	this.icx=		Math.floor(iw / 2);
	this.icy=		Math.floor(ih / 2);
	this.xpiv =		-1;
	this.xrot = 	0;
	this.ypiv =		-1;
	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.sFactor =	1.00; // automatic parameter scaling factor
	this.click = 	null;
}
function flatpane_getClass() { return "FlatPane"; }
function flatpane_setup() {
	this.clampSize(vpw-200,vph-200);
	
	this.numslices = 1;
	this.half = 0.5;

	var i = 0;
	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 = "-1000px";
	this.dive[i].style.top = "-1000px";
	this.dive[i].style.width = this.iw+"px";
	this.dive[i].style.height = this.ih+"px";
	this.dive[i].style.overflow = "hidden";
	this.dive[i].style.backgroundColor = "transparent";
	this.dive[i].style.zIndex = "240";
	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 = "0px";
	this.imge[i].style.top = "0px";
	this.imge[i].style.height = "100%";
	this.imge[i].style.width = "100%";
	this.imge[i].style.backgroundColor = "transparent";

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

function flatpane_run3d() {
	if (!this.prepared) this.setup();
	var i = 0;
	this.dive[i].style.left = ""+((this.pw*this.ix)-this.icx)+"px";
	this.dive[i].style.top= ""+((this.ph*this.iy)-this.icy)+"px";
	this.dive[i].style.width = ""+Math.floor(this.iw * this.sFactor)+"px";
	this.dive[i].style.height = ""+Math.floor(this.ih * this.sFactor)+"px";
	setOpacity(this.dive[i],this.opacity*100);
	if (this.click) {
		this.dive[i].addEventListener('click', this.click, false)
		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.sFactor;
					this.iy = this.queue[i].getY() * this.sFactor;
					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.queue[i].finish(); finished = true; // Not Supported
				} else if (this.queue[i].getType()=="ElevatedMoveTask") {
					this.queue[i].finish(); finished = true; // Not Supported
				} else if (this.queue[i].getType()=="BounceTask") {
					this.queue[i].finish(); finished = true; // Not Supported
				} else if (this.queue[i].getType()=="DropTask") {
					this.queue[i].finish(); finished = true; // Not Supported
				} else if (this.queue[i].getType()=="YSpinTask") {
					this.queue[i].finish(); finished = true; // Not Supported
				} else if (this.queue[i].getType()=="XSpinTask") {
					this.queue[i].finish(); finished = true; // Not Supported
				} else if (this.queue[i].getType()=="XSpinReplaceTask") {
					this.queue[i].finish(); finished = true; // Not Supported
				} else if (this.queue[i].getType()=="YSpinReplaceTask") {
					this.queue[i].finish(); finished = true; // Not Supported
				} 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 flatpane_offX(e) {
	var x = 0;
	while (e!=null) {
		x = x + e.offsetLeft;
		e = e.offsetParent;
	}
	return x;
}
function flatpane_offY(e) {
	var y = 0;
	while (e!=null) {
		y = y + e.offsetTop;
		e = e.offsetParent;
	}
	return y;
}
function flatpane_getScreenX(x,y,z) {
	return ( (x / z) * this.zoom);
}
function flatpane_getScreenY(x,y,z) {
	return ( (y / z) * this.zoom);
}
function flatpane_getScreenWidth(z) {
	return this.iw
}
function flatpane_getScreenHeight(z) {
	return this.ih
}
function flatpane_setStrip(i,basex,basey,x,y,z) {} // not supported
function flatpane_isStable() {
	return this.stable;
}
function flatpane_addTask(task) {
	if ((this.queue==null) || (this.queue[0]==null)) {
		this.queue[0] = task;
	} else {
		this.queue[this.queue.length] = task;
	}
}
function flatpane_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 flatpane_getUID() {return this.uid; }
function flatpane_getBaseZ() {return this.zoom; }
function flatpane_getCurrentX() { return this.ix; }
function flatpane_getCurrentY() { return this.iy; }
function flatpane_getCurrentZ() { return this.iz; }
function flatpane_getCurrentOrientation() { return this.orientation; }
function flatpane_getOpacity() { return this.opacity; }
function flatpane_setOpacity(o) { this.opacity = o; }
function flatpane_centerPivot() { this.xpiv = 0; this.ypiv = 0; }
function flatpane_leftPivot() { this.ypiv = 1; }
function flatpane_rightPivot() { this.ypiv = 2; }
function flatpane_topPivot() { this.xpiv = 1; }
function flatpane_bottomPivot() { this.xpiv = 2; }
function flatpane_orient(o) {} // not supported
function flatpane_rolloverX( src ) {} // not supported
function flatpane_onClick( f ) { this.click = f; }
function flatpane_getQueueLength() {
	return this.queue.length;
}
function flatpane_clampSize(mw,mh) {
	this.sFactor = 1.0;
	
	if (this.iw > mw) {
		this.sFactor = mw/this.iw;
	} else if (this.ih > mh) {
		this.sFactor = mh/this.ih;
	}
	if (this.sFactor != 1.0) {
		this.iw *= this.sFactor;
		this.ih *= this.sFactor;
		this.ix *= this.sFactor;
		this.iy *= this.sFactor;
		this.icx*= this.sFactor;
		this.icy*= this.sFactor;
	}
	return this.sFactor;
}
function flatpane_getScalingFactor() {
	return this.sFactor;
}

FlatPane.prototype.setup = flatpane_setup;
FlatPane.prototype.getClass = flatpane_getClass;
FlatPane.prototype.run = flatpane_run3d;
FlatPane.prototype.offX = flatpane_offX
FlatPane.prototype.offY = flatpane_offY
FlatPane.prototype.getScreenX = flatpane_getScreenX;
FlatPane.prototype.getScreenY = flatpane_getScreenY;
FlatPane.prototype.getScreenWidth = flatpane_getScreenWidth;
FlatPane.prototype.getScreenHeight = flatpane_getScreenHeight;
FlatPane.prototype.setStrip = flatpane_setStrip;
FlatPane.prototype.isStable =pane_isStable;
FlatPane.prototype.addTask = flatpane_addTask;
FlatPane.prototype.runQueue = flatpane_runQueue;
FlatPane.prototype.getUID = flatpane_getUID;
FlatPane.prototype.getBaseZ = flatpane_getBaseZ;
FlatPane.prototype.getCurrentX = flatpane_getCurrentX;
FlatPane.prototype.getCurrentY = flatpane_getCurrentY;
FlatPane.prototype.getCurrentZ = flatpane_getCurrentZ;
FlatPane.prototype.x = flatpane_getCurrentX;
FlatPane.prototype.y = flatpane_getCurrentY;
FlatPane.prototype.z = flatpane_getCurrentZ;FlatPane.prototype.getCurrentOrientation = flatpane_getCurrentOrientation;
FlatPane.prototype.centerPivot = flatpane_centerPivot;
FlatPane.prototype.leftPivot = flatpane_leftPivot;
FlatPane.prototype.rightPivot = flatpane_rightPivot;
FlatPane.prototype.topPivot = flatpane_topPivot;
FlatPane.prototype.bottomPivot = flatpane_bottomPivot;
FlatPane.prototype.orient = flatpane_orient;
FlatPane.prototype.rolloverX = flatpane_rolloverX;
FlatPane.prototype.getQueueLength = flatpane_getQueueLength;
FlatPane.prototype.clampSize= flatpane_clampSize;
FlatPane.prototype.getScalingFactor = flatpane_getScalingFactor;
FlatPane.prototype.s = flatpane_getScalingFactor;
FlatPane.prototype.getOpacity = flatpane_getOpacity;
FlatPane.prototype.onClick = flatpane_onClick;
