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

// functions cache to speedup 
function obtainElementByIdMain( id )
{
  if ( document.getElementById )
    return document.getElementById( id );
  else
    return document.all( id );
}
function setElementWidthByIdMain( elementId, width )
{
  var element = obtainElementByIdMain( elementId );
  if ( element )
  {
    // to work on both: IE and good browsers
    if ( typeof( width ) == 'number' )
      element.style.width = width+"px";
    else
      element.style.width = width;
  }  
}
function setElementHeightByIdMain( elementId, height )
{
  var element = obtainElementByIdMain( elementId );
  if ( element )
  {
    // to work on both: IE and good browsers
    if ( typeof( height ) == 'number' )
      element.style.height = '' + max(0,height)+"px";
    else
      element.style.height = height;
  };
}
function setElementLeftByIdMain( elementId, left )
{
  var element = obtainElementByIdMain( elementId );
  if ( element )
  {
    // to work on both: IE and good browsers
    if ( typeof( left ) == 'number' )
      element.style.left = left+"px";
    else
      element.style.left = left;
  };
}
function getMsieVersionMain()
{
  var msieVersion = navigator.userAgent.match(/MSIE (\d)/);
  if ( msieVersion && msieVersion[1] )
  {
    return msieVersion[1];
  }
  else
  {
    return false;
  }
}
function getWindowWidthMain()
{
  var scrollBarWidth = 20;
  if ( navigator.userAgent.indexOf("IE") >= 0 )
    scrollBarWidth = 0;
  return ( (document.all)? document.body.clientWidth : window.innerWidth ) - scrollBarWidth;
}
function getWindowHeightMain()
{
  if ( typeof(window.innerHeight) == 'number' && window.innerHeight )
    return window.innerHeight;
  else if ( document.documentElement && typeof(document.documentElement.clientHeight) == 'number' && document.documentElement.clientHeight )
    return document.documentElement.clientHeight;
  else if ( document.body && typeof(document.body.clientHeight) == 'number' && document.body.clientHeight )
    return document.body.clientHeight;
  else
    return 0;
}


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

// updates the elements positions
function refreshMainElementsPositions()
{
  try{
    setElementHeightByIdMain( "documentContentId", max(getWindowHeightMain(), minDocumentHeight) );
  }catch(e){};
}

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

function fixPngInIe6()
{
  var logoImage = obtainElementByIdMain('logoImage'); 
  logoImage.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+logoImage.src+"',sizingMethod='image')"; 
  logoImage.src = THEME_PATH+"background/blank.gif";
}

try{
if (parseFloat(getMsieVersionMain()) < 7) 
{ 
  addDependentCallback(function(){
    onAfterLoad += 'fixPngInIe6(); ';
  },'globalEvents');
}
}catch(e){}

addDependentCallback(setAdminButtonState,'authorization');
function setAdminButtonState()
{ 
  if (USER_RIGHTS_MODERATE)
  {
    setDisplayState(obtainElementById("admin"), "block");
  }
  else
  {
    setDisplayState(obtainElementById("admin"), "none");
  }
  setTimeout(function(){addDependentCallback(setAdminButtonState,'authorization')}, 1000);
}

