var slideShow =  {
    init : function( options ){
        
        slideShow.settings = {
            duration : 7,   // How much seconds will pass before slideshow continues
            fadeTime : 3, // How much seconds will take to fade out slide to next slide
            direction : "normal"  // Normal or random
        }
        
        if(options!=undefined){
            for(i in slideShow.settings ){
                if(options[i]!==undefined){
                    slideShow.settings[i]=options[i];
                }

            }
        }
        
        slideShow.current_index = 0;
        slideShow.slides = $$("#slideshow img");
        slideShow.total_slides = slideShow.slides.length;
        
        setTimeout(function(){ 
            slideShow.autoRun();
        },(slideShow.settings.duration)*1000);
        
    },
    show : function(index){
        var l = slideShow.slides[slideShow.current_index];
        var e = slideShow.slides[index];
        
        var fx = new Fx({duration: slideShow.settings.fadeTime*1000});
        fx.set = function(value){l.setOpacity(value); }; 
        fx.start(1, 0);
       
        var fx = new Fx({duration: slideShow.settings.fadeTime*1000});
        fx.set = function(value){e.setOpacity(value); }; 
        fx.start(0, 1);
        
        slideShow.current_index=index;
    },
    autoRun : function(){
        
        if(slideShow.settings.direction=="random"){
            var index=null;
            while(index==null){
                var index = Math.floor(Math.random()*slideShow.total_slides);
                if(index==slideShow.current_index) index=null;
            }
        }
        else {
            index=slideShow.current_index+1;
            if(index==slideShow.total_slides) index=0;
        }
        
        slideShow.show(index);
        
        setTimeout(function(){ 
            slideShow.autoRun();
        },(slideShow.settings.duration+slideShow.settings.fadeTime)*1000);
        
    }
}
