jQuery(function($) {
 $('#right').cycle({
     fx:      'scrollLeft',
     next:   '#right',
     timeout:  5000,
     easing:  'backinout'
  });
  $('body.home .logo').css("opacity", 0).animate({opacity: 1 },400);
    $('.nav').css("opacity", 0).animate({opacity: 1 },400);
    $('#slideshow_index').css("opacity", 0).animate({opacity: 1 },600);
    $('showcase, #fixed_header_ref, #fixed_header_logo, #fixed_header_cms, #fixed_header_leistung, #fixed_header_login, #fixed_header_impressum').css("opacity", 0).animate({opacity: 1 },300);
    $('#description').css("opacity", 0).animate({opacity: 1 },1000);



$('.nav').droppy({trigger: 'hover'});
   Cufon.replace('.nav,h1,h2, h3, .aktuell, #footer, #subnav1, #subnav2', {hover: true });
   Cufon.replace('.current li', {hover: true, color:'#fff'});
   Cufon.replace('.fixed_left h5', {color: '#848b9d'});
   Cufon.replace('#content h5', {color: '#000',fontWeight: 'Bold',fontFamily:'Bold'});
  
  $('#footer_button li').animate({"opacity": 0.7 });
  $('#footer_button li').hover(
    function() {
      $(this).stop().animate({ "opacity": 3 });
    }, 
    function() {
      $(this).stop().animate({ "opacity": 0.7 });
  });

// => fn gallery
  var $galleries = $("ul.gallery");
  $("li", $galleries).hide();
  $("li:first", $galleries).fadeIn("fast");

  var create_gallery_navigation = function($ul_gallery) {
    var gallery_selector = $ul_gallery.attr('id'),
        $nav = $("<ul>").attr({ id:"nav-"+gallery_selector, "class": "nav-gallery"}),
        $nav_li, dyn_selector, $anchor;

        $ul_gallery.after($nav);

    $("li", $ul_gallery).each(function(index, li){
      dyn_selector = "item" + gallery_selector + "_" +index;
      $(li).attr("id", dyn_selector);
      $anchor = $("<a>").attr("href", "#" + dyn_selector).text(index +1);
      $anchor.hover(function(e){ show_image(e, $ul_gallery);}, function(e){ hide_image(e, $ul_gallery);});

      $nav_li = $("<li>").append($anchor).appendTo($nav);
    });
  };
  
  var show_image = function(e, $gallery) {
    $("li", $gallery).fadeOut("fast");
    $($(e.target).attr("href")).fadeIn("fast");
    return false;
  };
  var hide_image = function(e) {
    $("li:first", $gallery).fadeIn("fast");
    $($(e.target).attr("href")).fadeOut("fast");
    return false;
  };
  
  $galleries.each(function(index, gallery){
    create_gallery_navigation($(gallery));
  });

// <= fn gallery

    
  var scrollToElement = function(selector) {
    if (!$(selector).length) return;
    var offset = $(selector).position();
    $('body, html').animate({scrollTop: offset.top - 40}, 'slow');
  };
 
  $("#toc-refernces li a").click( function(e) {
    var $el = $(this);
    scrollToElement($el.attr("href"));
    return false;
  });
  $("#down").click(function(){
    scrollToElement("#footer");
    return false;
  });

});




