function swapBan(){
  var $active = $('.ban.current');
  var $next = ($('.ban.current').next().length > 0) ? $('.ban.current').next() : $('.ban:first');
  $active.fadeOut(1500,function(){
	$active.removeClass('current');
  });
  $next.fadeIn(1500).addClass('current');
}
$(document).ready(function($) {
    $('#message').hide();
    var gallery;
	var onMouseOutOpacity = 0.67;
    function makeGallery(){
			onMouseOutOpacity = 0.67;
			$('#thumbs ul.thumbs li').opacityrollover({
				mouseOutOpacity:   onMouseOutOpacity,
				mouseOverOpacity:  1.0,
				fadeSpeed:         'fast',
				exemptionSelector: '.selected'
			});
            gallery=null;
            gallery = $('#thumbs').galleriffic({
            delay:                     3000, // in milliseconds
            numThumbs:                 15, // The number of thumbnails to show page
            preloadAhead:              5, // Set to -1 to preload all images
            enableTopPager:            true,
            enableBottomPager:         true,
			defaultTransitionDuration: 500,
            maxPagesToShow:            7,  // The maximum number of pages to display in either the top or bottom pager
            imageContainerSel:         '#slideshow', // The CSS selector for the element within which the main slideshow image should be rendered
            //controlsContainerSel:      '#controls', // The CSS selector for the element within which the slideshow controls should be rendered
            captionContainerSel:       '#caption', // The CSS selector for the element within which the captions should be rendered
			onSlideChange:             function(prevIndex, nextIndex) {
				// 'this' refers to the gallery, which is an extension of $('#thumbs')
				this.find('ul.thumbs').children()
					.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
					.eq(nextIndex).fadeTo('fast', 1.0);
			},
			onPageTransitionOut:       function(callback) {
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {
				this.fadeTo('fast', 1.0);
			}
        });
    }
    $('.news_photos a').click(function(e){
        //alert($(this).attr('name'));
		if($(this).attr('name')){
			$('#sousmenu li a').removeClass('current');
			$(this).addClass('current');
            $.get('scripts/changeGallery.php',{'typePage':5,'idGalerie':$(this).attr('name')},function(data){
				/*$('ul.thumbs').empty();
                $('ul.thumbs').html(data);
				makeGallery();*/
				$('#galerieleft').fadeOut(function(){
					$('#slideshow').empty();
					$('#caption').empty();
				});
				$('#thumbs').fadeOut(function(){
					$('.pagination').empty();
					$('ul.thumbs').empty().html(data);
					if(data){
						makeGallery();
						//$('#thumbs').removeAttr('style');
						//$('#galerieleft').removeAttr('style');
						$('#thumbs').fadeIn();
						$('#galerieleft').fadeIn();
						
					}
				});
            });
			
        }
        e.preventDefault();
    });
    $('.photos a').click(function(e){
        //alert($(this).attr('name'));
        if($(this).attr('name')){
			$('#sousmenu li a').removeClass('current');
			$(this).addClass('current');
            $.get('scripts/changeGallery.php',{'typePage':1,'idGalerie':$(this).attr('name')},function(data){
				$('#galerieleft').fadeOut(function(){
					$('#slideshow').empty();
					$('#caption').empty();
				});
				$('#thumbs').fadeOut(function(){
					$('.pagination').empty();
					$('ul.thumbs').empty().html(data);
					if(data){
						makeGallery();
						//$('#thumbs').removeAttr('style');
						//$('#galerieleft').removeAttr('style');
						$('#thumbs').fadeIn();
						$('#galerieleft').fadeIn();
					}
				});
            });
			
        }
        e.preventDefault();
    });
    $('#contact_form #submit_btn').click(function(e){
        if($("#contact_form").validate().form()){
             $.get('scripts/envoisMail.php',{'nom_txt':$('#nom_txt').val(),'email_txt':$('#email_txt').val(),'tel_txt':$('#tel_txt').val(),'demande_txt':$('#demande_txt').val()},function(data){
                if(data=='true'){
					$('#contact_form input').attr('value','');
					$('#contact_form textarea').val('');
					$('#contact_form input[type=submit]').hide();
					$('#message').show();
				}
             });
             e.preventDefault();
        }
    });
	$('.ban:first-child').addClass('current');
	if ($('#thumbs li').length>0){
		makeGallery();
    }
    setInterval('swapBan()', 5000);
    //$('#zonedroite *').removeAttr('filter');
	//alert($('#galerieright').css('margin'));
});
