window.addEvent("domready", function() {
    if ($('slide-list')) {
        $('slide-list').setStyle('width', '2000px');
    
        pocet = $$('#slide-list li').length;
        var totIncrement = 0;
        var increment = 83;
        var maxRightIncrement = increment*(5-pocet);
        // FX var 
        var fx = new Fx.Morph('slide-list',  {
        duration: 500,
        wait: true
        });
    }
    
    // Previous Button
    if ($('gallery-previous') && pocet>5) {
        $('gallery-previous').setStyle('display', 'block');
        $('gallery-previous').addEvent( 
        'click', function(event){ 
            if(totIncrement<0){ 
                totIncrement = totIncrement + increment;
                fx.start({'margin-left' : totIncrement});
            }
            event.stop();
        }); 
    }
    
    // Next Button
    if ($('gallery-next') && pocet>5) {
        $('gallery-next').setStyle('display', 'block');
        $('gallery-next').addEvent( 
            'click', function(event){ 
            if(totIncrement>maxRightIncrement){ 
                totIncrement = totIncrement - increment;
                fx.start({'margin-left' : totIncrement});
            }
            event.stop();
        });
    }
    
});
