// the maximal width of the site
var maxSiteWidth = 1200;
var siteOutlineLeftWidth = 0;
var siteOutlineRightWidth = 160;
var siteOutlineRightPadding = 5;
var siteOutlineLeftPadding = 5;
var siteOutlineCenterPadding = 5;
var paperOffset = -15;
var centerHeightFromAllDifference = 350;

var displayFullNavigationBox = false;
var getNavigationBoxHeight = function()
{ 
  if ( displayFullNavigationBox )
  {
    return getWindowHeight() - 150;
  }
  else
  {
    return 15;
  };
};
var getSiteHelperPanelMaxHeight = function()
{ 
  return getNavigationBoxHeight() + 90;
};
var getSiteHelperPanelMinHeight = function()
{
  return 1; 
};

// updates the elements positions
function refreshMainElementsPositions()
{
  var effectiveWindowWidth = getWindowWidth();
  var effectiveSiteWidth = min( maxSiteWidth, effectiveWindowWidth );
  setElementLeftById( 'siteOutlineLeft', 
    ( effectiveWindowWidth - effectiveSiteWidth ) / 2 + siteOutlineLeftPadding );
  setElementLeftById( 'siteOutlineRight', 
    ( effectiveWindowWidth + effectiveSiteWidth ) / 2 - siteOutlineRightWidth-1 - siteOutlineRightPadding );
  setElementLeftById( 'siteOutlineCenter', 
    ( effectiveWindowWidth - effectiveSiteWidth ) / 2 + siteOutlineLeftWidth + 
      2 * siteOutlineLeftPadding + siteOutlineCenterPadding );
  setElementWidthById( 'siteOutlineCenter', 
    effectiveSiteWidth - ( siteOutlineLeftWidth + siteOutlineRightWidth + 
      2 * ( siteOutlineLeftPadding + siteOutlineCenterPadding + siteOutlineRightPadding ) ) );
    
  setElementLeftById( 'backgroundOutlineP', 
    ( effectiveWindowWidth - effectiveSiteWidth ) / 2 + paperOffset );
  setElementWidthById( 'backgroundOutlineC', 
    effectiveSiteWidth);
    
  var msieVersion = getMsieVersion();
  if ( msieVersion && msieVersion < 7 )
  {
    var siteHeight = max( max( 
      getElementHeightById( 'siteOutlineCenter' )+getElementTopById( 'siteOutlineCenter' ),
      getElementHeightById( 'siteOutlineLeft' )+getElementTopById( 'siteOutlineLeft' ) ),
      getElementHeightById( 'siteOutlineRight' )+getElementTopById( 'siteOutlineRight' ) ) + 20;
      
    setElementHeightById( 'backgroundOutline', siteHeight );
    setElementHeightById( 'backgroundOutlineC', siteHeight-centerHeightFromAllDifference );
  }
  else
  {
    setElementHeightById( 'backgroundOutlineC', 0 );
    setElementHeightById( 'backgroundOutline', 0 );
    setElementHeightById( 'backgroundOutlineC', getDocumentHeight()-centerHeightFromAllDifference );
    setElementHeightById( 'backgroundOutline', getDocumentHeight() );
  };

  // updating the site helper panel position
  // on the first load it is not defined yet
  try
  {
    siteHelperPanelUpdatePosition();
  } catch ( e ) { };
}

// setting the onresize event for the window
window.onresize = refreshMainElementsPositions;

// assigning the script to move the site helper panel to the bottom of the screen
var msieVersion = getMsieVersion();
if ( msieVersion && msieVersion < 7 )
{
  window.onscroll = refreshMainElementsPositions;
}
