/*! slidereveal - v1.1.1 - 2016-03-04
* https://github.com/nnattawat/slidereveal
* Copyright (c) 2016 Nattawat Nonsung; Licensed MIT */
(function (jQuery) {
  // Private attributes and method
  var getPadding = function(jQueryel, side) {
    var padding = jQueryel.css('padding-' + side);
    return padding ? +padding.substring(0, padding.length - 2) : 0;
  };

  var sidePosition = function(jQueryel) {
    var paddingLeft = getPadding(jQueryel, 'left');
    var paddingRight = getPadding(jQueryel, 'right');
    return (jQueryel.width() + paddingLeft + paddingRight) + "px";
  };

  var SlideReveal = function(jQueryel, options) {
    // Define default setting
    var setting = {
      width: 250,
      push: true,
      position: "left",
      speed: 300, //ms
      trigger: undefined,
      autoEscape: true,
      show: function(){},
      shown: function(){},
      hidden: function(){},
      hide: function(){},
      top: 0,
      overlay: false,
      "zIndex": 1049,
      overlayColor: 'rgba(255,255,255,.4)'
    };

    // Attributes
    this.setting = jQuery.extend(setting, options);
    this.element = jQueryel;

    this.init();
  };

  // Public methods
  jQuery.extend(SlideReveal.prototype, {
    init: function() {
      var self = this;
      var setting = this.setting;
      var jQueryel = this.element;

      var transition = "all ease " + setting.speed + "ms";
      jQueryel.css({
        position: "fixed",
        width: setting.width,
        transition: transition,
        height: "100%",
        top: setting.top
      })
      .css(setting.position, "-" + sidePosition(jQueryel));

      if (setting.overlay) {
        jQueryel.css('z-index', setting.zIndex);

        self.overlayElement = jQuery("<div class='slide-reveal-overlay'></div>")
        .hide()
        .css({
          position: 'fixed',
          top: 0,
          left: 0,
          height: '100%',
          width: '100%',
          'z-index': setting.zIndex - 1,
          'background-color': setting.overlayColor,
        }).click(function() {
          self.hide();
        });

        jQuery("body").prepend(self.overlayElement);
      }

      // Add close stage
      jQueryel.data("slide-reveal", false);

      if (setting.push){
        jQuery("body").css({
          position: "relative",
          "overflow-x": "hidden",
          transition: transition,
          left: "0px"
        });
      }

      // Attach trigger using click event
      if (setting.trigger && setting.trigger.length > 0) {
        setting.trigger.on('click.slideReveal', function() {
          if (!jQueryel.data("slide-reveal")) { // Show
            self.show();
          } else { // Hide
            self.hide();
          }
        });
      }

      // Bind hide event to ESC
      if (setting.autoEscape) {
        jQuery(document).on('keydown.slideReveal', function(e) {
          if (jQuery('input:focus, textarea:focus').length === 0) {
            if (e.keyCode === 27 && jQueryel.data("slide-reveal")) { // ESC
              self.hide();
            }
          }
        });
      }
    },

    show: function(triggerEvents) {
      var setting = this.setting;
      var jQueryel = this.element;
      var jQueryoverlayElement = this.overlayElement;

      // trigger show() method
      if (triggerEvents === undefined || triggerEvents) { setting.show(jQueryel); }

      // show overlay
      if (setting.overlay) {
        jQueryoverlayElement.show();
      }

      // slide the panel
      jQueryel.css(setting.position, "0px");
      if (setting.push) {
        if (setting.position === "left") {
          jQuery("body").css("left", sidePosition(jQueryel));
        } else {
          jQuery("body").css("left", "-" + sidePosition(jQueryel));
        }
      }
      jQueryel.data("slide-reveal", true);

      // trigger shown() method
      if (triggerEvents === undefined || triggerEvents) {
        setTimeout(function() {
          setting.shown(jQueryel);
        }, setting.speed);
      }
    },

    hide: function(triggerEvents) {
      var setting = this.setting;
      var jQueryel = this.element;
      var jQueryoverlayElement = this.overlayElement;

      // trigger hide() method
      if (triggerEvents === undefined || triggerEvents) { setting.hide(jQueryel); }

      // hide the panel
      if (setting.push) {
        jQuery("body").css("left", "0px");
      }
      jQueryel.css(setting.position, "-" + sidePosition(jQueryel));
      jQueryel.data("slide-reveal", false);

      // trigger hidden() method
      if (triggerEvents === undefined || triggerEvents) {
        setTimeout(function(){
          // hide overlay
          if (setting.overlay) {
            jQueryoverlayElement.hide();
          }

          setting.hidden(jQueryel);
        }, setting.speed);
      }
    },

    toggle: function(triggerEvents) {
      var jQueryel = this.element;
      if (jQueryel.data('slide-reveal')) {
        this.hide(triggerEvents);
      } else {
        this.show(triggerEvents);
      }
    },

    remove: function() {
      this.element.removeData('slide-reveal-model');
      if (this.setting.trigger && this.setting.trigger.length > 0) {
        this.setting.trigger.off('.slideReveal');
      }
      if (this.overlayElement && this.overlayElement.length > 0) {
        this.overlayElement.remove();
      }
    }

  });

  // jQuery collection methods
  jQuery.fn.slideReveal = function (options, triggerEvents) {
    if (options !== undefined && typeof(options) === "string") {
      this.each(function() {
        var slideReveal = jQuery(this).data('slide-reveal-model');

        if (options === "show") {
          slideReveal.show(triggerEvents);
        } else if (options === "hide") {
          slideReveal.hide(triggerEvents);
        } else if (options === 'toggle') {
          slideReveal.toggle(triggerEvents);
        }
      });
    } else {
      this.each(function() {
        if (jQuery(this).data('slide-reveal-model')) {
          jQuery(this).data('slide-reveal-model').remove();
        }
        jQuery(this).data('slide-reveal-model', new SlideReveal(jQuery(this), options));
      });
    }

    return this;
  };

}(jQuery));
jQuery(window).load(function() {
jQuery("#slider").slideReveal({
  trigger: jQuery("#trigger"),
  position: "right",
  width: 350,
  push: false,
  overlay: true
});
jQuery('#slider, #headerbg, .menusection').css({'display':'block'});
});