// JavaScript Document

function slideShow( Obj ){

        var pass = this;
        // initializing
        this.curImg = 0;
        this.slides = Obj;
        this.slides.each( function( img, index ){
            if( index > 0 ) img.fade();
            img.set('morph', { duration: 'long' });
        }, this);
        this.next = function(){
            pass.curImg++;
            this.slides.each( function( img, index ){
                img.morph({ opacity: 0 });
            }, this);
            if( pass.curImg == this.slides.length ) pass.curImg = 0;
            if (this.slides[ pass.curImg ]) this.slides[ pass.curImg ].morph({ opacity: 1 });
        }
        this.prev = function(){
            pass.curImg--;
            this.slides.each( function( img, index ){
                img.morph({ opacity: 0 });
            }, this);
            if( pass.curImg < 0 ) pass.curImg = this.slides.length - 1;
            if (this.slides[ pass.curImg ]) this.slides[ pass.curImg ].morph({ opacity: 1 });
        }
}

function homeslideshow() {
    sshow1 = new slideShow( $$('td#sshow-1 img') );
    sshow1.next.periodical( 3000, sshow1 );

    sshow2 = new slideShow( $$('td#sshow-2 img') );
    sshow2.next.periodical( 3000, sshow2 );

    sshow3 = new slideShow( $$('td#sshow-3 img') );
    sshow3.next.periodical( 3000, sshow3 );

    sshow4 = new slideShow( $$('td#sshow-4 img') );
    sshow4.next.periodical( 3000, sshow4 );

    sshow5 = new slideShow( $$('td#sshow-5 img') );
    sshow5.next.periodical( 3000, sshow5 );

    sshow6 = new slideShow( $$('td#sshow-6 img') );
    sshow6.next.periodical( 3000, sshow6 );

    sshow7 = new slideShow( $$('td#sshow-7 img') );
    sshow7.next.periodical( 3000, sshow7 );

    sshow8 = new slideShow( $$('td#sshow-8 img') );
    sshow8.next.periodical( 3000, sshow8 );
}

function slideshow(){
	
	//$$('div#bandeau-slide img').setStyle('opacity','0');
	
    $$('div#bandeau-slide').each(function(element){

        var name = $$('div#bandeau-slide img').getProperty('src');


        new Asset.images(name, {
            onload: function(){},
            onComplete: function(){
				$$('div#bandeau-slide img').setStyle('display', 'block');
				
                if (sshow = new slideShow( $$('div#bandeau-slide img') )) {
					sshow.next.periodical( 3000, sshow );
				}
            }
        });
    });
}

function slideshow_tarifs(){
	
	sshow = new slideShow( $$('div#keyword-slide span') );
	sshow.next.periodical( 3000, sshow );
	/*
	alert('ok');
	 $$('div#keyword-slide').each(function(element){

        var name = $$('div#bandeau-slide img').getProperty('src');
		
        new Asset.images(name, {
            onload: function(){},
            onComplete: function(){
				$$('div#keyword-slide img').setStyle('display', 'block');
				
                if (sshow = new slideShow( $$('div#keyword-slide img') )) {
					sshow.next.periodical( 3000, sshow_tarif );
				}
            }
        });
    });
    */
}
/*
window.addEvent( 'load', function(){

	var images = $$('div#bandeau-slide img');
	
	
	for (i=0; i<images.length; i++){
		images[i].setStyle('opacity',0);
		images[i].setStyle('display','block');
		//alert(images[i].getProperty('src'));
	}
	
	if ( typeof( images[0] ) != "undefined" ) {
		images[0].setStyle('opacity',1);
	}

    var timer = homeslideshow.delay(3000);

	var timer2 = slideshow.delay(3000);

	var timer3 = slideshow_tarifs.delay(3000);
	
});
*/

window.addEvent( 'load', function(){
    
    sshow = new slideShow( $$('div#bandeau-slide img'));
    setTimeout(function() { $$('div#cache').setStyle('display', 'none');},1000);
    sshow.next.periodical( 3000, sshow );

    var timer = homeslideshow.delay(3000);
    var timer3 = slideshow_tarifs.delay(3000);
});

