var FLASH_OBJ_ID = "jigsawFlashObject";
var FLASH_CONTAINER_ID = "jigsawFlashContainer";
var FOOTER_HEIGHT = 20;

function SetFlashDivHeight(a_height)
{
	var l_obj = document.getElementById(FLASH_CONTAINER_ID);
	var l_flashobj = document.getElementById(FLASH_OBJ_ID);
	var l_minHeight = GetWindowHeight() - FOOTER_HEIGHT;
	a_height = a_height < l_minHeight ? l_minHeight : a_height ;
	l_obj.style.height = a_height+"px";
}

function GetFlashDivHeight()
{
	var l_obj = document.getElementById(FLASH_CONTAINER_ID);
	var l_height = l_obj.style.height;
	
	return parseFloat(l_height);
}

function GetWindowHeight()
{
	if(window.innerHeight)
	{
		return window.innerHeight;
	}else if(document.body.clientHeight)
	{
		return document.body.clientHeight;
	}else
	{
		return 0;
	}
}

function GetScrollHeight()
{
	var l_windowHeight = GetWindowHeight();
	var l_maxHeight = GetFlashDivHeight();
	l_maxHeight = l_maxHeight < l_windowHeight ? l_windowHeight : l_maxHeight;
	
	return (l_maxHeight - l_windowHeight);		// 20 is the height of the footer
}

function GetScrollYOffset()
{
	var l_ret = 0;
	if(window.pageYOffset )
	{
		l_ret = window.pageYOffset;
	}else if(document.body && document.body.scrollTop)
	{
		l_ret = document.body.scrollTop;
	}else if(document.documentElement && document.documentElement.scrollTop)
	{
		l_ret = document.documentElement.scrollTop;
	}
	return (l_ret ? l_ret : 0);
}

function GetScrollPercentage()
{
	var l_ret = GetScrollYOffset()/GetScrollHeight();
	return l_ret;
}


/**
 * 
 * @param a_scrollPercentage 		This sets the scroll position on the page 0 is top of page 1 is bottom of page
 * @return
 */
function SetScrollPosition(a_scrollPercentage)
{
	// Make sure we are not getting wrong values
	a_scrollPercentage = a_scrollPercentage <= 0 ? 0 : a_scrollPercentage >= 1 ? 1 : a_scrollPercentage;
	window.scroll(0, GetScrollHeight()*a_scrollPercentage);
}


function gotoSectionById(a_id)
{
	SWFAddress.setValue(a_id);
}
