// Defines the minium space between the content and the footer
// used when the content is bigger then window
MINIUM_FOOTER_GAP = 150;

window.onresize = moveFooter;

function moveFooter()
{    
    setContentHeight();
    positionFooter();	
}

function positionFooter()
{
    var contentHeight = 0;
    var footer = document.getElementById(footerID);
    
    // work out the window height bassed on the client browser
	if(IsMozilla())
	{
		windowHeight = window.innerHeight;
	}
	else if(IsInternetExplorer())
	{	    
		windowHeight = document.body.clientHeight;
		footer.style.zIndex = -1;
	}			
			
	contentHeight = getContentHeight();

	// if the window is greater then the content height then positon the footer relative to the window height
	if (windowHeight > contentHeight)
	{	    
		footer.style.top = windowHeight - footer.offsetHeight;
	}
	// else postion the footer relative to the content height
	else
	{
		footer.style.top = contentHeight;
	}
	
	// the footer is hidden until its been moved, so we need to fix the style.
	footer.style.visibility = 'visible';
}

function getContentHeight()
{       
	var contentContainer = document.getElementById(footerContentContanerID);
	var navBar = document.getElementById(navBarID);	
	
	var contentHeight = 0	
	var navBarHeight = 0;
	var contentContainerHeight = 0;
	
	if (contentContainer != null)
	{
		contentContainerHeight = contentContainer.offsetHeight;		
	}	
	else
	{
	    contentContainer = document.getElementById(fullPanelContentID);
	    
	    if (contentContainer != null)
	    {
	        contentContainerHeight = contentContainer.offsetHeight;		
	    }
	}
	
	if (navBar != null)
	{	    
		navBarHeight = navBar.offsetHeight;
	}	
    
    // set the content height to be equal to the tallest element in the content
	if (navBarHeight > contentContainerHeight)
	{
		contentHeight = navBarHeight;
	}
	else
	{
	    contentHeight = contentContainerHeight;
	}
	
	// add the gap so that there is space between footer and the content
	return contentHeight + MINIUM_FOOTER_GAP;
}

function setContentHeight()
{
   var content = document.getElementById(footerContentContanerID);
   var navBar = document.getElementById(navBarID);
   
   if (content != null)
   {
     // content.style.height = navBar.scrollHeight;
   }
}
