﻿//no conflict jquery
jQuery.noConflict();

// -- Navigation JQuery Extensions --
(function ($) {
    // The jQuery.matchcentreui namespace will automatically be created if it doesn't exist
    $.widget("matchcentreui.navigation", {
        // These options will be used as defaults
        options: {
            duration: 'fast',
            animation: // Animation and display parameters for displaying next tier.
                [
                    { slide: 'vertical' }, // Second Tier from First Tier
                    {slide: 'horisontal' }, // Third Tier from Second Tier
                    {slide: 'horisontal'} // Fourth to Nth Tier from third to (N-1)th Tier.
                ],
            overridecss: true,
            slideopen: 200,
            slideclose: 50,
            hoverintent: 100
        },
        _create: function () {
            // The _create method is where you set up the widget
            var element = this.element[0];
        },
        _init: function () {
            // The _init method is where you initialise or re-initialise the widget
            var widget = this;
            var element = this.element[0];

            // Set default positioning.
            $(element).addClass('mc-ui-posrel');
            $(element).css('position', 'relative');

            // Hide 2nd to nth tier menus
            $('> ul > li ul', element).hide();

            // Show Selected Sub Menu
            $('> ul li', element).hover(
                function () {
                    var hoverTarget = this;
                    $(hoverTarget).addClass('ui-state-hover');

                    // Get tier index.
                    var tierIdx = $(hoverTarget).parents('li.ui-state-hover', element).length;

                    // Get display and animation parameters.
                    var animation = widget.options.animation[Math.min(tierIdx, widget.options.animation.length)];
                    var slide = animation.slide;
                    var position = animation.position;

                    // Set the position of the target and Sub Menu
                    if (widget.options.overridecss) {
                        if (position != undefined)
                            $(hoverTarget).css({ position: position });

                        if ('horisontal' == slide) {
                            $('> ul', hoverTarget).css({ position: 'absolute', top: '0px', left: '100%' });
                        }
                        else if ('vertical' == slide) {
                            $('> ul', hoverTarget).css({ position: 'absolute', top: '100%', right: '0px' });
                        }
                    }

                    // Trigger animation
                    setTimeout(function () {
                        if (!$(hoverTarget).hasClass('ui-state-hover'))
                            return;

                        // Hide the nth tier menus
                        $('> ul > li ul', hoverTarget).hide();
                        if ('horisontal' == slide) {
                            $('> ul', hoverTarget).show(widget.options.slideopen);
                        }
                        else if ('vertical' == slide) {
                            $('> ul', hoverTarget).slideDown(widget.options.slideopen);
                        }
                    }, widget.options.hoverintent);
                },
                function () {
                    var hoverTarget = this;
                    $(hoverTarget).removeClass('ui-state-hover');

                    // Get tier index.
                    var tierIdx = $(hoverTarget).parents('li.ui-state-hover', element).length;

                    // Get display and animation parameters.
                    var animation = widget.options.animation[Math.min(tierIdx, widget.options.animation.length)];
                    var slide = animation.slide;

                    // Trigger animation
                    if ('horisontal' == slide) {
                        $('> ul', hoverTarget).hide(widget.options.slideclose);
                    }
                    else if ('vertical' == slide) {
                        $('> ul', hoverTarget).slideUp(widget.options.slideclose);
                    }
                }
            );
        },
        _setOption: function (key, value) {
            // Use the _setOption method to respond to changes to options
            $.Widget.prototype._setOption.apply(this, arguments)
        },
        destroy: function () {
            // Use the destroy method to reverse everything your plugin has applied
            $.Widget.prototype.destroy.call(this);
            // do something
        }
    });
})(jQuery);



