$(document).ready( function () {

	/* = GESTION DES POLICES
	---------------------------------------------------------------------------------------- */

	Cufon.replace('#mainContent.index cite', { fontFamily: 'HansHand' });
	Cufon.replace('#mainContent h2', { fontFamily: 'HansHand' });
	Cufon.replace('.navMain li .subMenu li a', { fontFamily: 'Champagne Limousines Thick' });

	Cufon.replace('.footerContentMain h4', { fontFamily: 'Champagne Limousines Thick' });
	Cufon.replace('.footerContentMain .content p', { fontFamily: 'Champagne Limousines Thick' });
	Cufon.replace('.footerContentMain .content li', { fontFamily: 'Champagne Limousines Thick' });
	Cufon.replace('.footerContentMain .content a', { fontFamily: 'Champagne Limousines Thick' });

	/* = Gestion des boutons d'affichage et de maquage du menu et des contenus
	---------------------------------------------------------------------------------------- */

	// => Boutons pour l'affichage du MENU
	$('.wrapperNavMain').append('<p class="btnSlideDown"><a href="#" class="down"><img src="decor/pic-arrow-down.png" alt="" height="13" width="28" /></a></p>');
	$('.navMain').after('<p class="btnSlideUp"><a href="#" class="up"><img src="decor/pic-arrow-up.png" alt="" height="14" width="23" /></a></p>');
	$('.wrapperNavMain .btnSlideUp').hide();

		/* => Gestion de l'affichage du Menu
		----------------------------------------- */
		$(".navMain").hide();
		$(".navMain ul.subMenu").hide();
		$(".navMain ul.subsub").hide();
		$('#containerNavMain .down').click(function(){
			$("#containerNavMain h2").hide();
			$("#containerNavMain").css('padding','10px 0 0 0');
			$(".navMain").slideDown("slow", function(){
				$('#containerNavMain .btnSlideUp').show();
				$('#containerNavMain .btnSlideUp').css({
					position:'relative',
					top:'-5px'
				});
			});
			$('.wrapperNavMain p.btnSlideDown').css('display','none');
		});
		$('#containerNavMain .btnSlideUp a').click(function(){
			$(".navMain").slideUp("slow", function(){
				$(".navMain").hide();
				$("#containerNavMain").css('padding','0');
				$("#containerNavMain h2").show();
				$('#containerNavMain .btnSlideUp').hide();
				$('.wrapperNavMain p.btnSlideDown').css('display','block');
			});
		});


	// => Boutons pour l'affichage du CONTENU
	$('#mainContent').append('<p class="btnSlideUp"><a href="#" class="up"><img src="decor/pic-arrow-up.png" alt="" height="16" width="23" /></a></p>');
	$('#mainContent').append('<p class="btnSlideDown"><a href="#" class="down"><img src="decor/pic-arrow-down.png" alt="" height="13" width="28" /></a></p>');
	$('#mainContent .btnSlideDown').hide();
	$('#mainContent.index .btnSlideUp').css('display','none');
	$('#mainContent.index .btnSlideDown').css('display','none');

		/* => Gestion de l'affichage du Contenu
		----------------------------------------- */
		$('#mainContent .btnSlideUp a').click(function(){
			$('#mainContent .btnSlideUp').hide();
			$('#mainContent .logo').hide();
			$(this).parent().parent().children('.theContent').slideUp("slow", function(){
				$('#mainContent .btnSlideDown').css('margin-top','20px');
				$('#mainContent .btnSlideDown').show();
			});
			$('#mainContent h2:first').show();
			$('#mainContent h2:first').css({
				'display':'block',
				'margin':'12px 0 0 0',
				'textAlign':'center'
			});
		});
		$('#mainContent .btnSlideDown a').click(function(){
			$('#mainContent .logo').show();
			$('#mainContent .btnSlideDown').hide();
			$(this).parent().parent().children('.theContent').slideDown("slow", function(){
				$('#mainContent .btnSlideUp').show();
			});
			$('#mainContent h2:first').css({
				'margin':'0',
				'textAlign':'left'
			});
		});

	// => Boutons pour l'affichage de la Gallery
	$('#footerGalleryContent').before('<p class="btnSlideUp"><a href="#" class="up"><img src="decor/footer-pic-arrow-up.png" alt="" height="16" width="26" /></a></p>');
	$('#footerGalleryContainer .btnSlideUp').css({
		position:'absolute',
		textAlign:'center',
		top:'-20px',
		width:'100%'
	});
	$('#footerGalleryContent').before('<p class="btnSlideDown"><a href="#" class="down"><img src="decor/footer-pic-arrow-down.png" alt="" height="16" width="26" /></a></p>');
	$('#footerGalleryContainer .btnSlideDown').css({
		position:'absolute',
		textAlign:'center',
		top:'2px',
		width:'100%',
		zIndex:'20'
	});
	$('#footerGalleryContainer .btnSlideDown').hide();
	$('.gallery').hide();
	$('#footerGalleryContent').prepend('<h2>Photos</h2>');
	$('#footerGalleryContent h2').css({
		fontSize:'1em',
		textAlign:'center',
		textTransform:'uppercase',
		fontFamily:'Champagne Limousines Thick',
		color:'#471636'

	});
	var footerHeight = $('#footerGalleryContainer').height();
	$('#footerGalleryContainer').css({
		height:footerHeight+'px',
		top:"-"+(footerHeight+10)+"px"
	});

		/* => Gestion de l'affichage de la Gallery
		----------------------------------------- */
		$('#footerGalleryContainer .btnSlideUp').click(function(){
			$('#footerGalleryContent h2').hide();
			$('#footerGalleryContainer').animate({
				height:'53px',
				top:'-63px'
			}, 800, function(){
				$('#footerGalleryContainer .btnSlideUp').hide();
				$('#footerGalleryContainer .btnSlideDown').show();
			});
			$('.gallery').slideDown(850);
		});

		$('#footerGalleryContainer .btnSlideDown a').click(function(){
			$('#footerGalleryContainer').animate({
				top:"-"+(footerHeight+10)+"px"
			}, 400, function(){
				$('#footerGalleryContainer .btnSlideDown').hide();
				$('#footerGalleryContainer .btnSlideUp').show();
			});
			$('#footerGalleryContent h2').show();
			$('.gallery').slideUp('normal');
		});

	/* = Gestion du Menu
	---------------------------------------------------------------------------------------- */

	$(".navMain li.toggleSubMenu span").each( function () {
		var TexteSpan = $(this).text();
		$(this).replaceWith('<a href="" title="Afficher le sous-menu">' + TexteSpan + '<\/a>') ;
	} ) ;

	$(".navMain li.toggleSubMenu > a").click( function () {
		$(this).addClass("activeItem");

		if ($(this).next("ul.subMenu:visible").length != 0) {
			$(this).next("ul.subMenu").slideUp("normal");
		}
		else {
			$(this).prev('a').removeClass("activeItem");
			$(".navMain ul.subMenu").slideUp("normal");
			$(this).next("ul.subMenu").slideDown("normal");
		}
		// On empeche le navigateur de suivre le lien :
		return false;
	});
	$('.secondLevel ul').show();
	$('.secondLevel > a').click(function(){
		if($(this).next("ul:visible").length != 0) {
			$(this).next("ul").slideUp("normal");
		}
		else {
			$('.secondLevel ul').slideUp("normal");
			$(this).next('ul').slideDown("normal");
		}
		return false;
	});

	/* = Gestion des Popins
	---------------------------------------------------------------------------------------- */

	/* => Popin Image */
    //$('a.zoombox').zoombox();
    // You can also use specific options
	$('a.zoombox').zoombox({
        theme		: 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
		duration    : 800,           	// Animation duration
        animation   : true,             // Do we have to animate the box ?
        width       : 860,              // Default width
        height      : 652,              // Default height
        gallery     : false,        	// Allow gallery thumb view
        autoplay 	: false,            	// Autoplay for video
		withNav		: true
    });

	/* => Popin Html */
	$('.popinTexte').click(function(){
		$.zoombox.open('testmaquette/long_sejours_BS.html',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});

	$('.popinTexte2').click(function(){
		$.zoombox.open('testmaquette/long_sejours_HS.html',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte3').click(function(){
		$.zoombox.open('testmaquette/court_sejours_BS.html',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte4').click(function(){
		$.zoombox.open('testmaquette/court_sejours_HS.html',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte5').click(function(){
		$.zoombox.open('testmaquette/weekend_BS.html',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte6').click(function(){
		$.zoombox.open('testmaquette/contact.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte7').click(function(){
		$.zoombox.open('testmaquette/reservation.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte8').click(function(){
		$.zoombox.open('testmaquette/presse1.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte9').click(function(){
		$.zoombox.open('testmaquette/presse2.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte10').click(function(){
		$.zoombox.open('testmaquette/presse3.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte11').click(function(){
		$.zoombox.open('testmaquette/presse4.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte12').click(function(){
		$.zoombox.open('testmaquette/bkdo1.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte13').click(function(){
		$.zoombox.open('testmaquette/bkdo2.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte14').click(function(){
		$.zoombox.open('testmaquette/bkdo3.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte15').click(function(){
		$.zoombox.open('testmaquette/bkdo4.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte16').click(function(){
		$.zoombox.open('testmaquette/bkdo5.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte17').click(function(){
		$.zoombox.open('testmaquette/bkdo6.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte18').click(function(){
		$.zoombox.open('testmaquette/bkdo7.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 400,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte19').click(function(){
		$.zoombox.open('testmaquette/cheque_kdo_resa.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte20').click(function(){
		$.zoombox.open('testmaquette/cheque_kdo_resa_150.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte21').click(function(){
		$.zoombox.open('testmaquette/conditions.html',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte22').click(function(){
		$.zoombox.open('testmaquette/findannee.html',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});
	$('.popinTexte23').click(function(){
		$.zoombox.open('testmaquette/weekend_HS.html',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});

	$('.popinTexte24').click(function(){
		$.zoombox.open('testmaquette/bkdo8.php',{
			theme       : 'tendacayou',		//available themes : zoombox,lightbox, prettyphoto, darkprettyphoto, simple
			width       : 860,				// Default width
			height      : 500,				// Default height
			gallery 	: false,
			withNav		: false
		});
	});

	/* = Appel de la fonction de gestion du
	---------------------------------------------------------------------------------------- */
	mybg.init(); // En mode simple

});

mybg = {

	init : function(){
		if(gallery){
			$('.simpleBackground').remove();
			$('#footerGalleryContainer').show();
			var i=0;
			var imgBgGalleryArray = new Array();
			$('.gallery li').each(function(){
				var imgBgGallery = $(this).children('a').attr('href');
				$(this).children('a').attr({ href : '#' });
				imgBgGalleryArray[i] = imgBgGallery;
				$(this).children('a').addClass(''+i);
				i++;
			});
			$('.gallery li a.3').css('margin-right','40px');
			mybg.createGalleryBg(imgBgGalleryArray);
			$(window).resize(mybg.redim);
		} else {
			$('#footerGalleryContainer').hide();
			mybg.links = $('.simpleBackground img').attr('src');
			mybg.createSimpleBg(mybg.links);
		}
	},

	createSimpleBg : function(links){
		mybg.links = links;
		$('.simpleBackground').remove();
		$('body').append('<div class="containerBackground"><div><table cellspacing="0" cellpadding="0"><tbody><tr><td><img src="'+mybg.links+'" alt="" /></td></tr></tbody></table></div></div>');
		var trPosition = $('.containerBackground tr').offset();
		var trTop = trPosition.top;
		var imgPosition = $('.containerBackground td img').offset();
		var imgTop = imgPosition.top;
		var imgLeft = imgPosition.left;
	},

	createGalleryBg : function(imgBgGalleryArray){
		$('body').append('<div class="containerBackground"><div><table cellspacing="0" cellpadding="0"><tbody><tr><td>Galerie sous forme de background etirable</td></tr></tbody></table></div></div>');
		$('.containerBackground td').remove();
		var tabLongueur = imgBgGalleryArray.length;
		for(x=0; x<tabLongueur; x++){
			$('.containerBackground tr').append('<td class="'+x+'" style="z-index:'+(tabLongueur - x)+'"><img src="'+imgBgGalleryArray[x]+'" alt="" /></td>');
			$('.containerBackground td.'+x).css({position:'absolute', height:'100%', textAlign:'center', verticalAlign:'middle', width:'100%', top:'0'});
			mybg.redim(tabLongueur);
		}
		for(y=1; y<tabLongueur; y++){
			$('.containerBackground td.'+y+' img').css({
				left:'+'+mybg.windowW()+'px',
				position:'relative'
			});
		}
		mybg.anim(tabLongueur);
	},

	load : function(){
		if(mybg.img.complete){
			window.clearInterval(mybg.timer);
			//alert("image chargée");
			$(".containerBackground").hide();
			mybg.anim();
		}
	},

	loadImgGallery : function() {
		//if(mybg.imgGallery.complete){window.clearInterval(mybg.timer);alert("image chargée");$(".containerBackground").hide();mybg.anim();} mybg.anim(tabLongueur);
	},

	anim : function(tabLongueur){
		$(".containerBackground").fadeIn();
		// Gallery Bg
		$('.gallery li a').click(function(){
			var imgClicke = $(this).attr('class');
			mybg.nav(imgClicke, tabLongueur);
		});
	},

	nav : function(imgClicke, tabLongueur){
		var imgGalleryBgPosition = $('.containerBackground td.'+imgClicke+' img').offset();
		if(imgGalleryBgPosition.left > 0){
			$('.gallery li a').css('opacity','1');
			$('.gallery li a.'+imgClicke+'').css({
				opacity:'0.5'
			});
			$('.containerBackground td.'+(imgClicke)+' img').animate({
				left: '-'+((mybg.windowW()/mybg.windowW())-1)+'px'
			}, 1000);
			for(z=0; z<imgClicke; z++){
				$('.containerBackground td.'+z+' img').animate({
					left: '-'+mybg.windowW()+'px'
				}, 1070);
			}
		} else if(imgGalleryBgPosition.left < 0){
			$('.gallery li a').css('opacity','1');
			$('.gallery li a.'+imgClicke+'').css({
				opacity:'0.5'
			});
			$('.containerBackground td.'+(imgClicke)+' img').animate({
				left: '+'+((mybg.windowW()/mybg.windowW())-1)+'px'
			}, 1000);
			for(z=tabLongueur; imgClicke<z; z--){
				$('.containerBackground td.'+z+' img').animate({
					left: '+'+mybg.windowW()+'px'
				}, 1070);
			}
		}
	},

	redim : function(tabLongueur){
		//Dimensions
		var trHeight = $('.containerBackground tr').height();
		var tdHeight = $('.containerBackground td').height();
		var imgHeight = $('.containerBackground td img').height();
		var espaceLibre = tdHeight-imgHeight;
		// Repositionnement du top
		$('.containerBackground td.'+x).css({
			marginTop:'+'+(espaceLibre/2)+'px'
		});
	},

	windowH : function(){
		if(window.innerHeight) return window.innerHeight ;
		else {return $(window).height();}
	},

	windowW : function(){
		if(window.innerWidth) return window.innerWidth ;
		else{return $(window).width();}
	}
}


