// JavaScript Document

var $j = jQuery.noConflict();
var protect = false;

  function layout()
  {
    $j("#sidebar .menu-item a:visible:first").css('border', 'none');
  
    var infobox = $j("#infobox");

    var menupos = $j("#access").position();
    var menuheight = $j("#access").height();
      
    if (infobox.length > 0)
    {
      var pos = $j("#content").height();
      // var pos = $j('#clear').position().top;
      // var top = pos.top;
      var top = pos - $j("#infobox").height();
      var newpos = -top - 10;
  
      var menubottom = -top + menupos.top + menuheight;
      
      // var newpos = menubottom;
      
      if ($j.browser.msie)
      {
        if ($j.browser.version<=7)
        {
          newpos = -top;
        }
      }
  
      $j("#infobox").css({top: newpos});
      
      var newheight = $j("#content").height() - $j("#infobox").height();
      $j("#content").css('height', newheight);
    }

    if ($j.browser.msie)
    {
      if ($j.browser.version<7)
      {
        pos = $j("#primary").position();
        top = pos.top;
        newpos = -top +menupos.top + menuheight;
        $j("#primary").css({top: newpos});
      }
    }


  }

  function mainmenu(){
    $j(" #mainmenu ul li ul").css({display: "none"});
    $j(" #mainmenu li").hover(showmenu, hidemenu);

    function showmenu(event){
      $j(' #submenu ul').css( { visibility: "hidden" } );

      var mythis = $j(this);
      var offset = mythis.position();

      var top = offset.top
      var height = mythis.innerHeight();
      var width = mythis.outerWidth();
      var left = offset.left

      // $j('#log').text("top: " + top + " height: " + height + " :: " + event.pageY);


      $j(this).find('ul:first').css( { 
        display:"inline",
        fontWeight:"normal",
        position:"absolute",
        top: (top + (height/2) + 15) + "px",
        left: (left - (width/2)) + "px"
        } );

      event.preventDefault();        
    };
    
    function hidemenu(event){
      $j(' #submenu ul').css( { visibility: "visible" } );
      $j(this).find('ul:first').css( { display: "none" } );

      event.preventDefault();        
    };
    
  }

  $j(document).ready(function(){
    mainmenu();
    $j(window).load(function(){
      layout();
      });
    // setTimeout('layout()', 500);
    // layout();
  });

