
function FlineController()
{
	this.SniSelected = document.getElementById('tdSniSelected')
	this.divSniSelector = document.getElementById('divSniSelector')
	if( this.SniSelected && this.divSniSelector )
	{
		this.showSniSelector()
	}
	
	this.TniSelected = document.getElementById('divTniSelected')
	this.divTniSelector = document.getElementById('divTniSelector')
	if( this.SniSelected && this.TniSelected && this.divTniSelector )
	{
		this.showTniSelector()
	}
}


FlineController.prototype.showSniSelector = function()
{
	var refPoint = this.getElementPos(this.SniSelected)
	this.divSniSelector.style.top = this.toPx(refPoint.top - 40)
	this.divSniSelector.style.left = this.toPx(175)
	this.divSniSelector.style.height = this.toPx(40)
	this.divSniSelector.style.width = this.toPx(refPoint.left - 175)
}


FlineController.prototype.showTniSelector = function()
{
	var refPointSni = this.getElementPos(this.SniSelected)
	var refPointTni = this.getElementPos(this.TniSelected.parentNode)

	this.divTniSelector.style.top = this.toPx(refPointSni.top + 10)
	this.divTniSelector.style.left = this.toPx(refPointSni.left - 30)
	this.divTniSelector.style.height = this.toPx(refPointTni.top + this.TniSelected.offsetTop - refPointSni.top)
	this.divTniSelector.style.width = this.toPx(30)
}


FlineController.prototype.getElementPos = function(elem)
{
	var left = this.findPosLeft(elem)
	var top  = this.findPosTop(elem)

	return {
		left: left,
		top:  top
	}
}


FlineController.prototype.toPx = function(px)
{
	return (px + 'px')
}

FlineController.prototype.findPosLeft = function(elem)
{
	var left = 0
	if( elem.offsetParent )
	{
		while( elem.offsetParent )
		{
			left += elem.offsetLeft
			elem = elem.offsetParent
		}
	}
	else if( elem.x )
	{
		left += elem.x
	}
	return left
}


FlineController.prototype.findPosTop = function(elem)
{
	var top = 0;
	if( elem.offsetParent )
	{
		while( elem.offsetParent )
		{
			top += elem.offsetTop
			elem = elem.offsetParent
		}
	}
	else if(elem.y )
	{
		top += elem.y
	}
	return top
}
