	
	/*
	
	
		• oDiv(id,name,x,y,w,h,mW,mH,bPix,pCol,bgCol,origin,a,action,step)
		• updateColour(cCol, tCol)
		• redefine(name,x,y,w,h,origin)
		
	*/


	function oDiv(id,name,x,y,w,h,mW,mH,bPix,pCol,bgCol,origin,a,action,step) {
		this.id = id;
		this.name = name;
		this.d = false;				// Display
		this.x = x;						// X Location
		this.y = y;						// Y Location
		this.tX = x;					// Target X
		this.tY = y;					// Target Y
		this.w = w;						// Width
		this.h = h;						// Height
		this.tW = w;					// Target Width
		this.tH = h;					// Target Height
		this.oW = w;					// Original Width
		this.oH = h;					// Original Height
		this.z = 0;						// zIndex
		this.tZ = 0;					// Target zIndex
		this.mW = mW;					// Margin Width
		this.mH = mH;					// Margin Height
		this.bPix = bPix;			// Border Pixels
		this.tBPix = bPix;		// Target Border Pixels
		this.oBPix = bPix;		// Original Border Pixels
		this.pCol = pCol;			// Pixel Colour
		this.tPCol = pCol;		// Target Pixel Colour
		this.oPCol = pCol;		// Target Pixel Colour
		this.bgCol = bgCol; 	// Background Colour
		this.tBgCol = bgCol;	// Target Background Colour
		this.oBgCol = bgCol;	// Target Background Colour
		this.o = origin;			// Stretch from
		this.a = a;						// Animate?
		this.loop=false;			// Loop?
		this.step = (step == null)?6:step; 	// Pixel Step
		this.speed = 10;			// Repeat Speed
		this.timer = "";			// Timer for setTimeout()
		this.action = function() {
			eval(action);
		};										// Run an action after loop is finished.
		this.redraw = function() {
			if (this.d)
				document.getElementById(this.id).style.display = "block";
			else
				document.getElementById(this.id).style.display = "none";
			if (this.a == true) {
				this.loop = false;
				if (this.tW > this.w) {
					this.w += this.step;
					if (this.o == 'c')
						this.tX = this.tX - parseInt(this.step/2,10);
					if (this.w > this.tW) this.w = this.tW; else this.loop = true;
				}
				if (this.tW < this.w) {
					this.w -= this.step;
					if (this.o == 'c')
						this.tX = this.tX - parseInt(this.step/2,10);
					if (this.w < this.tW) this.w = this.tW; else this.loop = true;
				}
				document.getElementById(this.id).style.width = this.w+'px';

				if (this.tH > this.h) {
					this.h += this.step;
					if (this.o == 'c')
						this.tY = this.tY - parseInt(this.step/2,10);
					if (this.o == 'lb')
						this.tY = this.tY - parseInt(this.step,10);
					if (this.h > this.tH)
						this.h = this.tH; else this.loop = true;
				}
				if (this.tH < this.h) {
					this.h -= this.step;
					if (this.o == 'c')
						this.tY = this.tY - parseInt(this.step/2,10);
					if (this.o == 'lb')
						this.tY = this.tY - parseInt(this.step,10);
					if (this.h < this.tH) this.h = this.tH; else this.loop = true;
				}
				document.getElementById(this.id).style.height = this.h+'px';

				if (this.tX > this.x) {
					this.x += this.step;
					if (this.x > this.tX) this.x = this.tX; else this.loop = true;
				}
				if (this.tX < this.x) {
					this.x -= this.step;
					if (this.x < this.tX) this.x = this.tX; else this.loop = true;
				}
				document.getElementById(this.id).style.left = this.x+'px';

				if (this.tY > this.y) {
					this.y += this.step;
					if (this.y > this.tY) this.y = this.tY; else this.loop = true;
				}
				if (this.tY < this.y) {
					this.y -= this.step;
					if (this.y < this.tY) this.y = this.tY; else this.loop = true;
				}
				document.getElementById(this.id).style.top = this.y+'px';
				if (this.name == "oM") {
				}

				if (this.tZ != this.z)
					this.z = this.tZ;
				if (this.tZ > this.z) {
					this.z++;
					if (this.z > this.tZ) this.z = this.tZ; else this.loop = true;
				}
				if (this.tZ < this.z) {
					this.z--;
					if (this.z < this.tZ) this.z = this.tZ; else this.loop = true;
				}
				document.getElementById(this.id).style.zIndex = this.z;

				if (this.bPix != this.tBPix){
					oldPix = document.getElementById(this.id).style.border;
					newPix = (this.bPix < this.tBPix)?this.bPix+1:this.bPix-1;
					document.getElementById(this.id).style.border = oldPix.replace(this.bPix+"px",newPix+"px");
					this.bPix = (this.bPix < this.tBPix)?this.bPix+1:this.bPix-1;
					if (this.bPix != this.tBPix)
						this.loop = true;
						
				}
				if (this.bgCol != this.tBgCol) {
					this.bgCol = updateColour(this.bgCol, this.tBgCol, 2);
					document.getElementById(this.id).style.backgroundColor = "#"+this.bgCol;
					if (this.bgCol != this.tBgCol)
						this.loop = true;
				}
				if (this.pCol != this.tPCol) {
					oldBorder = document.getElementById(this.id).style.border;
					oldPC = this.pCol;
					this.pCol = updateColour(this.pCol, this.tPCol, 2);
					document.getElementById(this.id).style.border = "solid "+this.bPix+"px #"+this.pCol;
					if (this.pCol != this.tPCol)
						this.loop = true;
				}

				if (this.loop) {
					this.timer = setTimeout(this.name+'.redraw();',this.speed);
				} else {
					this.action();
				}
			} else {
				this.x = this.tX;
				this.y = this.tY;
				this.w = this.tW;
				this.h = this.tH;
				document.getElementById(this.id).style.width = this.w+'px';
				document.getElementById(this.id).style.height = this.h+'px';
				document.getElementById(this.id).style.left = this.x+'px';
				document.getElementById(this.id).style.top = this.y+'px';
			}
		},
		this.reset = function() {
			this.tW = this.oW;
			this.tH = this.oH;
			this.tBPix = this.oBPix;
		}
	}

	function updateColour(cCol, tCol, locSpeed) {
		aCol=[
			 parseInt(cCol.substring(0,2),16),parseInt(tCol.substring(0,2),16)
			,parseInt(cCol.substring(2,4),16),parseInt(tCol.substring(2,4),16)
			,parseInt(cCol.substring(4,6),16),parseInt(tCol.substring(4,6),16)
		];
		for (i=0; i<aCol.length; i+=2) { 
			if (aCol[i+1] > aCol[i]) {
				aCol[i] = aCol[i] + locSpeed;
				if (aCol[i+1] < aCol[i] || aCol[i] > 255) aCol[i] = aCol[i+1];
			}
			if (aCol[i+1] < aCol[i]) {
				aCol[i] = aCol[i] - locSpeed;
				if (aCol[i+1] > aCol[i] || aCol[i] < 0) aCol[i] = aCol[i+1];
			}
			aCol[i] = parseInt(aCol[i],10).toString(16);
			aCol[i] = aCol[i].toUpperCase();
			if (aCol[i].length == 1) aCol[i] = "0"+aCol[i];
		}
		return aCol[0]+aCol[2]+aCol[4]
	}
	
	function redefine(name,x,y,w,h,origin,z,d) {
		obj = eval(name);
		if (x != null) obj.tX = x;
		if (y != null) obj.tY = y;
		if (w != null) obj.tW = w;
		if (h != null) obj.tH = h;
		if (origin != null) obj.o = origin;
		if (z != null)
			if (z == 'top') obj.tZ = ++navSet.z;
		if (d != null) obj.d = d;
		obj.redraw();
		obj.a = true;
	}
	
	