/*
# UTéF8
*/
var delay = 2000;
var timeout = 5000;
var i = 0;
var a = null;

function nextEl ( posEl ) {
			///////////return;//////// 
	clearTimeout(a);
	
	//var posEl = $(e.currentTarget).data('position'); IE semble ne pas récupérer correctement les data via cette méthode
	
	if ( posEl != i ) {
		i = posEl;
	}
			
	if(parseInt(jQuery.browser.version) == '6') {
		$('#onglets li.selected a').css('background-position', '0 0');
	}	
	$('#onglets')
		.find('.selected')
			.removeAttr('class')
		.end()
		.find('li:eq('+posEl+')')
			.addClass('selected');
	
	if(parseInt(jQuery.browser.version) == '6') {
		$('#onglets li.selected a').css('background-position', '0 -23px');
	}	
	
	$('#img_slideshow img:visible, #content_legend p:visible').fadeOut( delay );
	$('#img_slideshow img:eq('+posEl+'), #content_legend p:eq('+posEl+')').fadeIn( delay );
	
	a = setTimeout( function () {
			i = i == 6 ? 0 : ++i ;
			$('#onglets li a:eq('+i+')').trigger('click');
			$('#bt_savoir_plus').attr({href:$('#onglets li a:eq('+i+')').attr('href')});
			
	}, timeout );
				
}


function defil(maxscroll) {
// return;
		if(!maxscroll){ // il faut le definir en poussant le scroll a donf et il retournera sa valeur maxi
		$('#lmz').scrollLeft(20000);
		t_defil=setTimeout('defil('+$('#lmz').scrollLeft()+')',10);
		// on rembobine :)
		$('#lmz').scrollLeft(0);
		return;
		}
		
	clearTimeout(t_defil);
	var decal=2 , delai=30 ; ;
		if($.browser.msie) delai= Math.round(delai*0.78);
	var scrollLeft=$('#lmz').scrollLeft();
		if(scrollLeft>=maxscroll){
		$('#lmz').scrollLeft(0);
		} else {
			$('#lmz').scrollLeft(scrollLeft+decal);
		}
	
	t_defil=setTimeout('defil('+maxscroll+')',delai);

}


$(function() {
  
  	//Quelques fix pour IE
	if($.browser.msie){
		
		//Fix CSS pour IE6/7
		$('.presentation dl:last-child, #footer li:first-child').css('background', 'none');
		$('.news_content:last-child').css({background:'none', margin : '0'});
		
		/*if ( $('ul.missions').length ) {
			var l = $('ul.missions li').length;
			$('ul.missions li').each( function (i) {
				$(this).css({'z-index':l-i, 'background':'none'});
			}); 
		}*/
		
		//Fix png pour IE6
		if(parseInt(jQuery.browser.version) == '6') {
			DD_belatedPNG.fix('.btn_savoir_plus, #onglets li a')	
		}
		
	};

});


