$(document).ready(function(){
	//Menu déroulant
	$('ul#menu1').menuBox({
        menuWi : '171'

  });

	//Lien pour nouvelle page
	$('a[class^="_blank"]').click(function(){
		window.open(this.href, '_blank');
		return false;
    });
	if( $('#liste_quietesvous').length ){
		$('#liste_quietesvous').sSelect();
		
		$('#liste_quietesvous').change(function(){
			  var obj = $("option:selected",this);
			  window.location.href = $(obj).attr("value");
		});
	
	}
	
	if( $('#liste_themes').length ){
		$('#liste_themes').sSelect();
		
		$('#liste_themes').change(function(){
			  var obj = $("option:selected",this);
			  window.location.href = $(obj).attr("value");
		});
	}
	
	if( $("a[class^='lightbox']").length ){
		$("a[class^='lightbox']").prettyPhoto({
			deeplinking : false,
			social_tools: ""
		});
	}
	
	//	Diaporama
	if( $('#slides').length ){
		$("#slides").slides({
			preload: true,
			preloadImage: 'img/loading.gif',
			play: 5000,
			slideSpeed: 500,
			generateNextPrev: false,
			generatePagination: false,
			animationStart: function(){
			    $('.fond_diaporama').hide();
			},
			animationComplete: function(current){
				$('.fond_diaporama:eq('+(current-1)+')').fadeIn();
			}
		});
		
		var wid = $(window).width()/2;
		 
		if (wid*2 > 1400) {
			lef = (wid*2-1400)/2;
			$("#slides").css({'width' : '1400px'});
			$(".slides_container").css({'width' : '1400px'});
			
			//$("#slides td").css({'margin-left' : '0px','width' : '1400px'});
		 } else {
			$("#slides").css({'left' : (wid-700)+'px','width' : ((wid*2)-(wid-700))+'px'});
			$(".slides_container").css({'width' :'1400px'});
		 }
		  
		 $(window).resize(function() {
		 var wid = $(window).width()/2;
		 if (wid*2 > 1400) {
				lef = (wid*2-1400)/2;
				$("#slides").css({'width' : '1400px'});
				//$("#slides td").css({'margin-left' : '0px','width' : '1400px'});
				$(".slides_container").css({'width' : '1400px'});
			} else {
				$("#slides").css({'left' : (wid-700)+'px','width' : ((wid*2)-(wid-700))+'px'});
				$(".slides_container").css({'width' : '1400px'});
			}
		});
	}
	
	if( ( $.browser.msie && $.browser.version >= '9.0' ) || !$.browser.msie ){
		$('.sponsorFlip').bind("click",function(){
	
			// $(this) point to the clicked .sponsorFlip element (caching it in elem for speed):
	
			var elem = $(this);
	
			// data('flipped') is a flag we set when we flip the element:
	
			if(elem.data('flipped'))
			{
				// If the element has already been flipped, use the revertFlip method
				// defined by the plug-in to revert to the default state automatically:
	
				elem.revertFlip();
	
				// Unsetting the flag:
				elem.data('flipped',false);
			}
			else
			{
				// Using the flip method defined by the plugin:
	
				elem.flip({
					direction:'lr',
					speed: 350,
					onBefore: function(){
						// Insert the contents of the .sponsorData div (hidden
						// from view with display:none) into the clicked
						// .sponsorFlip div before the flipping animation starts:
	
						elem.html(elem.siblings('.sponsorData').html());
					}
				});
	
				// Setting the flag:
				elem.data('flipped',true);
			}
		});
	}
});
