/*jslint white: true, browser: true, devel: true, onevar: true, undef: true,
  nomen: true, eqeqeq: true, plusplus: false, bitwise: true, regexp: true,
  newcap: true, immed: true, strict: false, maxlen: 80, indent: 2
*/
/*global window: false */
(function ($)
{
  //Live events and non-HTML stuff:


  $(document).ready(function ()
  {
    var testomnialRotate = setInterval(function () {
      var current = $('.testimonials .testimonial:visible').first(),
          next = current.next().length > 0 ?
            current.next() : $('.testimonials .testimonial').first();

      current.fadeOut(1000);
      next.fadeIn(2000);

    }, 8000);

    $('.testimonials .testimonial:not(:first)').hide();

    //below is the background change
    (function slideshow(el) {
      var front = el === '#image_front' ? '#image_front' : '#image_back',
          back = el === '#image_front' ? '#image_back':'#image_front';

      setTimeout(function () {

        $(front).hide().stop().fadeIn(2000);
        $(back).show().stop().fadeOut(2000,
        function () {
          var i = parseInt($(front).attr('class').split('_')[2], 10);
          if (i >= 6) {
            i = 0;
          }
          $(back).removeClass().addClass('image_front_' + (i + 1));
        });
        slideshow(back);
      }, 3000);

    }('#image_front'));

  });

}(window.jQuery));
