/**
 * Subcategories menu
 * @requires jquery.js
 */

function menu() {

  this.locked = true;
  this.timeout;

  this.lock = function() {
    menu.locked = true;
    window.clearTimeout(menu.timeout);
  };

  this.unlock = function() {
    menu.locked = false;
    window.clearTimeout(menu.timeout);
  };

  this.show_delayed = function(link) {
    this.unlock();
    this.timeout = window.setTimeout(function() { menu.show(link); }, 250);
  };

  this.show = function(link) {
    if (!this.locked) {
      window.clearTimeout(this.timeout);
      $('#menu p').hide();
      this.locked = true;
      var i = $(link).eq(0).attr('id').substr(1);
      $('#s' + i).show().css('opacity', '0.75');
    }
  };

  this.hide = function() {
    window.clearTimeout(this.timeout);
    $('#menu p').hide();
    this.locked = true;
  };

}

var menu = new menu();

$(document).ready(function() {

  $('#menu h3 a').bind('mouseenter', function() { menu.show_delayed(this); });
  $('#menu h3 a').bind('mouseleave', menu.lock);
  $('#content div').bind('mousemove', menu.lock);
  $('#top, #main_window, #menu_left, #menu_right').bind('mouseenter', menu.hide);
  $('#menu p').bind('mouseleave', menu.hide);

});