$(document).ready(function(){
	// Rollover sur le menu principal
	function toggleImg(elt){
		$(elt).hover(
			function(){
				if($(this).attr("src").indexOf("_a.jpg") == -1) {
					var newSrc = $(this).attr("src").replace(".jpg","_a.jpg");
					$(this).attr("src",newSrc);
				}
			},
			function(){
				if($(this).attr("src").indexOf("_a.jpg") != -1) {
					var oldSrc = $(this).attr("src").replace("_a.jpg",".jpg");
					$(this).attr("src",oldSrc);
				}
			}
		);
	}

	function toggleActive(img){
		if($(img).attr("src").indexOf("_a.jpg") != -1) {
		} else {
			var oldSrc = $(img).attr("src").replace(".jpg","_a.jpg");
			$(img).attr("src",oldSrc);
		}
	}
	function toggleInactive(img){
		if($(img).attr("src").indexOf("_a.jpg") != -1) {
			var oldSrc = $(img).attr("src").replace("_a.jpg",".jpg");
			$(img).attr("src",oldSrc);
		} else {
		}
	}

	//hover pour le menu principal
	toggleImg("#top_menu ul li a img");

	//hover pour la page galerie
	$("#sub1 a img").click( function() {
		toggleActive("#sub1 a img");
		toggleInactive("#sub2 a img");
		toggleInactive("#sub3 a img");
		toggleInactive("#sub4 a img");
		$("#videos").hide();
	} );
	$("#sub2 a img").click( function() {
		toggleActive("#sub2 a img");
		toggleInactive("#sub1 a img");
		toggleInactive("#sub3 a img");
		toggleInactive("#sub4 a img");
		$("#videos").show();
	} );
	$("#sub3 a img").click( function() {
		toggleActive("#sub3 a img");
		toggleInactive("#sub1 a img");
		toggleInactive("#sub2 a img");
		toggleInactive("#sub4 a img");
		$("#videos").hide();
	} );

	$("#sub4 a img").click( function() {
		toggleActive("#sub4 a img");
		toggleInactive("#sub1 a img");
		toggleInactive("#sub2 a img");
		toggleInactive("#sub3 a img");
		$("#videos").hide();
	} );

	// Scroll pour la page galerie
	$('#sections').serialScroll({
		items:'li.scrollzone',
		navigation:'#nav ul li',
		force:true,
		constant:false
	});

	// Carousel pour l'accueil
	$(function() {
	    $(".carousel").jCarouselLite({
	        btnNext: ".next",
	        btnPrev: ".prev",
    		visible: 5,
    		auto: 1400,
    		speed: 1400,
    		scroll: 4,
			vertical:true
	    });
	});

	// Galleria
	jQuery(function($) {
			$('.galleria').addClass('gallery_demo'); // adds new class name to maintain degradability

			$('ul.gallery_demo').galleria({
				history   : true, // activates the history object for bookmarking, back-button etc.
				clickNext : true, // helper for making the image clickable
				insert    : '#main_image', // the containing selector for our main image
				onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes

					// fade in the image & caption
					if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
						image.css('display','none').fadeIn(1000);
					}
					caption.css('display','none').fadeIn(1000);

					// fetch the thumbnail container
					var _li = thumb.parents('li');

					// fade out inactive thumbnail
					_li.siblings().children('img.selected').fadeTo(500,0.6);

					// fade in active thumbnail
					thumb.fadeTo('fast',1).addClass('selected');

					// add a title for the clickable image
					image.attr('title','Next image >>');
				},
				onThumb : function(thumb) { // thumbnail effects goes here

					// fetch the thumbnail container
					var _li = thumb.parents('li.thmb');

					// if thumbnail is active, fade all the way.
					var _fadeTo = _li.is('.active') ? '1' : '0.6';

					// fade in the thumbnail when finnished loading
					thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);

					// hover effects
					thumb.hover(
						function() { thumb.fadeTo('fast',1); },
						function() { _li.not('.active').children('img').fadeTo('fast',0.6); } // don't fade out if the parent is active
					)
				}
			});
		});

	// Calcul tarifs

});
