﻿(function() {

    jQuery.fn.FloatMenu = function(options) {
        jQuery.extend(this, FloatMenu);
        this._init(jQuery(this), options);
        return this;
    }

    var FloatMenu = {

        options: {
            isTinyMCE: false
        },

        speed: 500,
        delay: 500,
        isPanel: false,
		opened : null,

        _init: function(selector, options) {

            var _self = this;
            this.container = selector;
            this.element = this.container;

            jQuery.extend(this.options, options);

            if (!this.container.size()) {
                return false;
            }

 			this.container.find('a').each(function(index,a){								 
				a  = jQuery(a);
				if(a.hasClass('hover')){
					a.submenu = jQuery(a.attr('submenu'));
					a.hoverIntent({
						sensitivity: 7, 
						interval: 100, 
						over: function() { _self.showMenu(a); }, 
						timeout: 500,
						out: function() { }
					});
				}else{
					a.hoverIntent({
						sensitivity: 7, 
						interval: 100, 
						over: function() { _self.hideMenu(_self.opened);_self.opened = null; }, 
						timeout: 500,
						out: function() { }
					});
				}
				a.animated = false;
				_self.setStatus(a);
			})
            
            

        },

        setStatus: function(a) {
            if (a.attr('status')) {
                if (a.attr('status') == 'open')
                    a.attr('status', 'close');
                else{
                    a.attr('status', 'open');
					this.opened = a;
				}
            } else {
                a.attr('status', 'close');
            }
        },

        showMenu: function(a) {
            if (a.attr('status') == 'close' && a.animated == false) {
				if(this.opened != null)
					this.toggleMenu(this.opened);
				this.toggleMenu(a);
            }
        },

        hideMenu: function(a) {
            if (a != null && a.attr('status') == 'open' && a.animated == false) {
                this.toggleMenu(a);
            }
        },

        toggleMenu: function(a) {
            var _self = this;
            var options = {};
            var speed = this.speed;
            a.animated = true;
            a.submenu.slideToggle(function() { a.animated = false; _self.setStatus(a); });
        },

        emptyFunction: function() {
            alert("it is a new instance");
        }
    };

})(jQuery);

