// the maximal width of the site
var maxSiteWidth = 1250; 
var minDocumentHeight = 2000; 
var siteOutlineOffset = -5;
var siteOutlineLeftWidth = 360;
var siteOutlineRightWidth = 0;
var siteOutlineRightPadding = 15;
var siteOutlineLeftPadding = 30;
var siteOutlineCenterPadding = 15;
var paperOffset = -15;
var centerHeightFromAllDifference = 20;




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; 
};



// 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;
}


// updates the elements positions
function refreshMainElementsPositions()
{
  //try{
  
  var effectiveWindowWidth = getWindowWidthMain();
  var effectiveSiteWidth = Math.min( maxSiteWidth, effectiveWindowWidth );
  var msieVersionRef = 0;
  try {
    msieVersionRef = getMsieVersionMain();
    if ( msieVersionRef && msieVersionRef < 7 )
    {
      // correcting the scrollbar;
      effectiveSiteWidth -= 20;
    }
  } catch(e) {};
  
  try{
  setElementLeftByIdMain( 'siteOutlineLeft', 
    ( effectiveWindowWidth - effectiveSiteWidth ) / 2 + siteOutlineLeftPadding + siteOutlineOffset );
  }catch(e){};
  try{
  setElementLeftByIdMain( 'siteOutlineRight', 
    ( effectiveWindowWidth + effectiveSiteWidth ) / 2 - siteOutlineRightWidth-1 - siteOutlineRightPadding + siteOutlineOffset );
  }catch(e){};
  try{
  setElementLeftByIdMain( 'siteOutlineCenter', 
    ( effectiveWindowWidth - effectiveSiteWidth ) / 2 + 0*siteOutlineLeftPadding + siteOutlineOffset );
  }catch(e){};
  try{
  setElementWidthByIdMain( 'siteOutlineCenter', 
    effectiveSiteWidth - ( 0*siteOutlineLeftWidth + 0*siteOutlineRightWidth + 
      1 * ( 0*siteOutlineLeftPadding + 0*siteOutlineCenterPadding + siteOutlineRightPadding ) ) );
  }catch(e){};
  try{
  setElementWidthByIdMain( 'contentContainer', 
    effectiveSiteWidth - ( siteOutlineLeftWidth + siteOutlineRightWidth + 
      1 * ( siteOutlineLeftPadding + 2*siteOutlineCenterPadding + siteOutlineRightPadding ) ) );
  }catch(e){};
  try{
  setElementWidthByIdMain( 'siteOutlineLeft', siteOutlineLeftWidth );
  }catch(e){};

  try{
  setElementLeftByIdMain( 'siteOutlineFooter', siteOutlineLeftPadding );
  }catch(e){};
  try{
  setElementWidthByIdMain( 'siteOutlineFooter', 
    effectiveSiteWidth - ( siteOutlineLeftPadding + siteOutlineRightPadding ) );
  }catch(e){};
      
  //setElementLeftById( 'backgroundOutlineP', 
  //  ( effectiveWindowWidth - effectiveSiteWidth ) / 2 + paperOffset );
  try{
  setElementWidthByIdMain( 'backgroundOutlineC', 
    effectiveSiteWidth);
  }catch(e){};
    
    
  if ( msieVersionRef )// && msieVersionRef == 7 )
  {
    //setElementHeightById( 'backgroundOutlineP', 0 );
    setElementHeightByIdMain( 'backgroundOutline', 0 );
    var siteHeight = max( max( 
      getElementHeightById( 'siteOutlineCenter' )+getElementTopById( 'siteOutlineCenter' ),
      getElementHeightById( 'siteOutlineLeft' )+getElementTopById( 'siteOutlineLeft' ) ),
      getElementHeightById( 'siteOutlineRight' )+getElementTopById( 'siteOutlineRight' ) ) + 250;
      
    setElementHeightByIdMain( 'backgroundOutline', siteHeight );
    //setElementHeightById( 'backgroundOutlineP', siteHeight-centerHeightFromAllDifference );
  }
  else
  {
    //setElementHeightById( 'backgroundOutlineP', 0 );
    setElementHeightByIdMain( 'backgroundOutline', 0 );
    //setElementHeightById( 'backgroundOutlineP', getDocumentHeight() );
    setElementHeightByIdMain( 'backgroundOutline', getDocumentHeight()+centerHeightFromAllDifference );
  };
  
  try{
    setElementHeightByIdMain( "documentContentId", max(getWindowHeightMain(), minDocumentHeight) );
  }catch(e){};
  

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

  //}catch(e){alert(e.message)};
}

// 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 = getMsieVersionMain();
if ( msieVersion && msieVersion < 7 )
{
  //window.onscroll = refreshMainElementsPositions;
}


try{
if (parseFloat(getMsieVersionMain()) < 7) 
{ 
  setTimeout(function(){
    var image = '';
    image = obtainElementByIdMain('logoImage'); 
    image.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+image.src+"',sizingMethod='image')"; 
    image.src = "/themes/default/background/blank.gif";
    
    image = obtainElementByIdMain('teachers'); 
    image.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+image.currentStyle.backgroundImage.replace(/url\(('|")(.*)('|")\)/,'$2')+"',sizingMethod='crop')"; 
    image.style.backgroundImage = "url(/themes/default/background/blank.gif)";
    
    image = obtainElementByIdMain('phones'); 
    image.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+image.currentStyle.backgroundImage.replace(/url\(('|")(.*)('|")\)/,'$2')+"',sizingMethod='crop')"; 
    image.style.backgroundImage = "url(/themes/default/background/blank.gif)";
  },100);
}
}catch(e){}

