/* SPARKY DYNAMICALLY GENERATED JAVASCRIPT - DO NOT EDIT THIS FILE!
YOUR CHANGES WILL BE OVERWRITTEN AFTER NEXT SAVE OF TEMPLATE PARAMETERS!
You can add your custom JavaScript code in template options, under Custom tab or
you can edit file custom.js to add your JavaScript code. */

// Drop-down menu

function isAppleDevice(){
    return (
        (navigator.userAgent.toLowerCase().indexOf("ipad") > -1) ||
        (navigator.userAgent.toLowerCase().indexOf("iphone") > -1) ||
        (navigator.userAgent.toLowerCase().indexOf("ipod") > -1)
    );
}

(function(jQuery){  
    jQuery.fn.dropDownMenu_mainmenu = function(options) {  
  
        var defaults = {  
            speed: 300,  
            effect: "fadeToggle"
        };  
        var options = jQuery.extend(defaults, options);  
      
        return this.each(function() {

            var screenWidth = jQuery("body").width();

            jQuery(".mnu_mainmenu ul").hide();
            jQuery(".mnu_mainmenu li ul li").filter(":last-child").css("border-bottom", "none");

            if(screenWidth > 991) {

                jQuery(".mnu_mainmenu li").hover(function(){
                    jQuery(this).children("ul").stop()[options.effect](options.speed);
                },function(){
                    jQuery(this).css("position","relative").children("ul").stop()[options.effect](options.speed);
                });

            } else {
                                        
                jQuery("nav ul.navv_sparky").find("li > ul").prev().addClass("firstClick");        

                jQuery(document).on("click",".mnu_mainmenu a", function(){
                    if(!jQuery(this).hasClass("firstClick"))
                        jQuery(this).addClass("firstClick");
                    
                    return true;
                });
                
                jQuery(document).on("click",".mnu_mainmenu .firstClick",function(e){    
                    if((jQuery("html.no-touchevents").length == 1 && screenWidth > 992) || (isAppleDevice() && screenWidth > 992)){
                        return true;
                    }
                    e.preventDefault(); 

                    var href = jQuery(this).attr("href");
                    var target = jQuery(this).attr("target");
                    var link = jQuery(this);
                    jQuery(this).attr("href","#");
                    jQuery(this).attr("target","");
                    
                    jQuery(this).removeClass("firstClick");
                    
                    setTimeout(function(){
                        link.attr("href",href);
                        link.attr("target",target);
                    },200);
                    if(screenWidth > 992){
                        jQuery(this).children("ul").stop()[options.effect](options.speed);
                    }           
                    else
                        jQuery(this).parent().find("ul:first:not(:visible)").stop(true,true)[options.effect](options.speed);
                });

            }
            
            jQuery(window).resize(function(){
                var screenWidth = jQuery("body").width();
                if(screenWidth > 992)
                    jQuery("nav ul.navv_sparky").find("li > ul").prev().removeClass("firstClick");
                else
                    jQuery("nav ul.navv_sparky").find("li > ul").prev().addClass("firstClick");
            });
            
        });  
    };  
})(jQuery);

jQuery(document).ready(function(){
    jQuery(".mnu_mainmenu").dropDownMenu_mainmenu({
        speed: 0,
        effect: "toggle"
    });
    
    //hover menu fix    
    setTimeout(function(){
        jQuery("#blocker").remove();
        jQuery("nav ul.navv_sparky").find("li > ul").prev().addClass("firstClick");
    }, 1000)
    
});
