/*
 * Menu v0.1.2 - jQuery menu widget
 * Copyright (c) 2008 Tamás Paksa
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

;(function($){

  $.fn.menu_horizontal = function(options){
    $(this).addClass('menu_horizontal');
    return $(this).each(function(){
      var $$ = $(this);
      var menuitem = false;
      var o = $.extend({},$.fn.menu_horizontal.defaults,options);
      $("li>a", this).mouseover(function(){
        if (o.onTitleID != '')
            $('#'+o.onTitleID).text($(this).attr('title') + " ");
      });
      $("li", this).mouseover(function(){
        menuitem = $(this);
        $(this).nextAll("li").find("ul").animate(o.hideAnimation,o.speed);
        $(this).prevAll("li").find("ul").animate(o.hideAnimation,o.speed);
        if ($(this).closest('ul').html() != $$.html()) { //ha nem a gyökér elemről van szó
          $(this).children("ul").css('top', $(this).attr('offsetTop'));
          $(this).children("ul").css('left', $(this).attr('offsetLeft') + $(this).attr('offsetWidth'));
        } else {
          if (o.setWidth) {
            $(this).children("ul").width($(this).width());
          }
        }
        if ($(this).children("ul").is(":hidden")) {
          $(this).children("ul").animate(o.showAnimation,o.speed);
        }
      });
      $("li", this).mouseout(function(){
        var _this = $(this);
        clearTimeout($$.sfTimer);
        menuitem = true;
        $$.sfTimer = setTimeout(function(){
          if (menuitem === true) {
            $('ul', $$).animate(o.hideAnimation,o.speed);
          } else {
          }
        },o.delay);  
      });
      $("li:has(ul)>a", this).append(document.createTextNode(o.appendText));
      $("li:has(ul)", this).children("ul").hide();
      $("", this).append('<li class="clear" />');
      $("li:has(.active)", this).addClass('active');
    });
  };

  $.fn.menu_horizontal.defaults = {
    delay        : 500,
    appendText   : '...',
    showAnimation: {opacity: 'show'},
    hideAnimation: {opacity: 'hide'},
    speed        : 'fast',
    setWidth     : false,
    onTitleID    : '',
    onInit       : function(){}, // callback functions
    onBeforeShow : function(){},
    onShow       : function(){},
    onHide       : function(){}
  };

})(jQuery);

