LoocosSite.getInstance().addReadyHandler( function (){

  var menuboxes = $("div.navi>ul>li");
  var menuboxesmore = $("div.navi>ul>li.navimore");

  menuboxes.mouseleave( function( event ){
    //console.log("mouseleave()");
    //$(this).children( 'ul.level2').slideUp(50);
    $('ul.level2').stop( true, true ).hide();
  });

  menuboxes.mouseenter( function(){
    //console.log("mouseenter()");
    $('ul.level2').stop( false, true ).hide();

    var submenu = $(this).children( 'ul.level2' );
    submenu.stop().show(50).slideDown();

    $(submenu).find('li').each( function( ){
      $(this).click( function( event ){
	event.preventDefault();
	window.location = $(this).find("a").attr("href");
      });
    });

  });

  menuboxes.click( function( event ){
    event.preventDefault();
    if ( ! $(this).hasClass( 'navimore' ) ){
      window.location = $(this).find("a").attr("href");
    }
  });

  $('div.navi>ul>li').each( function() {
    if ( $(this).hasClass( 'navimore' ) ){
      $(this).children( 'a' ).click( function ( event ) {
	event.preventDefault();
      });
    }
  });

  var noderef = location.href;
  $('div.navi a').each( function() {
    var node = $(this);
    if ( node.hasClass( 'main' ) || node.hasClass( 'main2') ){
      var linkstuff = this.href;
      if ( linkstuff == noderef ){
	node.addClass("navisel");
	if ( node.hasClass( 'main2' ) ){
	  node.parents( 'li.navimore ').css( 'background-image', 'url(/images/downsel.png)' );
	}
      }
    }
  });

  height = $('#maincontent').height();
  if ( height < 400 )
    $('#maincontent').css( 'min-height', 400 );

});

