// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(function() {
  /*$('.banner-slideshow > *').css("display", "none");
  $('.banner-slideshow > *:first-child').css("display", "block");
  $('.banner-slideshow > *:first-child').addClass("active");
  $('.banner-slideshow > *:first-child + .work-banner:first').addClass("next");
  
  beginSlideshow();*/
  $('.banner-slideshow').cycle({fx: "fade", speedIn: 1500, speedOut: 1500, sync: false, timeout: 12000});
});

function beginSlideshow() {
  $('.active').fadeOut(5000, function() {$('.next').fadeIn("slow", switchSlide());});
}

function switchSlide() {
  $('.banner-slideshow > .active').removeClass("active");
  $('.banner-slideshow > .next').addClass("active");
  $('.banner-slideshow > .next').removeClass("next");
  $('.banner-slideshow > .active + .work-banner:first').addClass("next");

  if ($('.banner-slideshow > .active + .work-banner:first').length == 0) {
    $('.active').fadeOut(5000, function() {
      $('.banner-slideshow > .next').addClass("active");
      $('.banner-slideshow > .next').removeClass("next");
      $('.banner-slideshow > *:first-child').addClass("next");
      $('.next').fadeIn(5000, switchSlide());
    });
  } else {
    $('.active').fadeOut(5000, function() {$('.next').fadeIn(5000, switchSlide());});
  }
}