

var sat = {
    // agocha ou amosa un elemento soio,
    // ou un elemento que conten outros (test length)
    // el: elemento a modificar
    // val valor a darlle a display [none ou block]
    display: function (el,val) {
        if (el.length) {
            for (var i = 0 ; i < el.length; i++) {
                el[i].style.display = val;
            }
        }
        else {
            el.style.display = val;
        }
    },
    activa: function (eldt, eldd) {
        // habilitacion das funcions internas do metodo
        var that = this;
        //var k;
        for (var k = 0; k < eldt.length; k+=1) {
            eldt[k].onclick = function (k) {
                return function () {
                    // desactivar todolos tab
                    for (var z = 0; z < eldt.length; z+=1) {
                        eldt[z].setAttribute('class', '');
                        that.display (eldd[z], 'none');
                    }
                    // activalo clicado
                    eldt[k].setAttribute('class', 'activo');
                    that.display (eldd[k], 'block');
                };
            }(k);
        }
    },
    ini: function (el) {
    	if (document.getElementById(el)) {
            var adl = document.getElementById(el);
            var adt = adl.getElementsByTagName('dt');
            var add = adl.getElementsByTagName('dd');
            // agochar todos 
            this.display (add, 'none');
            // amosa o primeiro
            this.display (add[0], 'block');
            // activalo tab clicado. O tab inicial determinase co CSS
            // o n° do tab activo determina o do dd visible
            this.activa(adt, add);
	}
    }
};


sat.ini('galerie');
sat.ini('tab');
sat.ini('ascenseur');

// Mini-carte: lien vers la carte principale

if ( document.getElementById('mini_carte') )
{
    document.getElementById('mini_carte').onclick = function ()
    {  
        document.location.href='carte';
    }
}
		
		
/*
|	---------------------------------------------------------
|		NEWSLETTERS
|	---------------------------------------------------------
|
|		Inscription aux bons plans
|		>	Supprimer le texte par défaut au click 
|
*/ 

if ( document.getElementById('newsletter') ) 
{
	var compteur	=	0;
	document.getElementById('email').onclick 	=	function ()
	{ 
		if ( compteur	==	0 )
		{
			document.getElementById('email').value 	=	'';
			compteur	=	1;
			console.info ( compteur );
		}
	}  
}
 
 


var iSlideShow = new Class.create();

iSlideShow.prototype = {

	initialize : function (oArgs){
		this.wait 			= oArgs.wait ? oArgs.wait : 3000;
		this.start 			= oArgs.start ? oArgs.start : 0;
		this.duration		= oArgs.duration ? oArgs.duration : 0.9;
		this.autostart		= (typeof(oArgs.autostart)=='undefined') ? true : oArgs.autostart;
		this.slides 		= oArgs.slides;
		this.counter		= oArgs.counter;
		this.caption		= oArgs.caption;
		this.playButton		= oArgs.playButton ? oArgs.playButton : 'PlayButton';
		this.pauseButton	= oArgs.pauseButton ? oArgs.pauseButton : 'PauseButton';
		this.iImageId		= this.start;
		if ( this.slides ) {
			this.numOfImages	= this.slides.length;
			if ( !this.numOfImages ) {
				alert('No slides?');
			}
		}
		if ( this.autostart ) {
			this.startSlideShow();
		}
	},

	// The Fade Function
	swapImage: function (x,y) {
		$(this.slides[x]) && $(this.slides[x]).appear({ duration: this.duration });
		$(this.slides[y]) && $(this.slides[y]).fade({duration: this.duration });
	},

	// the onload event handler that starts the fading.
	startSlideShow: function () {
		this.play = setInterval(this.play.bind(this),this.wait);
		if ( $(this.playButton) ) $(this.playButton).hide();
		$(this.pauseButton).appear({ duration: 0});

		this.updatecounter();

	},

	play: function () {

		var imageShow, imageHide;

		imageShow = this.iImageId+1;
		imageHide = this.iImageId;

		if (imageShow == this.numOfImages) {
			this.swapImage(0,imageHide);
			this.iImageId = 0;
		} else {
			this.swapImage(imageShow,imageHide);
			this.iImageId++;
		}

		this.textIn = this.iImageId+1 + ' of ' + this.numOfImages;
		this.updatecounter();
	},

	stop: function  () {
		clearInterval(this.play);
		$(this.playButton).appear({ duration: 0});
		$(this.pauseButton).hide();
	},

	goNext: function () {
		clearInterval(this.play);
		$(this.playButton).appear({ duration: 0});
		$(this.pauseButton).hide();

		var imageShow, imageHide;

		imageShow = this.iImageId+1;
		imageHide = this.iImageId;

		if (imageShow == this.numOfImages) {
			this.swapImage(0,imageHide);
			this.iImageId = 0;
		} else {
			this.swapImage(imageShow,imageHide);
			this.iImageId++;
		}

		this.updatecounter();
	},

	goPrevious: function () {
		clearInterval(this.play);
		$(this.playButton).appear({ duration: 0});
		$(this.pauseButton).hide();

		var imageShow, imageHide;

		imageShow = this.iImageId-1;
		imageHide = this.iImageId;

		if (this.iImageId == 0) {
			this.swapImage(this.numOfImages-1,imageHide);
			this.iImageId = this.numOfImages-1;

			//alert(NumOfImages-1 + ' and ' + imageHide + ' i=' + i)

		} else {
			this.swapImage(imageShow,imageHide);
			this.iImageId--;

			//alert(imageShow + ' and ' + imageHide)
		}

		this.updatecounter();
	},

	updatecounter: function () {
		var textIn = this.iImageId+1 + ' of ' + this.numOfImages;
		$(this.counter) && ( $(this.counter).innerHTML = textIn );
		if ( $(this.caption) && ( oNewCaption = $(this.slides[this.iImageId]).down('.image-caption') ) ) {
			$(this.caption).innerHTML = oNewCaption.innerHTML;
		}
	}
}

