/* Script on ready
---------------------------------*/	
$(document).ready(function(){

    /* sticky footer function */
    StickyFooter()

    /* mobile navigation */ 

    $('.menu-trigger').click(function(){
        $(this).stop().toggleClass('open')
        $('body, html').stop().toggleClass('scroll-hidden');
        $('.navbar').stop().toggleClass('open');
    })    

    if($('#mobile-menu ul ul').length > 0){   
        $('#mobile-menu ul ul ').before('<em class="submenu-caret"></em>')
    }

    $('.submenu-caret').click(function(){
        $(this).next().slideToggle();
        $(this).toggleClass('toggled');
        $(this).parent().siblings().find('ul').slideUp()
        $(this).parent().siblings().find('em').removeClass('toggled')
    })

 $(".search-bar").click(function () {
			$(".search-bar").toggleClass('active');
			$(".search-in").animate({
				height: "toggle",
				opacity: "toggle"
			}, "slow");
		});

});

/* Script on scroll
---------------------------------*/
$(window).scroll(function() {

});

/* Script on resize
---------------------------------*/
$(window).resize(function() {

    /* sticky footer function */
    StickyFooter()
});

/* Script on load
----------------------------------*/
$(window).on('load', function() {

    /* sticky footer function */
    StickyFooter()
});

/* Script all functions
----------------------------------*/

/* sticky footer function */
function StickyFooter(){
    var Stickyfooter = $('footer').outerHeight()
    $('#wrapper').css('margin-bottom',-Stickyfooter)
    $('#wrapper').css('padding-bottom',Stickyfooter)
}

/* equalheight */
equalheight = function(container){

    var currentTallest = 0,
        currentRowStart = 0,
        rowDivs = new Array(),
        $el,
        topPosition = 0;
    $(container).each(function() {

        $el = $(this);
        $($el).height('auto')
        topPostion = $el.position().top;

        if (currentRowStart != topPostion) {
            for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
                rowDivs[currentDiv].height(currentTallest);
            }
            rowDivs.length = 0; // empty the array
            currentRowStart = topPostion;
            currentTallest = $el.height();
            rowDivs.push($el);
        } else {
            rowDivs.push($el);
            currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
        }
        for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
            rowDivs[currentDiv].height(currentTallest);
        }
    });
}

$(window).on('load', function() {
    equalheight('.quality-assurance .equal-hei');
	 equalheight('.blog-sec .col-4 .post-thumbnail');
	
});


$(window).resize(function(){
    equalheight('.quality-assurance .equal-hei');
	 equalheight('.blog-sec .col-4 .post-thumbnail');
});



/*********************************************************/


$(document).ready(function(){
	
$('.product-right ul#menu-main-menu > li:has(ul)').addClass("has-sub"); 
	$('.product-right ul#menu-main-menu > li ul li:has(ul)').removeClass('has-sub').addClass("has-sub-child");
	$('.product-right ul#menu-main-menu > li ul > li ul li:has(ul)').removeClass('has-sub-child').addClass("has-sub-sub-child");
	
	$('.product-right ul#menu-main-menu > li.has-sub > a').after("<div class='puls'></div>");
	$('.product-right ul#menu-main-menu > li ul li.has-sub-child > a').after("<div class='puls1'></div>");
	$('.product-right ul#menu-main-menu > li ul > li ul li.has-sub-sub-child > a').after("<div class='puls2'></div>");
	
	$('.product-right ul#menu-main-menu > li > .puls').click(function() {
		var checkElement = $(this).next();
	
	$('.product-right  li').removeClass('active-1');
	$(this).closest('li').addClass('active-1');    
	
	
	if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		$(this).closest('li').removeClass('active-1');
		checkElement.slideUp('normal');
	}
	
	if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		$('.product-right  ul ul:visible').slideUp('normal');
		checkElement.slideDown('normal');
	}
	
		if (checkElement.is('ul')) {
			return false;
		} else {
			return true;    
		}        
	});
	
	//second level
	$('.product-right ul#menu-main-menu li.has-sub-child > .puls1').click(function() {
		var checkElement = $(this).next();
	
	$('.product-right ul#menu-main-menu li.has-sub-child').removeClass('active');
	$(this).closest('li').addClass('active-2');    
	
	
	if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		$(this).closest('li').removeClass('active-2');
		checkElement.slideUp('normal');
	}
	
	if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		$('.product-right ul#menu-main-menu li.has-sub-child ul:visible').slideUp('normal');
		checkElement.slideDown('normal');
	}
	
		if (checkElement.is('ul')) {
			return false;
		} else {
			return true;    
		}        
	});
	
	//three level
	$('.product-right ul#menu-main-menu li.has-sub-sub-child > .puls2').click(function() {
		var checkElement = $(this).next();
	
	$('.product-right ul#menu-main-menu li.has-sub-sub-child').removeClass('active');
	$(this).closest('li').addClass('active-3');    
	
	
	if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
		$(this).closest('li').removeClass('active-3');
		checkElement.slideUp('normal');
	}
	
	if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
		$('.product-right ul#menu-main-menu li.has-sub-sub-child ul:visible').slideUp('normal');
		checkElement.slideDown('normal');
	}
	
		if (checkElement.is('ul')) {
			return false;
		} else {
			return true;    
		}        
	});
	
});