$(document).ready(function() {

	/* *** detection version FlashPlayer 
			+ suppression bordures de flash sur IE et OPERA *** */
	// déclaration de la version demandée
	navigator.NeedFlashVersion=7;
	
	
	navigator.NeedFlash=false; //retounera false ou le nbre de swf trouvés
	navigator.FlashVersion=0;
	navigator.CanPlayFlashPlayer=false;
	
	if( document.getElementsByTagName ){ // DOM
	var of=document.getElementsByTagName('object'); var nf=of.length;
		for (var i=0;i<nf;i++){
		var source=of[i].innerHTML;
			if(!(/\.swf["?]/gi.test(source))) continue;
		of[i].AllowScriptAccess = "always";
			if( !navigator.NeedFlash ){
			navigator.NeedFlash=0;
				try{
				navigator.FlashVersion=parseInt(navigator.plugins["Shockwave Flash"].description.match(/[0-9]+[.,]/));
				}catch(e){
					try{
					var ie_vers=of[i].GetVariable("$version");
					navigator.FlashVersion=(parseInt(ie_vers.match(/[0-9]+[.,]/)));
					}catch(e){}
				}
			}
		navigator.NeedFlash++;
		}
	// affichage info utilisateur
		if(navigator.NeedFlash && navigator.FlashVersion<navigator.NeedFlashVersion){
		navigator.CanPlayFlashPlayer=false;
		/* ** 
		rien ne s'affichera si :
		- pas de flash dans la page
		- navigator.FlashVersion = NaN ou Undefined ou est bonne :)
		- la classe NeedFlashVersion est à display none :)
		** */
		var div=document.createElement('DIV');
		div.className='NeedFlashVersion';
		div.innerHTML='You need to upgrade your Flash Player';
		document.body.appendChild(div);
		}else{
		navigator.CanPlayFlashPlayer=true;
		}
	}
	/* *** FIN detection version FlashPlayer *** */

})/* FIN doc.ready*/


$(window).load(function () {
	
	
    $('#img_slideshow img:first-child, #content_legend p:first-child, #ref_diaporama div:first-child').css('display', 'block');
	
	$('#onglets li a').each( function (i) {
									  if(i==0) $('#bt_savoir_plus').attr({href:$(this).attr('href')});
		
		$(this).data( 'position', i );

		$(this).bind( 'click', function() {
			nextEl($(this).data('position'));
			$('#bt_savoir_plus').attr({href:$(this).attr('href')});
			return false;
		});
		
	});
			
	i++;
	a =  setTimeout( function () {
		$('#onglets li a:eq('+i+')').trigger('click');
	}, 5000);
	
	defil();
	
	/*Comportement du menu principal*/
	$('#main_menu > li').hover( 
		function () {
			var $targetul = $(this).children("ul:eq(0)");
			// $targetul.css('display', 'block');
			$targetul.slideDown(250);
		},
		function () {
			var $targetul=$(this).children("ul:eq(0)");
			//$targetul.css('display', 'none');
			$targetul.slideUp(150);
		}
	);
	
	/*Diaporama des logos de la page d'accueil*/
	if ( $('#ref_diaporama').length ) {
		$('#ref_diaporama a:first-child').css('display', 'block');
		$('#ref_diaporama').fade({ timeout : 2000 });
	}
	
	/*News défilante de la page d'accueil*/
	$('#scroll_bottom').click( function() {
	
		var container = $('#scroll_container');
		var oldTop = parseInt( container.css('top') );
		
		if( oldTop <= (container.height()-224)*-1 ) { 
		
			return false;
			
		};
		
		container.css( 'top', (oldTop-20)+'px' );
		return false;
	
	});
	$('#scroll_top').click( function() {
	
		var container = $('#scroll_container');
		var oldTop = parseInt( container.css('top') );
		
		if( oldTop >= 0 ) { 
			
			container.css( 'top', '0px' );
			return false
			
		};
		
		container.css( 'top', (oldTop+20)+'px' );
		return false;
	
	});
	
	/*Comportement du selecteur de langue*/
	$('#lang_selector').hover( function() {
		$('#lang_selector .not_selected').css('display', 'block');
	}, function() {
		$('#lang_selector .not_selected').css('display', 'none');
	});
	
	/*Infobulles de la page notre mission*/
	/*if ( $('#metierbulles ol').length ) {
	
		$('#metierbulles ol').hover( function() { 
			$(this).next('ol').show(); 
		}, function() {
			$(this).next('ol').hide(); 
		});
	
	}
	*/
	if ( $('#metierbulles ol li').length ) {
			var l = $('#metierbulles ol li').length;
			$('#metierbulles ol li').each( function (i) {
				$(this).css({'z-index':l-i});
			});
		};
	
	$('#metierbulles ol > li').hover( 
		function () {
			var $targetul = $(this).children("i:eq(0)");
			$targetul.css('display', 'block');
		},
		function () {
			var $targetul=$(this).children("i:eq(0)");
			$targetul.css('display', 'none');
		}
	);
	/*fIN Infobulles de la page notre mission*/
	
	/*Infobulles de la page produits*/
	if ( $('.map_avion').length ) {

		$('.map_avion a').hover( 
			function() {
				$("img", $(this) ).css('visibility', 'visible');
				$(this).next().css('display', 'block');
			},
			function() {
				$("img", $(this) ).css('visibility', 'hidden');
				$(this).next().css('display', 'none');
			}
		);
	}
	
	/*Infobulles de la page services*/
	if ( $('.map_services').length ) {

		$('.map_services a').hover( 
			function() {
				$(this).next().css('display', 'block');
			},
			function() {
				$(this).next().css('display', 'none');
			}
		);
	}
	
	/*Lightbox des pages actualités*/
	if ( $('.colRight_actualitesInfosRight').length ) {
	
		$('a[rel*=lightbox]').lightBox();
		
	}
	
	/*Diaporama des pages nos-implantations-site*/
	if ( $('#gallery_site').length && $('#gallery_site img').length > 1 ) {
	 	$('#gallery_site img:first-child').css('display', 'block')
		$('#gallery_site').fade({ timeout : 2000 });
	}
	
	/*Diaporama des pages produits*/
	if ( $('#gallery_produit').length && $('#gallery_produit img').length > 1 ) {
		$('#gallery_produit div:first-child').css('display', 'block')
		$('#gallery_produit').fade({ timeout : 2000 });
	}
});

	/* traitement fromulaire "f" */
String.prototype.trim = function() {return this.replace(/(^\s*)|(\s*$)/g,'');}
function ismail(mail){return (/^([a-z_0-9\.-]+)@([a-z_0-9\.-]+)\.([a-z]{2,5})$/).test(mail);}
function ismail_nl(mail){return (/^([a-z_0-9\.-]+)@([a-z_0-9\.-]+)\.([a-z]{2,5})$/).test(mail);}
function Fwrite(str){document.write(str);}
function change_url(str){location=str;}


function verifForm(o){
	if( mess=verif(o) ){
	alert(mess);
	return false;
	}else{
	return true;
	}
}

function verif(o){
// return false;
var n=o.elements.length;
	for(var i=0;i<n;i++){
	var V, elmt = o.elements[i], v__mess, v__name;
		switch (elmt.type) {
		case 'text' :
		case 'password' :
		case 'textarea' :
		elmt.value=elmt.value.trim();
		}
		if( V=elmt.className.match(/(^| )(v__\w+)/) ){
			v__name=V[2];
			v__mess=o[V[2]].value;
			
			switch(v__name){
				case 'v__empty' : 
					if( elmt.value=='' ) { return v__mess;};break;
				
				case 'v__mail' : if( !ismail(elmt.value) ) {return v__mess; };break;
				
				default :
				
			}
		}
	}
return false;
}

