$(document).ready(function(){
 if (typeof(RS_homeImages) != 'undefined' && RS_homeImages.length > 0) {
     var RS_currentImageIndex = 0;
     
     RS_homeImagePreload = function() {
        var nextIndex = RS_currentImageIndex+1;
        if (nextIndex == RS_homeImages.length) {
            nextIndex = 0;
        }
       if (typeof(RS_homeImages[nextIndex].img) == 'undefined') {
           var img = new Image();
           $(img).load(function() {
             this.loaded = true;
             $(this).css('display','none');             
             $('#imgCycleContainer').get(0).appendChild(img);
           });
           img.className = 'dynamic';
           img.loaded = false;
           img.src = RS_homeImages[nextIndex].src;
           img.setAttribute('title',RS_homeImages[nextIndex].title);
           img.setAttribute('alt',RS_homeImages[nextIndex].title);
           RS_homeImages[nextIndex].img = img;
       }  
     };
          
     RS_homeImageFadeNext = function(){
        RS_currentImageIndex++;
        if (RS_currentImageIndex == RS_homeImages.length) {
            RS_currentImageIndex = 0;
        }
        RS_homeImagePreload();
        if (typeof(RS_homeImages[RS_currentImageIndex].img) != 'undefined'
            && RS_homeImages[RS_currentImageIndex].img.loaded) {
            $(RS_homeImages[RS_currentImageIndex].img).addClass('queued');
            $('#imgCycleContainer img.current').fadeOut("slow", function() {                    
                    $('#imgCycleContainer .queued').removeClass('queued').fadeIn('slow', function() {$(this).addClass('current'), window.setTimeout(RS_homeImageFadeNext, 4000);});
                    $(this).removeClass('current');
                }
            );
        }        
     }
     
     RS_homeImagePreload();
     window.setTimeout(RS_homeImageFadeNext, 4000);     
     
 }
});