﻿(function (a) {
    var b = null;
    a.fn.hideAway = function () {
        return this.each(function () {
            new a.hideAway(this);
        })
    };
    a.hideAway = function (a) {
        this.menuBar = $(a).children(".control");
        this.menuPanel = $(a).children("#menu");
        this.init()
    };
    a.hideAway.fn = a.hideAway.prototype = {
        hideAway: "0.0.1"
    };
    a.hideAway.fn.extend = a.hideAway.extend = a.extend;
    a.hideAway.fn.extend({
        init: function () {
            this.enabled = null;
            _self = this;
            $(window).resize(function () {
                _self.resize()
            });
            var a = this.menuPanel;
            var b = this.menuBar;
            this.menuBar.contents().wrap('<a href="javascript:">').parent().append("<span>-</span>");
            this.menuBar.closeMenu = function () {
                this.opened = false;
                this.children("a").children("span").text("+");
                a.slideUp()
            };
            this.menuBar.openMenu = function () {
                this.opened = true;
                this.children("a").children("span").text("-");
                a.slideDown()
            };
            this.menuBar.children("a").click(function () {
                if (b.opened) {
                    b.closeMenu()
                } else {
                    b.openMenu()
                }
            });
            _self.resize()
        },
        resize: function () {
            if (matchMedia("only screen and (max-width: 480px)").matches) {
                if (this.enabled != true) {
                    this.enable()
                }
            } else {
                if (this.enabled != false) {
                    this.disable()
                }
            }
        },
        disable: function () {
            this.enabled = false;
            this.menuBar.hide();
            this.menuBar.openMenu()
        },
        enable: function () {
            this.enabled = true;
            this.menuBar.show();
            this.menuBar.closeMenu()
        }
    })
})(jQuery)
