//- Instinct_Layer_W3 -//
function Instinct_Layer_W3(oLayer) {
//- Model - Link -//
	//- static -//
	Instinct_Layer__getLayer = Instinct_Layer_W3__getLayer;
	
	//- method -//
	oLayer.clearBuffer = clearBuffer;
	oLayer.appendBuffer = appendBuffer;
	oLayer.flushBuffer = flushBuffer;
	oLayer.replaceContent = replaceContent;
	oLayer.generateLayer = generateLayer;
	oLayer.streamLayer = streamLayer;
	oLayer.onLoad = onLoad;
	oLayer.show = show;
	oLayer.hide = hide;
	oLayer.moveTo = moveTo;
	oLayer.moveBy = moveBy;
	oLayer.clip = clip;
	
	//- get -//
	oLayer.getLayerParent = getLayerParent;
	oLayer.getLayer = Instinct_Layer__getLayer;
	oLayer.getVisibility = getVisibility;

	//- get : location -//
	oLayer.getOffsetLeft = getOffsetLeft;
	oLayer.getOffsetTop = getOffsetTop;
	oLayer.getLeft = getLeft;
	oLayer.getTop = getTop;
	oLayer.getWidth = getWidth;
	oLayer.getHeight = getHeight;
	oLayer.getRight = getRight;
	oLayer.getBottom = getBottom;
	oLayer.getZIndex = getZIndex;

	//- get : clip -//
	oLayer.getClipLeft = getClipLeft;
	oLayer.getClipTop = getClipTop;
	oLayer.getClipRight = getClipRight;
	oLayer.getClipBottom = getClipBottom;
	oLayer.getClipWidth = getClipWidth;
	oLayer.getClipHeight = getClipHeight;
	
	//- set -//
	oLayer.setClipHeight = setClipHeight;
	oLayer.setClipWidth = setClipWidth;
	oLayer.setZIndex = setZIndex;
	oLayer.setBgColor = setBgColor;
	oLayer.setBgImage = setBgImage;
	
	//- set : event -//
	oLayer.setOnMouseOver = setOnMouseOver;
	oLayer.setOnMouseOut = setOnMouseOut;
	oLayer.setOnClick = setOnClick;
	
	//- other -//
	oLayer.Restore = Restore;
	
//- Model - Implmentation -//
	//- Implmentation : Method -//
	function clearBuffer() {
		this.buffer = ''; 
	}
	function appendBuffer(cContent) {
		this.buffer += cContent;
	}
	function flushBuffer() {
		this.oLayer.innerHTML = this.buffer;
	}
	function replaceContent(cContent) { 
		this.clearBuffer();
		this.appendBuffer(cContent);
		this.flushBuffer();
	}
	function generateLayer() {
		//+ render layer
		var oDiv = document.createElement('DIV');
		oDiv.id = this.divName;
		oDiv.style.position = 'absolute';
		oDiv.style.visibility = 'hidden';
		oDiv.style.width = this.width;
		oDiv.style.height = this.height;
		oDiv.innerHTML = this.buffer;
		document.body.insertBefore(oDiv, null);
		this.oLayer = oDiv;
	}
	function streamLayer() {
		//+ render inline layer
		document.writeln('<div id="' + this.divName + '" style="position:absolute;visibility:hidden;width:' + this.width + 'px;height:' + this.height + 'px">');
		document.writeln(this.buffer);
		document.writeln('</div>');
		this.oLayer = document.getElementById(this.divName);
	}
	
	function onLoad() {
		if (document.getElementById(this.divName) != null) {
			this.oLayer = document.getElementById(this.divName);
		}
	}
	
	function show() {
		this.oLayer.style.visibility = 'visible';
	}	
	
	function hide() {
		this.oLayer.style.visibility = 'hidden';
	}
	
	function moveTo(nX, nY) {
		this.oLayer.style.left = nX;
		this.oLayer.style.top = nY;
	}
	
	function moveBy(nX, nY) {
		this.oLayer.style.left = this.getLeft() + nX;
		this.oLayer.style.top = this.getTop() + nY;
	}
	
	function clip(clipLeft, clipTop, clipRight, clipBottom) {
		this.oLayer.style.clip = 'rect('+ clipTop +' '+  clipRight +' '+ clipBottom +' '+ clipLeft +')';
	}

	//- Implmentation : Get -//
	function getLayerParent(cName) {
		var oLayer = getLayer(cName);
		if (oLayer != null) {
			return(oLayer.parentObject);
		} else {
			return(null);
		}
	} 
	
	function getVisibility() {
		return(this.oLayer.style.visibility);
	}

	//- Implmentation : Get_Location -//
	function getOffsetLeft() {
		return(this.oLayer.offsetLeft);
	}
	
	function getOffsetTop() {
		return(this.oLayer.offsetTop);
	}

	function getLeft() {
		var oLayer = this.oLayer;
		var nLeft = oLayer.offsetLeft;
		while (oLayer.offsetParent != null) {
			oLayer = oLayer.offsetParent;
			nLeft += oLayer.offsetLeft;
		}
		return(nLeft);
	}
	
	function getTop() {
		var oLayer = this.oLayer;
		var nTop = oLayer.offsetTop;
		while (oLayer.offsetParent != null) {
			oLayer = oLayer.offsetParent;
			nTop += oLayer.offsetTop;
		}
		return(nTop);
	}
	
	function getWidth() {
		var oLayer = this.oLayer;
		if (oLayer.offsetWidth != null) {
			return(oLayer.offsetWidth);
		} else {
			return(oLayer.clientWidth);
		}
	}
	
	function getHeight() {
		var oLayer = this.oLayer;
		if (oLayer.offsetHeight != null) {
			return(oLayer.offsetHeight);
		} else {
			return( oLayer.clientHeight);
		}
	}
	
	function getRight() {
		return(this.getLeft() + this.getWidth());
	}
	
	function getBottom() {
		return(this.getTop() + this.getHeight());
	}
	
	function getZIndex() {
		return(this.oLayer.style.zIndex);
	} 

	// -- Implementation : Get_Clip -- //
	function getClipLeft() {
		var oLayer = this.oLayer;
		if (oLayer.style.clip == '') return 0;
		
		var nDim = parseFloat(oLayer.currentStyle.clipLeft);
		return(isNaN(nDim) ? 0 : nDim);
	}
	
	function getClipTop() {
		var oLayer = this.oLayer;
		if (oLayer.style.clip == '') return 0;
		
		var vDim = parseFloat(oLayer.currentStyle.clipTop);
		return(isNaN(nDim) ? 0 : nDim);
	}
	
	function getClipRight() {
		var oLayer = this.oLayer;
		if (oLayer.style.clip == '') return(this.getWidth());
		
		var nDim = parseFloat( oLayer.currentStyle.clipRight);
		return(isNaN(nDim) ? 0 : nDim);
	}
	
	function getClipBottom() {
		var oLayer = this.oLayer;
		if (oLayer.style.clip == '') return(this.getHeight());
		
		var nDim = parseFloat(oLayer.currentStyle.clipBottom);
		return(isNaN(nDim) ? 0 : nDim);
	}
	
	function getClipWidth() {
		var oLayer = this.oLayer;
		if (oLayer.style.clip == '') return(this.getWidth());
		var nDim = parseFloat(oLayer.currentStyle.clipRight) - parseFloat(oLayer.currentStyle.clipLeft);
		return(isNaN(nDim) ? 0 : nDim);
	}
	
	function getClipHeight() {
		var oLayer = this.oLayer;
		if (oLayer.style.clip == '') return(this.getHeight());
		
		var nDim = parseFloat(oLayer.currentStyle.clipBottom) - parseFloat(oLayer.currentStyle.clipTop);
		return(isNaN(nDim) ? 0 : nDim);
	}

	//- Implementation : Set -//
	function setClipHeight(nHeight) {
		this.height = nHeight;
		this.oLayer.style.height = nHeight + 'px';
	}
	
	function setClipWidth(nWidth) {
		this.width = nWidth;
		this.oLayer.style.width = nWidth +'px';
	}
	
	function setZIndex(nZ) {
		if (!isNaN(parseInt(nZ))) {
			this.oLayer.style.zIndex = nZ;
		}
	}
	
	function setBgColor(cColor) {
		if (cColor.length > 0) {
			this.oLayer.style.backgroundColor = cColor;
		}
	}
	
	function setBgImage(cSource) {
		this.oLayer.style.backgroundImage = 'url('+ cSource +')';
	}
	
	//- Implementation : Set_Event -//
	function setOnMouseOver(hEvent) {
		this.oLayer.onmouseover = hEvent;
	}
	
	function setOnMouseOut(hEvent) {
		this.oLayer.onmouseout = hEvent;
	}
	
	function setOnClick(hEvent) {
		this.oLayer.onclick = hEvent;
	} 

	//- Implementation : Other -//
	function Restore() {
		window.location.href = window.location.href;
	}
}

//- static -//
function Instinct_Layer_W3__getLayer(cName) {
	return document.getElementById(cName);
}