$(document).ready(function(){

  $("video").VideoJS();

  if($('#body-background > img').length>1) {
      $('#body-background > img').css('position', 'absolute');//workaround - transparenz geht sonst nicht richtig
      $('#body-background > img:not(:first-child)').css('display', 'none');

    var bgRotate=function(){
      $('#body-background > img').first().detach().appendTo($('#body-background'));
    };
    var bgFade=function(){
      var f = $('#body-background > img').first();
      f.add(f.next()).fadeToggle(1500, bgRotate);//Animationsdauer
    };
    window.setInterval(bgFade, 10000);//Animationsabstand
  }

  // Hintergrund
  $("#body-background").ezBgResize();

  $('.pxSlider').nivoSlider({
        effect:'random', //Specify sets like: 'fold,fade,sliceDown'
        slices:15,
        animSpeed:500, //Slide transition speed
        pauseTime:8000
  });

  // Portfolio
  $("#pxtooltip img[title]").tooltip({effect:'fade'});

  // Team-Page
  $("li.entry").tooltip({effect:'fade'});

  // Team-Page
  $("li.entry").find("div.vorne").live("click", function() {
    $(this).parent().flip({
      direction: "lr",
      content: $(this.parentNode).find("div.hinten")
    });
  });

  // Team-Page
  $("li.entry").live("click", function() {
    $(this).revertFlip();
  });

  // Archiv
  $("li.archiv").hide();
  $("#prevyear").css({ opacity: 1 });
  $("#nextyear").css({ opacity: 1 });

  if($("li.archiv").hasClass("Current")) {
     $("li.archiv.Current").show()
  } else {
     $("li.archiv:last-child").show();
     $("li.archiv:last-child").addClass("Current");
  } 

  if($("li.archiv.Current").is("li.archiv:first-child")) {
     $("#prevyear").css({ opacity: 0.3 });
  } 

  if($("li.archiv.Current").is("li.archiv:last-child")) {
     $("#nextyear").css({ opacity: 0.3 });
  }

  $("#prevyear").click(function() {
    if($("li.archiv.Current").prev().children("a").attr("href") != "undefined") 
      window.location = $("li.archiv.Current").prev().children("a").attr("href");
  });

  $("#nextyear").click(function() {
    if($("li.archiv.Current").next().children("a").attr("href") != "undefined") 
      window.location = $("li.archiv.Current").next().children("a").attr("href");
  });

  // Lightbox
  $('ul.gallery').find("li").each(function(index) {
    $(this).find("a").lightBox({
      imageLoading:   'http://www.projekt-x.de/media/163/lightbox-ico-loading.gif',    // (string) Path and the name of the loading icon
      imageBtnPrev:   'http://www.projekt-x.de/media/165/lightbox-btn-prev.gif',      // (string) Path and the name of the prev button image
      imageBtnNext:   'http://www.projekt-x.de/media/167/lightbox-btn-next.gif',      // (string) Path and the name of the next button image
      imageBtnClose:  'http://www.projekt-x.de/media/164/lightbox-btn-close.gif',    // (string) Path and the name of the close btn
      imageBlank:     'http://www.projekt-x.de/media/166/lightbox-blank.gif',      // (string) Path and the name of a blank image (one pixel)
      txtImage:       'Bild',  // (string) Specify text "Image"
      txtOf:          'von',    // (string) Specify text "of"
      keyToClose:     'c',    // (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
      keyToPrev:      'v',    // (string) (p = previous) Letter to show the previous image
      keyToNext:      'n'     // (string) (n = next) Letter to show the next image.
    });
  });

  // Lightbox
  $('div.infoboxgallery a').lightBox({
      imageLoading:   'http://www.projekt-x.de/media/163/lightbox-ico-loading.gif',    // (string) Path and the name of the loading icon
      imageBtnPrev:   'http://www.projekt-x.de/media/165/lightbox-btn-prev.gif',      // (string) Path and the name of the prev button image
      imageBtnNext:   'http://www.projekt-x.de/media/167/lightbox-btn-next.gif',      // (string) Path and the name of the next button image
      imageBtnClose:  'http://www.projekt-x.de/media/164/lightbox-btn-close.gif',    // (string) Path and the name of the close btn
      imageBlank:     'http://www.projekt-x.de/media/166/lightbox-blank.gif',      // (string) Path and the name of a blank image (one pixel)
      txtImage:       'Bild',  // (string) Specify text "Image"
      txtOf:          'von',    // (string) Specify text "of"
      keyToClose:     'c',    // (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
      keyToPrev:      'v',    // (string) (p = previous) Letter to show the previous image
      keyToNext:      'n'     // (string) (n = next) Letter to show the next image.
  });

});
