var slide, showroom;

document.addEvent('domready', function(){

    /* Animation for lifts */

	slide = new SlideShow('sub-lifts', {
		autoplay: true,
		delay: 9000,
		duration: 750,
        //transition: 'slideDown',
		transition: 'pushLeft',
        onShow: function(e){
            this.selectControl(e.next.index);
        }  
	});

    slide.selectControl = function(i){
        $$('.controls a').each(function(el, j){
        (i == j) 
            ? el.addClass('selected')
            : el.removeClass('selected');
        });
    };

    // Select the first by default
    slide.selectControl(0);

    // Set event handlers for controls
    $$('.controls a').each(function(el, i){
        el.addEvent('click', function(){
            
            if (!slide.isStopped) slide.pause();
            var index = slide.current.retrieve('slideshow-index');
            slide.show(i, {transition: i > index ? 'pushLeft' : 'pushRight'});
        });
    });

    $$('.controls .prev').addEvent('click', function(){
        if (!slide.isStopped) slide.pause();
        slide.show('previous', {transition: 'pushRight'});
    });    

    $$('.controls .next').addEvent('click', function(){        
        if (!slide.isStopped) slide.pause();
        slide.show('next', {transition: 'pushLeft'});
    });
    
    

    /* Animation for big images */
    
    showroom = new SlideShow('showroom', {
		autoplay: true,
		delay: 9000,
		duration: 1050,
		transition: 'crossFade',
        onShow: function(e){
            this.selectControl(e.next.index);
        }  
	});
    
    showroom.selectControl = function(i){
        $$('#photo-navigation a').each(function(el, j){
        (i == j) 
            ? el.addClass('selected')
            : el.removeClass('selected');
        });
    };

    showroom.selectControl(0);

    $$('#photo-navigation a').each(function(el, i){
        el.addEvent('click', function(){
            if (!showroom.isStopped) showroom.pause();
            showroom.show(i);
        });
    });
});
