var currentImage = 0;
var ImagePath = '/files/biover/Image/promo/';
var Data = {
  0: "1.jpg",
  1: "2.jpg",
  2: "3.jpg",
  3: "4.jpg"
};
var dataLength = 0;

jQuery(function(){

  jQuery('h3.title').each(function() {
    jQuery(this).nextUntil('h3.title').not('h3.title').wrapAll('<div class="content"></div>').parent().hide();
  }).children('span').click(function() {
    jQuery(this).parent().next('.content').stop().slideToggle();
  });

  jQuery('#askQuestionButton').click(function() {
    jQuery('#askForm').toggle();
  });

  if(jQuery('#promo').length) {
     jQuery.each(Data, function() {
      dataLength++;
    });
    jQuery('#slide-two').css({
      backgroundImage: 'url('+ImagePath + Data[currentImage] + ')'
    });
    jQuery('#slide-one').css({
      backgroundImage: 'url('+ImagePath + Data[currentImage + 1] + ')'
    });
    currentImage++;
    window.setTimeout(jPresentation, 4000);
  }

});


function jPresentation() {
  currentImage++;
    if(currentImage >= dataLength) {
      currentImage = 0;
    }
  if(jQuery('#slide-two').is(':visible')) {
    jQuery('#slide-two').fadeOut(2000, function() {
      jQuery(this).css({
        backgroundImage: 'url('+ImagePath + Data[currentImage] + ')'
      });
    });
  }
  else {
    jQuery('#slide-two').fadeIn(2000, function() {
      jQuery('#slide-one').css({
        backgroundImage: 'url('+ImagePath + Data[currentImage] + ')'
      });
    });
  }

  window.setTimeout(jPresentation, 6000);
}
