function banner(){};
banner.timeout = 5000;
banner.play = true;
banner.timer = null;

banner.pausePlay = function() {
  if (banner.play) { // Нажали на пауза
    banner.play = false;
    clearTimeout(banner.timer);
    $("#pausePlay").removeClass('arrowPause');
    $("#pausePlay").addClass('arrowPlay');
    if ($.browser.msie) if ($('#pausePlay').attr('style')) $('#pausePlay').attr('style', $('#pausePlay').attr('style').replace('pause', 'play'));
  }
  else {
    banner.play = true;
    banner.timer = setTimeout(banner.goNext, banner.timeout);
    $("#pausePlay").removeClass('arrowPlay');
    $("#pausePlay").addClass('arrowPause');
    if ($.browser.msie) if ($('#pausePlay').attr('style')) $('#pausePlay').attr('style', $('#pausePlay').attr('style').replace('play', 'pause'));
  }
}
banner.goNext = function() {
  var current = $("#mainPhotoBanner .onePhoto:visible");
  var nextOne = $("#mainPhotoBanner .onePhoto:visible").next('.onePhoto');
  if (!$(nextOne).length) nextOne = $("#mainPhotoBanner .onePhoto:first");
  banner.changeBanners(current, nextOne);
  if ($('#mainPhotoBanner .text').attr('style')) $('#mainPhotoBanner .text').attr('style', $('#mainPhotoBanner .text').attr('style').replace('height:0', ''));
}
banner.goPrev = function() {
  var current = $("#mainPhotoBanner .onePhoto:visible");
  var nextOne = $("#mainPhotoBanner .onePhoto:visible").prev('.onePhoto');
  if (!$(nextOne).length) nextOne = $("#mainPhotoBanner .onePhoto:last");
  banner.changeBanners(current, nextOne);
}

banner.changeBanners = function(current, nextOne) {
  clearTimeout(banner.timer);
  $(current).fadeOut('slow');
  $(nextOne).fadeIn('slow');
  if (banner.play) banner.timer = setTimeout(banner.goNext, banner.timeout);
}

banner.init = function() {
  banner.timer = setTimeout(banner.goNext, banner.timeout);
  //banner.goNext();
  
  $("#mainPhotoBanner").mouseover(function(){
    $('#arrowsBlock').show();
  });
  $("#mainPhotoBanner").mouseout(function(){
    $('#arrowsBlock').hide();
  });
  
  $("#arrowPrev").click(banner.goPrev);
  $("#arrowNext").click(banner.goNext);
  $("#pausePlay").click(banner.pausePlay);
}

$(document).ready(function() {
  banner.init();
});

