var current_image = 0, sc;
function slideImage()
{
  current_image++;
  if ( !$(".p"+current_image, ".photoSlider").get(0))
  {
    current_image=0;
    slideImage();
    return;
  }

  $("img", ".photoSlider").fadeOut("slow");
  $(".p"+current_image, ".photoSlider").fadeIn("slow");
  $(".photoSlider > div").fadeOut(300);
  setTimeout(function()
  {
    if (pst[current_image]["header"] != "")
    {
      $(".photoSlider .slider-textcontent")
        .html(
          "<h3>" + pst[current_image]["header"] + "</h3>"
          + "<p>" + pst[current_image]["descr"] + "</p>"
          + "<a href=\"" + pst[current_image]["link"] + "\">Подробнее...</a>"
        );
      $(".photoSlider > div").fadeIn(300);
    }
  }, 300);
  setTimeout(slideImage, 10000);
}

$(function(){
  sc = $("img", ".photoSlider").length;
  var cnt = 1000;
  if ( sc>1) {
    $("img", ".photoSlider").each(function(i)
    {
      $(this)
        .css("z-index", --cnt)
        .load(function()
        {
          if (i < sc - 1)
          {
            $(".photoSlider img.p" + (i + 2))
              .attr("src", $(".photoSlider img.p" + (i + 2)).attr("load"));
          }
        })
        .hide();
    });
    slideImage()
  }
  if ( sc==0) {
    $(".photoSlider").remove();
  }
  else
  {
    $(".photoSlider")
      .bind(
        "mouseenter",
        function()
        {
          $(".photoSlider .slider-infotext").css("opacity", "0.6");
        }
      )
      .bind(
        "mouseleave",
        function()
        {
          $(".photoSlider .slider-infotext").css("opacity", "0.15");
        }
      );
  }
  
})
