/*--------------------------------------------------------------
# Copyright (C) joomla-monster.com
# License: http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
# Website: http://www.joomla-monster.com
# Support: info@joomla-monster.com
---------------------------------------------------------------*/

//jQuery Off-Canvas

var scrollsize;

jQuery(function() {
    // Toggle Nav on Click
    jQuery('.toggle-nav').click(function() {
    	// Get scroll size on offcanvas open
    	if(!jQuery('body').hasClass('off-canvas')) scrollsize = jQuery(window).scrollTop();
        // Calling a function
        toggleNav();
    });
});

function toggleNav() {
	var y = jQuery(window).scrollTop();
    if (jQuery('body').hasClass('off-canvas')) {
        // Do things on Nav Close
        jQuery('body').removeClass('off-canvas');
        setTimeout(function() {
					//megamenu
					jQuery('.dj-megamenu-sticky').removeAttr('style');
	        jQuery('.sticky-bar #jm-logo-nav').removeAttr('style');
					//sticky-bar
	        jQuery('html').removeClass('no-scroll').removeAttr('style');
	        jQuery(window).scrollTop(scrollsize);
        }, 300);
    } else {
        // Do things on Nav Open
        jQuery('body').addClass('off-canvas');
				//megamenu
				jQuery('.dj-megamenu-sticky').css({'position':'absolute', 'top':y});
				//sticky-bar
				if (jQuery('body').hasClass('sticky-bar') && (jQuery('body').hasClass('make-sticky-top'))) {
					jQuery('.sticky-bar #jm-logo-nav').css({'position':'absolute', 'top':y});
        }
				if (jQuery('body').hasClass('sticky-bar') && (jQuery('body').hasClass('make-sticky-bottom'))) {
					var barBottom = jQuery('.sticky-bar #jm-logo-nav').offset();
					jQuery('.sticky-bar #jm-logo-nav').css({'position':'absolute', 'top':barBottom.top});
				}
				
				setTimeout(function() {
					jQuery('html').addClass('no-scroll').css('top',-y);
        }, 300);
    }
}
