﻿// Superfish plugin handles main navigation hover intent functionality as well as fade transitions and custom animation.
// The plugin adds CSS classes, mouseover and mouseout events to existing suckerfish menus fade transitions are removed from IE6-IE8 and replaced with slides for transparent shadow PNG support
(function ($) {
    $.fn.superfish = function (op) {
        // Superfish initialization and methods
        var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="', c.arrowClass, '"> &#187;</span>'].join('')),
			over = function () {
			    var $$ = $(this), menu = getMenu($$);
			    clearTimeout(menu.sfTimer);
			    $$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function () {
			    var $$ = $(this), menu = getMenu($$), o = sf.op;
			    clearTimeout(menu.sfTimer);
			    menu.sfTimer = setTimeout(function () {
			        $$.hideSuperfishUl();
			    }, o.delay);
			},
			getMenu = function ($menu) {
			    var menu = $menu.parents(['ul.', c.menuClass, ':first'].join(''))[0];
			    sf.op = sf.o[menu.serial];
			    return menu;
			},
			addArrow = function ($a) { $a.append($arrow.clone()); };

        return this.each(function () {
            var s = this.serial = sf.o.length;
            var o = $.extend({}, sf.defaults, op);
            sf.o[s] = sf.op = o;

            // Add here state arrow to top level list items
            $('>li', this).each(function () { addArrow($('>a:first-child', this)); });
            // Enable hoverintent for top level list items with submenus
            $('>li:has(".navPanel")', this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over, out).hideSuperfishUl();

            var $a = $('a', this);
            $a.each(function (i) {
                var $li = $a.eq(i).parents('li');
                $a.eq(i).focus(function () { over.call($li); }).blur(function () { out.call($li); });
            });
            o.onInit.call(this);

        }).each(function () {
            var menuClasses = [c.menuClass];
            if (sf.op.dropShadows && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
            $(this).addClass(menuClasses.join(' '));
        });
    };
    var sf = $.fn.superfish;
    sf.o = [];
    sf.op = {};
    sf.IE7fix = function () {
        var o = sf.op;
        if ($.browser.msie && $.browser.version > 6 && $.browser.version <= 8 && o.dropShadows && o.animation.opacity != undefined)
            this.toggleClass(sf.c.shadowClass + '-off');
    };
    sf.c = {
        menuClass: 'sf-js-enabled',
        arrowClass: 'arrow',
        shadowClass: 'sf-shadow'
    };
    sf.defaults = {
        hoverClass: 'hover',
        delay: 600,
        animation: { opacity: 'show' },
        speed: 400,
        dropShadows: true,
        disableHI: false,
        onInit: function () { },
        onBeforeShow: function () { },
        onShow: function () { },
        onHide: function () { }
    };
    $.fn.extend({
        hideSuperfishUl: function () {
            var o = sf.op;
            var $ul = $(['li.', o.hoverClass].join(''), this).add(this).removeClass(o.hoverClass).find('>.navPanel').hide().css('visibility', 'hidden');
            o.onHide.call($ul);
            return this;
        },
        showSuperfishUl: function () {
            var o = sf.op,
			sh = sf.c.shadowClass + '-off',
			$ul = this.addClass(o.hoverClass).find('>.navPanel:hidden').css('visibility', 'visible');
            sf.IE7fix.call($ul);
            o.onBeforeShow.call($ul);
            $ul.animate(o.animation, o.speed, function () { sf.IE7fix.call($ul); o.onShow.call($ul); });
            return this;
        }
    });
})(jQuery);
// End of Superfish plugin.
