$(document).ready(function () {
  // $(document).pngFix(); 
  initHomeTabs(100, 300);
  initMenu(100, 'fast', 'topnav_level1', 'topnav_level2');
  
  $('#imagebild').cycle({
        fx: 'fade'
    // , timeout: 7000
    // , speed:   1000
    // , delay: -2000 
      
      , timeout:  2000
      , speed:    1000
      , delay:   -1500      
  });
	
		$("#eventkalender").animate({ 
			height: '135px'
		}, 750 ,
			function() {
			
			$('.content').fadeIn(500);
			
		});	

});

function initHomeTabs(fadeIn, fadeOut) {
  $('.inhalte999Lay').each(function () {
    
    $(this).click(function () {
      $(this).find('a').each(function () {
        window.location.href = $(this).attr('href');
      });
    });
    
    // shift down
    $(this).mouseenter(function () {
      // $(this).css('background-position', '175px 133px');
      $(this).animate({backgroundPosition: '175px 165px'}, {duration: fadeIn, queue: false});
    });

    // shift up
    $(this).mouseleave(function () {
      $(this).animate({backgroundPosition: '175px 133px'}, {duration: fadeOut, queue: false});
    });
  
  });
}


function initMenu(delay, fadeOut, fl, sl) {
  $('UL.navigationspunkte.' + sl).hide();

  $('LI.' + fl).mouseenter(function () {
    $(this).find('UL.' + sl).each(function () {
      $(this).show();
        window.clearTimeout(this.timer);
      });
  });


  $('LI.' + fl).mouseout(function () {
    $(this).find('UL.' + sl).each(function () {
      (function (ul) { hideMenu(ul);})(this);
    });
  });

  // notwendig, weil von ul.level2 auf li.level1 offenbar
  // nicht immer ein mousenter gefeuert wird
  $('LI.' + fl).mousemove(function () {
    $(this).find('UL.' + sl).each(function () {
      window.clearTimeout(this.timer);
      $(this).stop(true, true);
      $(this).show();
    });
  });


  $('UL.' + sl + ', UL.' + sl + ' LI').mousemove(function () {
    window.clearTimeout(this.timer);
  });

  $('UL.' + sl).mouseout(function () {
    (function (ul) { hideMenu(ul); })(this);
  });

  function hideMenu(ul) {
    window.clearTimeout(ul.timer);
    ul.timer = window.setTimeout(function () {
      $(ul).fadeOut(fadeOut);
    }, delay);
  }
}
