// JavaScript Document

$(document).ready(function(){
	
		$('#contenerControl').click(function(){
			if( $('#content').hasClass('hidded') )  {
				$('#content').fadeIn(); 
				$('#content').removeClass('hidded'); 
				$('#contenerControl').html('<p>Fermer -</p>');
			}
			else {
				$('#content').fadeOut();
				$('#content').addClass('hidded');
				$('#contenerControl').html('<p>Ouvrir +</p>');
			}
		});

		// Gestion Onglets Contenus Caractériqtiques / Description
		
		$('.switchers').click(function() {
			var currentId = $(this).attr('id');
			//alert(currentId);
			
				if( currentId == "switchCar") { 
					$('.switchers').removeClass().addClass('switchers'); $('#switchCar').addClass('selText');
					$('#itemDes').fadeOut();
					$('#itemCar').fadeIn();
				}
				else { 
					$('.switchers').removeClass().addClass('switchers'); $('#switchDes').addClass('selText');
					$('#itemCar').fadeOut();
					$('#itemDes').fadeIn();
				}
			
		});
		
		
		// Gestion Onglets Adresses : Golfe Juan / Monaco / Mandelieu
		
		$('.adress').click(function() {
			var currentId = $(this).attr('id');
			//alert(currentId);
			
				if( currentId == "switchAdress1") { 
					$('.adress').removeClass().addClass('adress'); $('#switchAdress1').addClass('selAdress');
					$('#adress2').fadeOut();
					$('#adress3').fadeOut();
					$('#adress1').fadeIn();
				}
				if ( currentId == "switchAdress2" ) { 
					$('.adress').removeClass().addClass('adress'); $('#switchAdress2').addClass('selAdress');
					$('#adress1').fadeOut();
					$('#adress3').fadeOut();
					$('#adress2').fadeIn();
				}
				if ( currentId == "switchAdress3" ) { 
					$('.adress').removeClass().addClass('adress'); $('#switchAdress3').addClass('selAdress');
					$('#adress1').fadeOut();
					$('#adress2').fadeOut();
					$('#adress3').fadeIn();
				}
			
		});
		
});



// Formulaire de contact

$(document).ready(function(){

	$('.masqued').hide();
	$('.masquer').change(function(){
		if( $(this).val() == 'oui' ) { $('.masqued').fadeIn(); }
		else { $('.masqued').fadeOut(); }
	});

});




// Diaporama Images


var diaporama = {
    
    nbSlide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbSlide = elem.find(".picViewIems").length;
        this.elem=elem;
        elem.find(".picViewIems").hide();
        elem.find(".picViewIems:first").show();
        this.elemCurrent = elem.find(".picViewIems:first");
        diaporama.play();
				
				elem.mouseover(diaporama.stop);
				elem.mouseout(diaporama.play);
				$('.minPics').mouseover(diaporama.stop);
				$('.minPics').mouseout(diaporama.play);
				
				$('#btnNext').click(function(){ diaporama.next(); });
				$('#btnPrev').click(function(){ diaporama.prev(); });
				
				// Gestion du diaporama Interne
		
				$('.picViewIems').hide();
				$('#pic1').show();
				
				$('.minPics').click(function(){

					var SelectedPic = $(this).attr('rel');
					var tmpResultat= SelectedPic.substr(3, 4);
					
					//alert(diaporama.nbCurrent);
					
					if(tmpResultat==diaporama.nbCurrent){ return false; }
					else {
						$('.picViewIems').fadeOut();
						$('#'+SelectedPic).fadeIn();
						diaporama.nbCurrent = parseInt(tmpResultat);
					}
				});
    },
    
    gotoSlide : function(num){
        if(num==this.nbCurrent){ return false; }
        
        $(".picViewIems").fadeOut();
        $("#pic"+num).fadeIn();
				
		this.nbCurrent = num;
        this.elemCurrent = this.elem.find("#wrapp"+num);
				
    },
    
    next : function(){

		//alert(diaporama.nbCurrent);
		
		var num  = parseInt(this.nbCurrent)+1;
        if(num  >this.nbSlide){
            num  = 1;
        }
        this.gotoSlide(num);
				
    },
    prev : function(){
        var num  = this.nbCurrent-1;
        if(num< 1){
            num= this.nbSlide;
        }
        this.gotoSlide(num);
    },
    stop : function(){
        window.clearInterval(diaporama.timer);
    },
    play : function(){
        window.clearInterval(diaporama.timer);
        diaporama.timer = window.setInterval("diaporama.next()",5000);
    }

}

$(function(){
    diaporama.init($("#picView"));

});



// Diapo. Arriere plan


var carrousel = {
    
    nbSlide : 0,
    nbCurrent : 1,
    elemCurrent : null,
    elem : null,
    timer : null,
    
    init : function(elem){
        this.nbSlide = elem.find(".slider").length;
        this.elem=elem;
        elem.find(".slider").hide();
        elem.find(".slider:first").show();
        this.elemCurrent = elem.find(".slider:first");
        carrousel.play();
				
					$('.slideFooter').click(function(){
						carrousel.gotoSlide($(this).attr('rel'));
					});
				
    },
    
    gotoSlide : function(num){
        if(num==this.nbCurrent){ return false; }
        
        $(".slider").fadeOut();
        $("#wrapp"+num).fadeIn();
				
				$('.slideFooter').removeClass('slideFooterSel');
				$('#slFo' + num).addClass('slideFooterSel');
				
				this.nbCurrent = num;
        this.elemCurrent = this.elem.find("#wrapp"+num);
				
    },
    
    next : function(){

				var num  = parseInt(this.nbCurrent)+1;
				
        if(num  >this.nbSlide){
            num  = 1;
        }
        this.gotoSlide(num);
				
    },
    prev : function(){
        var num  = this.nbCurrent-1;
        if(num< 1){
            num= this.nbSlide;
        }
        this.gotoSlide(num);
    },
    stop : function(){
        window.clearInterval(carrousel.timer);
    },
    play : function(){
        window.clearInterval(carrousel.timer);
        carrousel.timer = window.setInterval("carrousel.next()",10000);
    }

}

$(function(){
    carrousel.init($("#wrapper"));

});
