$(document).ready(function(){
    timeoutCounter = 500;
    initDropdown();
}); // end document ready

initDropdown = function(){
  $('div.dropdownh > ul > li, div.dropdownv > ul > li').each(function(i) {
    var timeOut;
    horizontal = $(this).parent().parents('div.dropdownh').get();

    $(this).hover(function(){
        clearTimeout(timeOut);

        // Old Shool aber funzt
//         $('.dropdownh > ul > li > ul,.dropdownv > ul > li > ul').css('display','none');
//         $('> ul',this).css('display','none');

        // Check for horizontal menu
        if (horizontal[0]){
            $(this).parent('ul').find ('> li > ul').css('display','none');
        }
        else{
//             $('> ul',this).css('display','none');
        }

        $('> ul', this).css('display','block');
        if ($.browser.msie) {
            var $this_ul = $('> ul', this);
            $this_ul.prepend("<iframe></iframe>");
            $('iframe', this).css('height',$this_ul.get(0).offsetHeight + 'px');
        };
    },function(){  // on mouseOut
        var self = this;
        timeOut = setTimeout(function() {
          $('> ul', self).css('display','none');
          if ($.browser.msie) {
            $(self).find('iframe').remove();
          };
     },timeoutCounter);
   });
 });

  $('div.dropdownh > ul > li:lt(3) ul > li, div.dropdownv > ul li').each(function(i) {
    var timeOutSub;
    if ($('> ul', this).size() > 0) {
      $('> a', this).addClass('has-subnav');
      $('> a.active', this).removeClass().addClass('active-has-subnav');

      $(this).hover(function(){ //this part is for mouseOver
        clearTimeout(timeOutSub);
        $(this).parent().find('li:not(this) ul').css('display','none');
        $('> ul', this).css({display:'block',visibility:'visible'});
        if ($.browser.msie) {
          var $this_ul = $('> ul', this);
          $this_ul.prepend("<iframe></iframe>");
          $('iframe', this).css('height',$this_ul.get(0).offsetHeight + 'px');
        };
      },function(){ // on mouseOut
        var self = this;
        timeOutSub = setTimeout(function() {
          $('> ul', self).css({display:'none',visibility:'hidden'});
          if ($.browser.msie) {
            $(self).find('iframe').remove();
          };
        },timeoutCounter);
      });
    }
  });
 //Die Parents des aktuellen Menüpunkts auch aufleuchten lassen.
  $('.dropdownh > ul > li > ul > li > ul > li, .dropdownv li').hover(function() {
        $(this).parents( 'li' ).find('a:eq(0)').addClass('hover');
      },function(){
        $(this).parents( 'li' ).find('a:eq(0)').removeClass('hover');
   });
}

