$.fn.x = function(n) {
      var result = null;
      this.each(function() {
          var o = this;
          if (n === undefined) {
              var x = 0;
              if (o.offsetParent) {
                  while (o.offsetParent) {
                      x += o.offsetLeft;
                      o = o.offsetParent;
                  }
              }
              if (result === null) {
                  result = x;
              } else {
                  result = Math.min(result, x);
              }
          } else {
              o.style.left = n + 'px';
          }
      });
      return result;
 };

 $.fn.y = function(n) {
      var result = null;
      this.each(function() {
          var o = this;
          if (n === undefined) {
              var y = 0;
              if (o.offsetParent) {
                  while (o.offsetParent) {
                      y += o.offsetTop;
                      o = o.offsetParent;
                  }
              }
              if (result === null) {
                  result = y;
              } else {
                  result = Math.min(result, y);
              }
          } else {
              o.style.top = n + 'px';
          }
      });
      return result;
 }; 
 

$(document).ready(function(){
	//onresize = init_scrollbar();

	i_left = $("#marker").x();
	$("#container").css("left", i_left);
	$("#scrollArea").css("left", i_left+565+5);
	$("#mid #dog").css("left", i_left+665+30);
	oMenuL1 = $("#main_menu_L1 .margin");
	oMenuL1.css("margin-left", i_left-$("#main_menu_L1 .margin div.separator").width() );
	oMenuL1.css("width", oMenuL1.width()+$("#main_menu_L1 .margin div.separator").width());
	oMenuL2 = $("#main_menu_L2 .margin");
	oMenuL2.css("margin-left", i_left-10);
	
	// white space
	new_mid_height = $("body").height()-80-227;
	if (new_mid_height > $("#mid").height() )
	{
		$("#mid").css("height", $("body").height()-80-227);
	}
	$("#container").css("height", $("#mid").height()-130);
	$("#mid #dog").css("top", $("#mid").height()+188-314);

	// little hack instead of has_subitems
	$(".section").each(function(){
		if ($(this).html().replace(/^\s+|\s+$/g, '') == "")
		{
			$(this).remove();
		}
	
	});

	init_L2_menu();
});

$(window).resize(function(){
	i_left = $("#marker").x();
	$("#container").css("left", i_left);
	$("#scrollArea").css("left", i_left+565+5);
	$("#mid #dog").css("left", i_left+665+30);
	oMenuL1 = $("#main_menu_L1 .margin");
	oMenuL1.css("margin-left", i_left-$("#main_menu_L1 .margin div.separator").width() );
	oMenuL1.css("width", oMenuL1.width()+$("#main_menu_L1 .margin div.separator").width());
	oMenuL2 = $("#main_menu_L2 .margin");
	oMenuL2.css("margin-left", i_left-10);

	//$("#mid").css("height", $("body").height()-100-227);
	$("#container").css("height", $("#mid").height()-130);
	$("#mid #dog").css("top", $("#mid").height()+188-314);

	init_L2_menu();
});

function init_L2_menu()
{
	try {
        var ddmx = new DropDownMenuX('menu1');
        ddmx.delay.show = 0;
        ddmx.delay.hide = 400;
        ddmx.position.levelX.left = 2;
        ddmx.init();
	} catch(e){}

}
