﻿var _LargeThumbs;
var _CurrentThumb = 0;

$(document).ready(function() {
  $(".MediumThumb").click(function() {
    $(".LargeThumb").hide();
    $(".FullHtml").hide();
    $(".SmallThumb").hide();

    $(".LargeThumb[ID='" + this.id + "']").show();
    $(".LargeThumb[ID='" + this.id + "']").find(".LargeThumbView").hide();
    $(".LargeThumb[ID='" + this.id + "']").find(".LargeThumbView:first").show();

    $(".FullHtml[ID='" + this.id + "']").show();
    $(".SmallThumb[ID='" + this.id + "']").show();
    $(".MediumThumb").removeClass("selected");
    $(this).addClass("selected");
  });
  $(".MediumThumb:first").addClass("selected");
  $(".SmallThumbView").click(function() {
    $(".LargeThumbView").hide();
    $(".LargeThumbView[ID='LT" + this.id + "']").show();

  });

  _LargeThumbs = $(".LargeThumb");
  
  if ($(".LoadImage:first").length > 0)
    setTimeout(LoadImages, 10);

  
    
  setTimeout(FadeNext,5000);
    
});



function FadeNext()
{
  var _outThumb = _CurrentThumb;
  if(_CurrentThumb < _LargeThumbs.length - 1)
    _CurrentThumb++;
   else
    _CurrentThumb = 0;
  jQuery(_LargeThumbs[_CurrentThumb]).fadeIn("slow");
  jQuery(_LargeThumbs[_outThumb]).hide();
  setTimeout(FadeNext,5000);
}

var loadingCount = 0;

function LoadImages() {

  $(".LoadImage").each(function(index, el) {
    el = $(el);
    if (loadingCount < 10) {
      var ImgSrc = el.attr('ImgSrc');

      el.removeAttr('ImgSrc');
      el.removeClass('LoadImage');
      loadingCount++;
      el.attr('src', ImgSrc).load(function() {
        loadingCount--;
        if (loadingCount < 10)
          LoadImages();
      });

      if (loadingCount >= 10)
        return false;

    }
  });

}