
function slideshow_trim(value) {
    value = value.replace(/^\s+/,''); 
    value = value.replace(/\s+$/,'');
    return value;
}


var slideshow_list=slideshow_images.split(',');
for(var i=0;i<slideshow_list.length;i++){
    slideshow_list[i]=slideshow_directory+'/'+slideshow_trim(slideshow_list[i]);
}

var loadingImage;
var loadingImageTimer=0;
var slideshowTimer=0;
var slideshow_currentImage=0;
var slideshow_downloadDate;

function checkImageLoaded(){
    if(loadingImage.complete){
        clearInterval(loadingImageTimer);
        loadingImageTimer=0;
        
        var ms=(new Date()).getTime() - slideshow_downloadDate.getTime();
        
        var imgdiv=document.getElementById('content1');
        
        var pos='top left';
        
        var c=document.getElementById('content2');
        if(!c){
            c=document.getElementById('content3');
        }
        if(c){
            c.style.display='block';
            c.style.position='relative';
            c.style.zIndex=2;
        }
        
        
        
        var front=document.getElementById('slideshow_frontlayer');
        if(front){
            front.style.position='absolute';
            front.style.width='100%';
            front.style.height='100%';
            front.style.opacity=0;
            front.style.display='none';
            front.style.backgroundRepeat='no-repeat';
            front.style.backgroundPosition='left top';
        }
        
        front.style.backgroundImage='url('+loadingImage.src+')';
        front.style.display='block';
        jQuery(front).animate({opacity:1},slideshow_fadeSpeed*1000,null,function(){
                              imgdiv.style.backgroundImage='url('+loadingImage.src+')';
                              front.style.opacity=0;
                              front.style.display='none';
                              loadingImage=null;
                              if( (ms/1000) > slideshow_speed){
                                    clearInterval(slideshowTimer);
                                    slideshow_loadNext();
                                    slideshowTimer=setInterval("slideshow_tick()",slideshow_speed*1000);
                              }
                              });
        
    }
}

function slideshow_loadNext(){
    if(loadingImage)
        return false;
    slideshow_currentImage++;
    if(slideshow_currentImage==slideshow_list.length)
        slideshow_currentImage=0;
    
    loadingImage=new Image();
    slideshow_downloadDate=new Date();
    loadingImage.src=slideshow_list[slideshow_currentImage];
    loadingImageTimer=setInterval("checkImageLoaded()",100);
    return true;
}

function slideshow_tick(){
    slideshow_loadNext();
}


jQuery(document).ready(function(){ 

                       var imgdiv=document.getElementById('content1');
                       
                       imgdiv.innerHTML='<div id="slideshow_frontlayer"></div>'+imgdiv.innerHTML;

                       slideshowTimer=setInterval("slideshow_tick()",slideshow_speed*1000);
                       
                       });


