(function() {
  var add_toggle, detect_screen, is_mobile, is_mobile_width, is_page_highlights, is_tiny, is_tiny_width, needs_update, on_resize, set_mobile_off, set_mobile_on, set_tiny_off, set_tiny_on;
  is_mobile = null;
  is_tiny = null;
  set_mobile_on = function() {
    is_mobile = true;
    $(".legend .infos").stop().hide();
    $(".toggle").stop().show();
    return $("body").addClass("mobile");
  };
  set_mobile_off = function() {
    is_mobile = false;
    $(".legend .infos").stop().show();
    $(".toggle").stop().hide();
    return $("body").removeClass("mobile");
  };
  set_tiny_on = function() {
    is_tiny = true;
    if (is_page_highlights() === false) {
      return $("#informations").after($("#menu"));
    }
  };
  set_tiny_off = function() {
    is_tiny = false;
    if (is_page_highlights() === false) {
      return $("#main_content").prepend($("#menu"));
    }
  };
  is_mobile_width = function() {
    return $("#header").css("clear") === "both";
  };
  is_tiny_width = function() {
    return $("#header").css("clear") === "left";
  };
  needs_update = function() {
    var update_mobile, update_tiny;
    update_mobile = is_mobile_width() === true && is_mobile === false || is_mobile_width() === false && is_mobile === true;
    update_tiny = is_tiny_width() === true && is_tiny === false || is_tiny_width() === false && is_tiny === true;
    return update_mobile || update_tiny;
  };
  detect_screen = function() {
    if (is_mobile_width()) {
      set_mobile_on();
      return set_tiny_off();
    } else if (is_tiny_width()) {
      set_mobile_on();
      return set_tiny_on();
    } else {
      set_mobile_off();
      return set_tiny_off();
    }
  };
  on_resize = function() {
    if (needs_update()) {
      return detect_screen();
    }
  };
  is_page_highlights = function() {
    return $(".highlights").size() > 0;
  };
  add_toggle = function() {
    $(".legend .links").append("<a class='ext toggle' href='#'>description</a>");
    return $(".toggle").click(function(event) {
      event.preventDefault();
      return $(".infos", $(this).parent().parent()).stop().slideToggle();
    });
  };
  $(document).ready(function() {
    if (is_page_highlights()) {
      add_toggle();
    }
    detect_screen();
    return $(window).resize(function() {
      return on_resize();
    });
  });
}).call(this);

