var od_slideshow = new Class({

    /**
	* Inicializace
	*/ 
    initialize: function(options) {
        // Povinne nastaveni
        this.cont = $(options['idSlideshow']); 
    
        // Volitelne nastaveni
        this.containerSlideButton = $(options['containerSlideButton']); 
        this.durationTime = $defined(options['durationTime']) ? options['durationTime'].toInt() : 300; 
        this.delayTime = $defined(options['delayTime']) ? options['delayTime'].toInt() : 4000; 
        this.delayTimeAfterClick = $defined(options['delayTimeAfterClick']) ? options['delayTimeAfterClick'].toInt() : 20000; 
        this.transitionEffect = $defined(options['transitionEffect']) ? options['transitionEffect'] : 'pushLeft'; 
        this.slideButton = $defined(options['slideButton']) ? options['slideButton'] : false;
        this.autoplay = $defined(options['autoplay']) ? options['autoplay'] : true;
    
        // Nastavuje se pokud je nastaveno slideButton 
        this.pathBtnImg = options['pathBtnImg'];
        this.pathBtnImgSelect = options['pathBtnImgSelect'];
        this.pathBtnImgHover = options['pathBtnImgHover'];

        if(this.cont === null)
            return;    
    
        this.main();
    },
  
  
    /**
	* Hlavni ridici funkce
	*/ 
    main: function() {
        this.initSlideshow();
        this.initButtons();
        this.eventActionSlide();
    }, 
  
  
    /**
   * Inicializace slideshow
   */     
    initSlideshow: function() {
        this.slideShow = new SlideShow(this.cont,{		
            delay: this.delayTime,
            duration: this.durationTime,
            transition: this.transitionEffect,
            autoplay: this.autoplay
        });        
    },
  
  
    /**
   * Inicializace tlacitek
   */     
    initButtons: function() {
        if(this.containerSlideButton === null)
            return;
      
        if(this.slideButton) {   
            var slideContents = this.cont.getElements('div');
            slideContents.each(function(item, index) {
                var slideBtn = new Element('img', {
                    src: (index == 0 ? this.pathBtnImgSelect : this.pathBtnImg),
                    alt: ''
                });    
              
                slideBtn.inject(this.containerSlideButton, 'bottom');
            }.bind(this));
      
            this.btns = this.containerSlideButton.getElements('img');
        } else {
            this.btns = this.containerSlideButton.getChildren();
            this.btns[0].addClass('selected');      
        }         
    },    
  
  
    /**
   * Zobrazeni slidu
   */ 
    eventActionSlide: function() {
        var timer = '';
        if(this.btns){
            this.btns.each(function(item, index) {
          
                // Click
                item.addEvent('click', function(){
                    if(timer)
                        $clear(timer);
    
                    this.slideShow.pause();
                    this.slideShow.show(this.slideShow.slides[index], {
                        duration: this.durationTime
                    });
            	
                    timer = (function(){
                        this.slideShow.play();
                    }.bind(this)).delay(this.delayTimeAfterClick - this.delayTime);
                    if(this.slideButton) {
                        this.btns.set('src', this.pathBtnImg);
                        item.set('src', this.pathBtnImgSelect);
                    }
                }.bind(this));  
          
                if(this.slideButton) {
                    // MouseOver
                    item.addEvent('mouseover', function() {  
                        select = item.get('src').slice(-10); 
                        if(select != 'select.png')
                            item.set('src', this.pathBtnImgHover);
        
                    }.bind(this)); 
              
                    // MouseOut
                    item.addEvent('mouseout', function(){
                        select = item.get('src').slice(-10); 
                        if(select != 'select.png')    
                            item.set('src', this.pathBtnImg);       
                    }.bind(this));  
                }
                 
            }.bind(this));
      
            this.slideShow.addEvents({
    	     
                onShowComplete: function(obj) {
                    if(this.slideButton) {
                        this.btns.set('src', this.pathBtnImg);
                        this.btns[obj.next.index].set('src', this.pathBtnImgSelect); 
                    } else {
                        elm = $('containerSlideButton').getChildren();
                        elm.removeClass('selected');
                        elm[obj.next.index].addClass('selected');       
                    }  
                }.bind(this)
            }); 
        }  
    }
 
})

function d(str) {
    console.log(str);
}



