
//slideshowf_id = "slideshow_folder_box"; 
slideshowf_image_id = "slideshow_folder_box_img";
slideshowf_text_id = "slideshow_folder_box_txt";
slideshowf_autostart = 1;

slideshowf_step_duration = slideshowf_duration_fade / slideshowf_fade_steps;
slideshowf_img_count = slideshowf_pics.length+1;

slideshowf_img_counter = 1;

function arrayShuffle(){
        var tmp, rand;
        for(var tmpi =0; tmpi < this.length; tmpi++){
                rand = Math.floor(Math.random() * this.length);
                tmp = this[tmpi]; 
                this[tmpi] = this[rand]; 
                this[rand] =tmp;
        }
}
Array.prototype.shuffle =arrayShuffle;


function slideshow_box_folder() {
        // random first image / keep order
        if (slideshowf_mode=="slide_random_start") {
                for(i=0;i<=Math.floor(Math.random()*slideshowf_pics.length);i++){
                        slideshowf_pics.push(slideshowf_pics.shift());
                }
        }
        // shuffle image order
        if (slideshowf_mode=="slide_random") {
                slideshowf_pics.shuffle();
        }
        
        slideshowf_pics[slideshowf_img_count-1] = slideshowf_pics[0];
        
        html_code = "<div style='position:absolute;'>";
        for(j=1; j<=slideshowf_img_count; j++){
                img_id = slideshowf_image_id+j;
                txt_id = slideshowf_text_id+j;
                img_src = slideshowf_pics[j-1][0];
                html_code += "<div id='"+img_id+"' class='slideshowf_image'>";
                html_code += "<a href='"+slideshowf_link+"' target='"+slideshowf_linktarget+"'>";
                html_code += "<img src='"+img_src+"' border='0' /></a>";
                html_code += "<div id='"+txt_id+"'>"+slideshowf_pics[j-1][3]+"</div>";
                html_code += "</div>";
        }
        html_code = html_code + "</div>";
        
        document.write("<style type='text/css'>");
        document.write(".slideshowf_image {position:absolute;text-align:center;width:"+slideshowf_width+"px;height:"+(slideshowf_height)+"px;background-color:"+slideshowf_bg+";visibility:hidden;z-index:1;overflow:hidden;}");
        document.write("</style>");
        
        /*
        document.write("<div id='test0'></div>");
        document.write("<div id='test1'></div>");
        document.write("<div id='test2'></div>");
        document.write("<div id='test3'></div>");
        counter = 0;
        */
        
        
        this.slideshow_fade_img1 = function() {
                self2 = this;
                document.getElementById(slideshowf_text_id+slideshowf_img_counter).style.visibility = "hidden";
                startnew = 0;
                prevImg = document.getElementById(slideshowf_image_id+slideshowf_img_counter);
                prevImg.style.zIndex = 1;
                if (slideshowf_img_counter < slideshowf_img_count) {
                        slideshowf_img_counter =  slideshowf_img_counter+1;
                } else {
                        startnew = 1;
                        slideshowf_img_counter =  1;
                        
                        document.getElementById(slideshowf_id).innerHTML = html_code;
                        firstImg1 = document.getElementById(slideshowf_image_id+1);
                        firstImg1.style.visibility = "visible";
                
                        setTimeout("self2.slideshow_fade_img1()", 250);
                }
                
                if (startnew==0) {
                        slideshowf_fade_start = new Date().getTime();
                        slideshowf_fade_end = slideshowf_fade_start + slideshowf_duration_fade;
                        
                        document.getElementById(slideshowf_text_id+slideshowf_img_counter).style.visibility = "visible";
                        nextImg = document.getElementById(slideshowf_image_id+slideshowf_img_counter);
        //                document.getElementById("test3").innerHTML = "next: "+slideshowf_img_counter;
                        nextImg.style.opacity = 0;
                        nextImg.style.filter = "alpha(opacity=0)";
                        nextImg.style.visibility = "visible";
                        nextImg.style.zIndex = 5;
        //                document.getElementById("test0").innerHTML = " ";
                        
                        self2.slideshow_fade_step1();
                }
        }
        
        this.slideshow_fade_step1 = function() {
                self2 = this;
        //        counter++;
        //        document.getElementById("test1").innerHTML = "counter: "+counter;
                
                timefade = new Date().getTime();
                if (timefade < slideshowf_fade_end) {
                        newalpha = 100 - (slideshowf_fade_end - timefade) / slideshowf_duration_fade * 100;
        //                document.getElementById("test2").innerHTML = newalpha;
                        nextImg.style.opacity = newalpha/100;
                        nextImg.style.filter = 'alpha(opacity=' + newalpha + ')';
                        
                        setTimeout("self2.slideshow_fade_step1()", slideshowf_step_duration);
                } else {
        //                document.getElementById("test2").innerHTML = "DONE";
                        
                        nextImg.style.zIndex = 2;
                        nextImg.style.opacity = 1;
                        nextImg.style.filter = 'alpha(opacity=100)';
                        
                        setTimeout("self2.slideshow_fade_img1()", slideshowf_duration_image);
                }
        }
        
        this.slideshow_start1 = function(){
                self2 = this;
                document.getElementById(slideshowf_id).innerHTML = html_code;
                
                first_img = document.getElementById(slideshowf_image_id+1);
                first_img.style.visibility = "visible";
        
                if(slideshowf_autostart==1){
                        setTimeout("self2.slideshow_fade_img1()", slideshowf_duration_image);
                }
        }
}


new slideshow_box_folder().slideshow_start1();