var initNavigation = function() {
  var navLi = $('#navigation li');
  var navUl = navLi.find('ul');
  navUl.show();
  var spacerHeight = '50';
  navUl.hide().css({'marginTop':-spacerHeight}).show();

  $('#navigation li').hover(
    function(){
      $(this).find('ul').stop().delay(100).animate({'marginTop':12}, 300);
      if ($(this).find('ul').length > 0) {
        $('#navigationSpacer').stop().animate({'height':spacerHeight+'px'}, 300);
      }
    },
    function(){
      $(this).find('ul').stop().animate({'marginTop':-spacerHeight}, 300);
      if ($(this).find('ul').length > 0) {
        $('#navigationSpacer').stop().animate({'height':'0px'}, 300);
      }
    });
}

/* jcycle 
 * set image container height to auto each time
 * a new image load
 */
function currentItem(curr, next, opts) { 
  var index = opts.currSlide;
  var $ht = $(this).height() + 10;
  $(this).parent().height($ht);
};

$(document).ready(function(){
  initNavigation();
  
  if($(".album_preview").length) {
    $(".album_preview .image_container a.grouped_elements").fancybox({
      'onComplete'    :    function() {  $("#fancybox-title").hide(); }
    });
  }
  
  if (!Modernizr.mq("screen and (max-width:1230px)")) {
    $('#logo').fadeIn(1000);
  }
   
  $("#startseite .fadeout img, #logo img, #prevLinkImage, #nextLinkImage").mouseover(function() {
    $(this).fadeTo('fast', 0.8, function() {});
  });
  $("#startseite .fadeout img, #logo img, #prevLinkImage, #nextLinkImage").mouseout(function() {
    $(this).fadeTo('fast', 1, function() {});
  });
  
  $("#logo").hover(
    function(){
      $(this).stop().animate({'left':'40px'}, 'slow');
    },
    function(){
      $(this).stop().animate({'left':'50px'}, 'slow');
    }
  );
 
});
