/*
 * Simple Menu based on jMenu by Sawanna
 *
 * modified by Christian Fillies to use Child DIVs instead of Child ULs
 * also it adds the class "hover" to the currently rolled-over a tag in a menu, leaving the parent <a> with the class "hover" as a menu is open
 * and modified to work with j() instead of $()
 *
 * Example:
 *
 * j(document).ready(function() {
 *   j('#jmenu').jmenu({animation:'fade',duration:100});
 * });
 *
 * Original jMenu (c) 2010 Sawanna Team (http://sawanna.org)
 *
 */

var jmenu={
    effect: 'fade',        /* default animation effect */
    duration: 400,         /* default duration */
    set: function (settings)
    {
       try
        {
            if (settings.animation == 'show') { this.effect='show'; }
            if (settings.animation == 'slide') { this.effect='slide'; }
            if (settings.animation == 'fade') { this.effect='fade'; }
        } catch (e) {}
        
        try
        {
            this.duration=settings.duration;
        } catch (e) {} 
      },
	  
//
// * Removed the offset - we should do this thru css for 1 level navigations
//
//    fix_pos:function(elem)
//    {
//        if (j(elem).parent('ul').parent('li').length)
//        {
//            j(elem).children('div').eq(0).css({marginTop:-j(elem).height(),marginLeft:j(elem).width()});
//        } else
//        {
//            j(elem).children('div').eq(0).css({'top':j(elem).offset().top+j(elem).height(),'left':j(elem).offset().left});
//        }
//    },
//
//
    show:function(elem)
    {
        if (this.effect=='fade') { j(elem).children('div').eq(0).stop(1,1).fadeIn(this.duration); }
        else if (this.effect=='slide') {j(elem).children('div').eq(0).stop(1,1).slideDown(this.duration); }
        else if (this.effect=='show') { j(elem).children('div').eq(0).stop(1,1).show(this.duration); }
    },
    hide: function(elem)
    {
        j(elem).children('div').eq(0).stop(1,1).fadeOut(100);
    }
}

jQuery.fn.jmenu=function(settings)
{
    jmenu.set(settings);
    
    j(this).find('li').each(function()
    {
            j(this).hover(
                function()
                {
					j(this).children('a').addClass('hover');
                    // jmenu.fix_pos(this);
                    jmenu.show(this);
                },
                function()
                {
					j(this).children('a').removeClass('hover');
                    jmenu.hide(this);
                }
            );
    });
}
