// JavaScript Document
// Method keepCenter
// Jukka Kortela
// Visualway Design Oy

DynLayer.prototype.keepCenter=function(widthc,heightc,offsetx,offsety,init) {
	var docwidth,docheight,oldwidth,oldheight;
	if (init) {
		this.centerwidth = DynAPI.document.getWidth();
		this.centerheight = DynAPI.document.getHeight();
		this.center(widthc,heightc,offsetx,offsety);
		DynAPI.addResizeFunction(this+".keepCenter("+widthc+","+heightc+","+offsetx+","+offsety+")");
	} else {
		DynAPI.document.findDimensions();
		docwidth = DynAPI.document.getWidth();
		docheight = DynAPI.document.getHeight();
		if (docwidth!=this.centerwidth || docheight!=this.centerheight) {
			if (is.dom && !is.ie) {
				this.center(widthc,heightc,offsetx,offsety);
			} else if (is.ie) {
				if (is.platform == "mac") {
					location.reload();
				} else {
					this.center(widthc,heightc,offsetx,offsety);
				}	
			} else if (is.ns4) {
				location.reload();
			}
		}
	}
};
DynLayer.prototype.center=function(widthc,heightc,offsetx,offsety) {
	var docwidth,docheight,x_uusi,y_uusi,width_C,height_C,offset_X,offset_Y;
	width_C = widthc || this.getWidth();
	height_C = heightc || this.getHeight();
	offset_X = offsetx || 0;
	offset_Y = offsety || 0;
	DynAPI.document.findDimensions();
	docwidth = DynAPI.document.getWidth();
	docheight = DynAPI.document.getHeight();
	if (docwidth <= width_C)
		x_uusi = 0;
	else {
		x_uusi = (docwidth-width_C)/2;
		if (is.ie) {
			x_uusi = parseInt(x_uusi);
		} else if (is.ns4) {
			x_uusi = Math.round(x_uusi);
		}
	}
	if (docheight <= height_C)
		y_uusi = 0;
	else {
		y_uusi = (docheight-height_C)/2;
		if (is.ie) {
			y_uusi = parseInt(y_uusi);
		} else if (is.ns4) {
			y_uusi = Math.round(y_uusi);
		}
	}
	this.moveTo(x_uusi+offset_X,offset_Y);
};
