/* Authentidate main JavaScripts
 *
 */
// $(document).ready will be fired, when the DOM is ready to manipulate, dimensions may not be available at this time
$(document).ready(function(){
  $('#mainMenu>li>ul').hide(); // needed to prevent CSS-only behaviour on first contact
  
  var menuDelay; // we need to initialize the menuDelay variable
  $('#mainMenu>li:has(ul)').hover(
    function() {
      $(this).siblings().children('ul').stop(true).hide(); // hide all other submenus
     // $(this).children('li').hover(
     //   function() {
     //      $(this).addClass('hover');
     //   }
     // );
      clearTimeout(menuDelay); // clear the menu timeout
      if($(this).children('ul').css('display') == 'none'){ // animate the menu only, when it isn't visible
        $(this).children('ul').slideDown(250);
      }
    },
    function() {
      $(this).children('ul').stop(true, true).height('auto'); // the height('auto') prevents the menu from memorizing an incorrect height-value forever when leaving the menu while the animation is running
      menuDelay = setTimeout(function(){$('#mainMenu>li>ul').hide();}, 250); // the menu timeout
    }
  );
  
  // insert target="_blank" for external Links and PDFs
  $('a[href^="http://"]:not([href*="authentidate.de"]):not([href*="authentidate.local"])').attr({target: "_blank"});
  $('a[href$=".pdf"]').attr({target: "_blank"});
});