/* $Id: main.js,v 1.11 2011-09-22 17:01:45 tolsson Exp $
 */

var menuitems;

function init_menus() {
  menuitems = $(".menuitems");
  resize();
  $(window).resize(resize);
  $(".menu").each(function(ix) {
    var item = menuitems.eq(ix);
    if (!item.is(".empty")) {
      var height = item.outerHeight();
      item.height("1px");
      item.add(this).hover(
        function(e) {
          item.show().hoverFlow(e.type, { height: height + "px" }, 200);
        },
        function(e) {
          item.delay(200).hoverFlow(e.type, { height: "1px" }, 400, function() {
            item.hide();
          });
        }
      );
    }
  });
}

function resize() {
  $(".menu").each(function(ix) {
    var item = menuitems.eq(ix);
    var width = $(this).outerWidth();
    if (item.outerWidth() < width) {
      item.width(width);
    }
  });
}

$(function() {
  init_menus();
  $("input.edit_mode").click(function() {
    $("body").css("cursor", "wait");
    this.form.submit();
  });
  $(":disabled").addClass("shaded");
  // IE kludges
  if (!jQuery.support.boxModel) {
    // IE has no support for min-width
    $(".button").each(function () {
      if ($(this).outerWidth() < 100) {
        $(this).width(100);
      }
    });
    // IE uses the wrong containing block
    $("div.nav input.back").each(function() {
      var pos = $(this).position();
      $(this).css("left", -pos['left'] + "px");
    });
    // IE change event doesn't work properly
    $("input[type=checkbox]").click(function() {
      this.blur();
      this.focus();
    });
  }
});

