/*--------------------------------------------------------------
# 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
---------------------------------------------------------------*/

//Set Module's Height script

function JMsetModulesHeight() {
	var regexp = new RegExp("_mod([0-9]+)$");

	var jmmodules = jQuery(document).find('.jm-module') || [];
	if (jmmodules.length) {
		jmmodules.each(function(index,element){
			var match = regexp.exec(element.className) || [];
			if (match.length > 1) {
				var modHeight = parseInt(match[1]);
				jQuery(element).find('.jm-module-in').css('height', modHeight + 'px');
			}
		});
	}
}

//header height
var JMheaderTimer;
function JMcheckheight() {
	var headerbg = jQuery('#jm-header-bg');
	var headercontent = jQuery('#jm-header-content');
	
  if (headerbg.length && headercontent.length) {
		var offsetHeaderBg = headerbg.outerHeight();
		var offsetContent = headercontent.outerHeight();
		var screenWidth = jQuery(window).width();
		if(offsetHeaderBg > offsetContent) {
			headercontent.removeClass('pstatic');
		} else if(offsetHeaderBg < offsetContent) {
			headercontent.addClass('pstatic');
			headerbg.removeAttr('style');
		} else {
			headercontent.removeClass('pstatic');
			headerbg.css('min-height', (offsetContent) + 'px');
		}
	}
};

//menu colorline
function JMcheckColorLine() {
	var bar = jQuery('#jm-logo-nav').next('#jm-colorful-line');
	var sticky = jQuery('body').hasClass('sticky-bar');
	if(bar.length && !sticky) {
		jQuery('body').addClass('bar-color');
	}
}

jQuery(document).ready(function(){
	JMsetModulesHeight();
	JMcheckColorLine();
});

jQuery(window).load(function() {
	clearTimeout(JMheaderTimer);
  JMheaderTimer = setTimeout(JMcheckheight, 10);
	jQuery(window).resize(function() {
		clearTimeout(JMheaderTimer);
		JMheaderTimer = setTimeout(JMcheckheight, 50);
	});
});


