/*
	Some primitive classes used throughout the portal.
*/
function Coord(x,y){
	this.x = x;
	this.y = y;
}

function Bounds(){
	if ( Bounds.arguments.length == 4) {
		// x, y, w, h
		this.init(Bounds.arguments[0],Bounds.arguments[1],Bounds.arguments[2],Bounds.arguments[3]);
	}
	if ( Bounds.arguments.length == 1) {
		// String xmin, ymin, xmax, ymax
		var data = Bounds.arguments[0].split(",");
		if ( data.length == 4) {
			for ( var i = 0; i < 4; i++){
				data[i] = Number(data[i]);
			}
			this.init(data[0], data[1],  // x, y
					  data[2] - data[0], // w
					  data[3] - data[1]) //h
		}
	}
}

Bounds.prototype.init = function (x,y,width, height){
									this.x = x;
									this.y = y;
									this.width = width;
									this.height = height;
								}

Bounds.prototype.center = function (){
								return new Coord(this.x + this.width/2,
												 this.y + this.height/2);
								}

Bounds.prototype.centerTo = function (aCoord){
								var c = this.center();
								var dx = aCoord.x - c.x;
								var dy = aCoord.y - c.y;
								this.y = this.y + dy;
								this.x = this.x + dx;
								}

Bounds.prototype.asBoundsString = function (){
								var del = ",";
								return ""+this.x+del+this.y+del+(this.x+this.width)+del+(this.y+this.height); 
								}

Bounds.prototype.setImageWidth = function(w) {this.imageWidth = w; }
Bounds.prototype.setImageHeight = function(h) {this.imageHeight = h; }
/*
	Returns Y coord in respect to the upper left corner. This is only done
	if the imageHeight property is set.
*/
Bounds.prototype.getImageY = function(h) {
								if ( this.imageHeight )return (this.imageHeight -this.height - this.y);
								else return this.y;
							}

