var ListerLoaded = false;
var TimeOutID;

function adjustLayout()
{
  clearInterval(TimeOutID);
  
  // Get natural heights
  var MarginBottom = 30;
  var topHeight    = (xHeight("top") + MarginBottom);
  var cHeight 		 = xHeight("MainContent");
  var lHeight 		 = xHeight("left");
  var ScreenHeight = (xClientHeight() - topHeight);
    
  // Find the maximum height
  var maxHeight = Math.max(cHeight, lHeight, ScreenHeight);
  
  // Assign maximum height to all columns  
  xHeight("MainContent", maxHeight);
  xHeight("left", maxHeight);
  
  //topHeight = xHeight("top");
   
  xHeight("containerLeft", (maxHeight +  topHeight - MarginBottom ) );
  xHeight("containerRight", (maxHeight +  topHeight - MarginBottom ) );
  
  RepositionUserLogin();
  loadlistener();
}


function loadlistener()
{
  if (!ListerLoaded)
  {
		// Built in delay for resize event.
		xAddEventListener(window, "resize", ResizeListener, false);
		ListerLoaded = true;
  }
	
  xAddEventListener(window, "scroll", RepositionUserLogin, false);  
}

var OnInitState = true;
var UserLoginDivHeight;
function RepositionUserLogin()
{	
	YTopLeftMenu     = 110;
	MarginBottom     = 42;
	MinScrollTop     = (xHeight("leftmenu") +  YTopLeftMenu - MarginBottom);
	ScreenHeight     = xClientHeight();
	ScrollTop        = xScrollTop();	
	YTopUserLogin    = (ScreenHeight - YTopLeftMenu) + ScrollTop;
	MaxTopLeft 		  = xHeight("left") + YTopLeftMenu;
	
	if (OnInitState)
	{
		UserLoginDivHeight = xHeight("UserLogin"); // This is for an Firefox workaround. Wich constantly thinks the height of userlogin is changing :S
		xTop("UserLogin",  MinScrollTop);
		OnInitState = false;
	}
		
	if (YTopUserLogin < MaxTopLeft)
	{
		YTopUserLogin   -= parseInt(MarginBottom + UserLoginDivHeight);
		
		if (YTopUserLogin > MinScrollTop)
		xSlideTo("UserLogin",0,YTopUserLogin,2000);
	}	
}


var g_bH = false;
  
function init(p_strId) {
    g_bH = false;
    var l_E = document.getElementById(p_strId);
    if(l_E && document.defaultView) {
      if(document.defaultView.getComputedStyle(l_E, 'hover')) {
        g_bH = true;
      }
    }
    l_E = null;
 }

function ResizeListener()
{
	if (TimeOutID)
	{		
		clearInterval(TimeOutID);		
	}
	
	TimeOutID = setInterval("adjustLayout()", 1000);	
}

