function niceLayer( layerID ) {
	this.ID = layerID;
	if( document.layers ) {
		this.layer = document.layers[ this.ID ];
		this.style = this.layer;
	} else if( document.all ) {
		this.layer = document.all[ this.ID ];
		this.style = this.layer.style;
	} else {
		this.layer = document.getElementById( this.ID );
		this.style = document.getElementById( this.ID ).style;
		if( !this.layer ) alert( "Error, layer: " + this.ID );
	}
	
	if( this.layer.document ) {
		this.doc = this.layer.document;
		this.images = this.doc.images;
	} else {
		//alert( this.layer );
	}
	
	this.syncPos = niceSyncPos;
	this.syncAll = niceSyncAll;
	this.move = niceMove;
	this.moveBy = niceMoveBy;
	this.relMove = niceRelMove;
	this.zoom = niceZoom;
	this.show = niceShow;
	this.hide = niceHide;
	this.slideLoop = niceSlideLoop;
	this.slide = niceslide;
	this.slideBy = niceSlideBy;
	this.setBgColor = niceSetBgColor;
	this.write = niceWrite;
	this.load = niceLoad;
	this.loadFinished = niceLoadFinished;
	this.getNested = niceGetNested;
	this.clip = niceClip;
	
	this.relLeft = ( document.layers ) ? parseInt( this.layer.pageX ) : parseInt( this.layer.offsetLeft );
	this.relTop = ( document.layers ) ? parseInt( this.layer.pageY ) : parseInt( this.layer.offsetTop );
	var agent = navigator.userAgent.toLowerCase();
	if( document.all && ( agent.indexOf( "mac" ) > -1 ) ) {
		this.relLeft += parseInt( document.body.leftMargin );
		this.relTop += parseInt( document.body.topMargin );
	}
	
	this.syncAll();
}

function niceSyncPos() {
	this.left = parseInt( this.style.left );
	this.top = parseInt( this.style.top );
	this.zIndex = parseInt( this.style.zIndex );
}

function niceSyncAll() {
	this.syncPos();
	this.width = ( document.layers ) ? this.doc.width : this.layer.scrollWidth;
	this.height = ( document.layers ) ? this.doc.height : this.layer.scrollHeight;
	tempVis = new String( "" + this.style.visibility );
	this.visible = ( tempVis.indexOf( "hid" ) > -1 ) ? false : true;
}

function niceMove( xPos, yPos ) {
	this.style.left = xPos;
	this.style.top = yPos;
	this.syncPos();
}

function niceMoveBy( xDist, yDist ) {
	this.style.left = this.left + xDist;
	this.style.top = this.top + yDist;
	this.syncPos();
}

function niceRelMove( xPos, yPos ) {
	this.style.left = xPos - this.relLeft;
	this.style.top = yPos - this.relTop;
	this.syncPos();
}

function niceZoom( zPos ) {
	this.style.zIndex = zPos;
	this.syncPos();
}

function niceShow() {
	this.style.visibility = "visible";
	this.syncAll();
}

function niceHide() {
	this.style.visibility = "hidden";
	this.syncAll();
}

function niceSlideLoop() {
	xDist = this.leftGoal - this.left;
	yDist = this.topGoal - this.top;
	if( parseInt( Math.abs( xDist / this.xDivider ) ) < 2 ) this.xDivider -= 1;
	if( parseInt( Math.abs( yDist / this.yDivider ) ) < 2 ) this.yDivider -= 1;
	if( Math.abs( xDist ) > 2 ) xDist /= this.xDivider;
	if( Math.abs( yDist ) > 2 ) yDist /= this.yDivider;
	this.moveBy( xDist, yDist );
	if( ( this.left == this.leftGoal ) && ( this.top == this.topGoal ) ) {
		clearInterval( this.ticker );
	}
}

function niceslide( xPos, yPos, tick, divider ) {
	this.leftGoal = parseInt( xPos );
	this.topGoal = parseInt( yPos );
	this.xDivider = parseInt( divider );
	this.yDivider = parseInt( divider );
	eval( "tempObj" + this.ID + " = this;" );
	if( this.ticker ) clearInterval( this.ticker );
	this.ticker = setInterval( "tempObj" + this.ID + ".slideLoop();", tick );
}

function niceSlideBy( xDist, yDist, tick, divider ) {
	this.leftGoal = parseInt( this.left + xDist );
	this.topGoal = parseInt( this.top + yDist );
	this.slide( this.leftGoal, this.topGoal, tick, divider );
}

function niceSetBgColor( aColor ) {
	if( document.layers ) {
		this.doc.bgColor = aColor;
	} else
		if( aColor )
			this.style.background = aColor
		else
			this.style.background = "";
}

function niceWrite( text ) {
	if( document.layers ) {
		this.doc.open();
		this.doc.write( text );
		this.doc.close();
	} else {
		this.layer.innerHTML = text;
	}
	this.syncAll();
}

function niceLoad( anyURL, bufferFrame ) {
	if( document.layers ) {
		this.layer.src = anyURL;
	} else {
		this.bufferFrame = document.frames[ bufferFrame ];
		if( !this.bufferFrame )
			alert( "The buffer frame is not ready!" );
		else
			this.bufferFrame.document.location.href = anyURL;
	}
}

function niceLoadFinished() {
	if( !document.layers ) this.layer.innerHTML = this.bufferFrame.document.body.innerHTML;
}

function niceGetNested( layerID ) {
	eval( "var " + layerID + "Obj = new niceLayer( 0 );" );
	eval( "tLayer = " + layerID + "Obj" );
	tLayer.ID = layerID;
	tLayer.layer = ( document.layers ) ? this.doc.layers[ tLayer.ID ] : this.doc.all[ tLayer.ID ];
	tLayer.style = ( document.layers ) ? tLayer.layer : tLayer.layer.style;
	tLayer.doc = tLayer.layer.document;
	tLayer.images = tLayer.doc.images;
	tLayer.syncAll();
	return tLayer;
}

function niceClip( clipLeft, clipTop, clipWidth, clipHeight ) {
	if( document.layers ) {
		this.layer.clip.top = clipTop;
		this.layer.clip.right = clipWidth;
		this.layer.clip.bottom = clipHeight;
		this.layer.clip.left = clipLeft;
	} else this.style.clip = "rect(" + clipTop + "px " + clipWidth + "px " + clipHeight + "px " + clipLeft + "px )";
}