var sFLB 			= 'FLBALL';
var sFLBDOC 		= 'FLB_';
var SFLBPOS			= 'POSFLB';
var Sori			= 'ori';
var iflbposx 		= 0;
var iflbposy 		= 0;
var iflbx 			= 0;
var iflby 			= 0;
var iorix 			= 0;
var ioriy 			= 0;
var iflbmaxwidth 	= 0;
var iflbmaxheight 	= 0;

//alert(" x " + iflbx + " y " + iflby + " iflbmaxwidth " + iflbmaxwidth + " iflbmaxheight " + iflbmaxheight);

/********************************************************************/
/********************************************************************/
/********************************************************************/
function setBgImgFLB(mode)
{
	searchFLB( document );
	//alert(" iflbmaxwidth " +  iflbmaxwidth + " : iflbmaxheight " + iflbmaxheight + " mode = "+mode);
	if (mode && mode=='edit'){
		iflbmaxheight = iflbmaxheight + 300;
	}
	try
	{
		obj = document.getElementById('BgImgFLB');
		obj.width=iflbmaxwidth;
		obj.height=iflbmaxheight;
	}
	catch(e)
	{
	}
}



function getPositionPOSFLB()
{
	searchFLBPOS( document );
	//alert(" X " +  iflbposx + " : Y " + iflbposy );
}

function setPositionFLB()
{
	searchFLB( document );
	searchOri( document );
	SetPositionId( SFLBPOS , iorix + iflbmaxwidth , ioriy + iflbmaxheight);
}


function searchFLBPOS (parent)
{
	var children = parent.childNodes;
	for (var i = 0; i < children.length; i++)
	{
		var child = children[i];
		if (child.nodeType != 1) {
			continue;
		}
		if (child.id.indexOf(SFLBPOS) == 0 )
		{
			iflbposx = getOffsetLeft (child);
			iflbposy = getOffsetTop (child);
			return;
		}
		searchFLBPOS (child);
	}
}

function searchFLB (parent)
{
	var children = parent.childNodes;
	for (var i = 0; i < children.length; i++)
	{
		var child = children[i];
		if (child.nodeType != 1) {
			continue;
		}
		if (child.id.indexOf(sFLB) == 0 )
		{
			iflbx = getOffsetLeft (child);
			iflby = getOffsetTop (child);

			searchFLBChild(child);

			return child;
		}
		searchFLB (child);
	}
}

function searchOri (parent)
{
	var children = parent.childNodes;
	for (var i = 0; i < children.length; i++)
	{
		var child = children[i];
		if (child.nodeType != 1) {
			continue;
		}
		if (child.id.indexOf(Sori) == 0 )
		{
			iorix = getOffsetLeft (child);
			ioriy = getOffsetTop (child);

			return child;
		}
		searchOri (child);
	}
}


function searchFLBChild (parent)
{
	var children = parent.childNodes;
	for (var i = 0; i < children.length; i++)
	{
		var child = children[i];
		if (child.nodeType != 1) {
			continue;
		}
		if (child.id.indexOf(sFLBDOC) == 0 )
		{
			if( getWidthMax(child) > iflbmaxwidth )
			{
				iflbmaxwidth =  getWidthMax(child);
			}
			if( getHeigthMax(child) > iflbmaxheight )
			{
				iflbmaxheight =  getHeigthMax(child);
			}
		}
		searchFLBChild (child);
	}
}



function SetPositionId ( id , ix , iy )
{
	try
	{
		e = document.getElementById ( id );
		e.style.width = ix + "px";
		e.style.height = iy + "px";
	}catch(ex){}
}

function getWidthMax ( e)
{
	return ( e.offsetLeft + e.offsetWidth );

}

function getHeigthMax (e)
{
	return ( e.offsetTop + e.offsetHeight );
}

function getOffsetTop (e)
{
	var top = e.offsetTop;
	var parent = e.offsetParent;
	while (parent) {
		top += parent.offsetTop;
		parent = parent.offsetParent;
	}
	return top;
}

function getOffsetLeft (e)
{
	var left = e.offsetLeft;
	var parent = e.offsetParent;
	while (parent) {
		left += parent.offsetLeft;
		parent = parent.offsetParent;
	}
	return left;
}

