﻿
///#required nineCommon.js For NTSize, NTPoint


function nineFloatLayer(objID)
{
	this.objID=objID;
	this.Offset=new NTPoint(0, 0);
	this.MinPos=new NTPoint(null, null);
	this.MaxPos=new NTPoint(null, null);
	this.objArea=new NTArea(null, null, null, null);
	this.CtrlTypeX=-1; //-1:NONE 1:DOCK LEFT 2:DOCK RIGHT 
	this.CtrlTypeY=-1; //-1:NONE 1:DOCK TOP 2:DOCK BOTTOM
	this.intvalKey=null;	
}

nineFloatLayer.prototype.SetTimer=function (thisName)
{
	this.KillTimer();
	this.intvalKey=setInterval(thisName+".OnMoveLayer();", 100);
	
}
nineFloatLayer.prototype.KillTimer=function ()
{
	if(this.intvalKey!=null)
		clearInterval(this.intvalKey); 
	this.intvalKey=null;
}

nineFloatLayer.prototype.OnMoveLayer=function ()
{
	var WinSize=this.GetWindowDimensions(null);
	var PageSize=this.GetPageDimensions(null);
	var ScrollPos=this.GetScrollPosition(null);
	//alert("WSIZE:"+WinSize);
	//alert("SPOS:"+ScrollPos);
	//alert("CtrlTypeY:"+this.CtrlTypeY);
	
	switch(this.CtrlTypeX)
	{
	case 1:
		document.getElementById(this.objID).style.left=ScrollPos.x+this.Offset.x;
		break;
	case 2:
		document.getElementById(this.objID).style.left=ScrollPos.x+WinSize.width-this.Offset.x;
		break;
	}
	
	switch(this.CtrlTypeY)
	{
	case 1:
		document.getElementById(this.objID).style.top=ScrollPos.y+this.Offset.y;
		break;
	case 2:
		document.getElementById(this.objID).style.top=ScrollPos.y+WinSize.height-this.Offset.y;
		break;
	}
}

nineFloatLayer.prototype.GetScrollPosition=function (twindow) {
	var tPoint=new NTPoint(0,0);
	if(!twindow || twindow==null)
	{
		if(document.body)
		{
			tPoint.x=document.body.scrollLeft;
			tPoint.y=document.body.scrollTop;
		}
		else if(document.documentElement)
		{
			tPoint.x=document.documentElement.scrollLeft;
			tPoint.y=document.documentElement.scrollTop;
		}
	}
	else
	{
		if (twindow && !window.opera){
			
		}

	}
	return tPoint;
}
nineFloatLayer.prototype.GetPageDimensions=function (twindow) {
	
	var xScroll, yScroll;
	var tSize=new NTSize(0,0);
	if(!twindow || twindow==null)
	{
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;//document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ 
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		

		var windowWidth, windowHeight;
		if (self.innerHeight) {	
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { 
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		if(yScroll < windowHeight){
			tSize.height = windowHeight;
		} else { 
			tSize.height = yScroll;
		}

		if(xScroll < windowWidth){	
			tSize.width = windowWidth;
		} else {
			tSize.width = xScroll;
		}
	}
	else
	{
		if (twindow && !window.opera){
			if((twindow.contentDocument && twindow.contentDocument.body.offsetHeight) || (twindow.document && twindow.document.body.scrollHeight))
			{
				if (twindow.contentDocument && twindow.contentDocument.body.offsetHeight) //ns6 syntax
					tSize.height = twindow.contentDocument.body.offsetHeight; 
				else if (twindow.document && twindow.document.body.scrollHeight) //ie5+ syntax
					tSize.height = twindow.document.body.scrollHeight;
			}
			else
			{
				if (twindow.document && twindow.document.body) { 
					tSize.height = twindow.document.body.clientHeight;
				}	
				
				
			}
			if((twindow.contentDocument && twindow.contentDocument.body.offsetWidth) || (twindow.document && twindow.document.body.scrollWidth))
			{
				if (twindow.contentDocument && twindow.contentDocument.body.offsetWidth) //ns6 syntax
					tSize.width = twindow.contentDocument.body.offsetWidth; 
				else if (twindow.document && twindow.document.body.scrollWidth) //ie5+ syntax
					tSize.width = twindow.document.body.scrollWidth;
			}
			else
			{
				if (twindow.document && twindow.document.body) { 
					tSize.width = twindow.document.body.clientWidth;
				}
			}
		}

	}
	return tSize;
}

nineFloatLayer.prototype.GetWindowDimensions=function (twindow) {
	
	var xScroll, yScroll;
	var tSize=new NTSize(0,0);
	if(!twindow || twindow==null)
	{
		
		

		var windowWidth, windowHeight;
		if (self.innerHeight) {	
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { 
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		tSize.height = windowHeight;
		tSize.width = windowWidth;
		
	}
	
	return tSize;
}

	
