if ( typeof Fractal === 'undefined' ) throw "Fractal core.js not loaded";

Fractal.Page = (function($){

    var Page = function( el ){
        this.el = el;
        this.navToggle = this.el.find('.fr-header-navButton');
        this.content = this.el.find('.fr-content');
        var navIsOpen = false;
    };

    Page.prototype = {

        init: function(){
            var self = this;
            this.navToggle.on('click', function(){
                if (self.navIsOpen) {
                    self.closeNav();
                } else {
                    self.openNav();
                }
                return false;
            });
            this.content.on('click', function(){
                if (self.navIsOpen && window.matchMedia('(max-width: 40em)').matches) {
                    self.closeNav();
                    return false;
                }
            });
        },

        openNav: function(){
            this.el.addClass("show-nav");
            this.navIsOpen = true;
            this.navToggle.removeClass('is-inactive').addClass('is-active');
        },

        closeNav: function(){
            this.el.removeClass("show-nav");
            this.navIsOpen = false;
            this.navToggle.removeClass('is-active').addClass('is-inactive');
        }

    };

    return Page;

})(jQuery, window);
