
// lance le diaporama
$('#diaporama').cycle();
$('#loader').show();
$('#diaporama').cycle('stop');
	$('#loader').show();
	var poli='stcroix';
	var aleatoire1 = Math.random()*99999;
	var aleatoire2 = Math.random()*99999;
	
	var chemin1 = $('#diaporama img').eq(0).attr('src');
	var chemin2 = $('#diaporama img').eq(1).attr('src');
	
	$('<img/>').attr('src', chemin1+'?' + aleatoire1).load(function ()
	{
		checkFinal(); 
	}); 
	$('<img/>').attr('src', chemin2+'?' + aleatoire2).load(function () {
     	 checkFinal(); 
	}); 
         $('#loader').show();
	var loaded = 0; 
	function checkFinal()
	{ 
		loaded++; 
        // lorsque les 2 images sont chargées
        if(loaded == 2)
		{ 
		  	$('#diaporama').cycle();$('#loader').hide();
		}
	}


// changement des diaporamas

$("#bobine a").click(function()
{ 
	$('#diaporama').cycle('stop');
	$('#loader').show();
	var poli=$(this).attr('name');
	var aleatoire1 = Math.random()*99999;
	var aleatoire2 = Math.random()*99999;
	
	$('<img/>').attr('src', 'images/diaporamas/'+poli+'/1.jpg?' + aleatoire1).load(function ()
	{
		checkFinal(); 
	}); 
	$('<img/>').attr('src', 'images/diaporamas/'+poli+'/2.jpg?' + aleatoire2).load(function () {
     	 checkFinal(); 
	}); 
         
	var loaded = 0; 
	function checkFinal()
	{ 
		loaded++; 
        // lorsque les 2 images sont chargées
        if(loaded == 2)
		{ 
		  	$('#diaporama').cycle('destroy');
				$('#legende-diaporama').load('diaporama.php?id='+poli+' #description');
			$('#diaporama').load('diaporama.php?id='+poli+' #diaponly' , {rand1: aleatoire1}, function ()
			{
				
				$('#diaporama').cycle({ slideExpr: 'img' });$('#loader').hide();
			}); 
		}
	}
	return false; 
});


$(".prodspecial a").click(function()
{ 
	$('#diaporama').cycle('stop');
	$('#loader').show();
	var poli=$(this).attr('name');
	var aleatoire1 = Math.random()*99999;
	var aleatoire2 = Math.random()*99999;
	
	$('<img/>').attr('src', 'images/diaporamas/'+poli+'/1.jpg?' + aleatoire1).load(function ()
	{
		checkFinal(); 
	}); 
	$('<img/>').attr('src', 'images/diaporamas/'+poli+'/2.jpg?' + aleatoire2).load(function () {
     	 checkFinal(); 
	}); 
         
	var loaded = 0; 
	function checkFinal()
	{ 
		loaded++; 
        // lorsque les 2 images sont chargées
        if(loaded == 2)
		{ 
		  	$('#diaporama').cycle('destroy');
				
			$('#diaporama').load('diaporama.php?id='+poli+' #diaponly' , {rand1: aleatoire1}, function ()
			{
				$('#legende-diaporama').load('diaporama.php?id='+poli+' #description', function ()
			{
				 $('#legende-diaporama').fadeIn();
			
			}); 
				$('#diaporama').cycle({ slideExpr: 'img' });$('#loader').hide();
			}); 
		}
	}
	return false; 
});

$('#ensavoirplus').mouseenter(function() {
 
    $('#legende-diaporama').fadeIn();	$('#sermux').animate({"left":-145});


});

$('#travaux #legende-diaporama[class!="retractable"]').mouseleave(function() {
$('#sermux').animate({"left":0});
    $('#legende-diaporama').fadeOut(); });







// masque certains éléments au chargement
function masqueElements()
{
	$('.fading-description').css("height","0");
$('#legende-diaporama').hide();
$('#loader').hide();

$('.form-container').hide();
$('.form-an').show();



}




// bloc news

$('#bloc-news img:eq(1)').hide();
function animNews()
{
	$('#bloc-news img:eq(1)').animate({margin: '0'}, 4000,function()
	{
    	$("#news-2").css("background","#fff");$("#news-1").css("background","#e1e6ea");
		$("#fleche-news").animate({'top':'115px'});
		$('#bloc-news img:eq(1)').show();
	});
	$('#bloc-news img:eq(1)').animate({margin: '0'}, 4000,function()
	{
		$("#news-2").css("background","#e1e6ea");$("#news-1").css("background","#fff");
		$("#fleche-news").animate({'top':'30px'});
		$('#bloc-news img:eq(1)').hide();
	});
}


$(document).ready(function()
{
	
	
	
	// diaporama des bornes
	
	
	$('#borne').cycle({ 
					  
   
	pause:         true      
});
	
	   $('#borne span').hide();
	   $('#bornechef span').hide();
	
	$("#borne ").hover(function() {
        $('#borne img:visible').parents('p').find('span').slideDown();
        }, function () {
      $('#borne img:visible').parents('p').find('span').slideUp();
        });
	
	
		$("#bornechef").hover(function() {
        $(this).find('span').slideDown();
        }, function () {
     $(this).find('span').slideUp();
        });
	
	
	   $('#dg div p').hide();
	
	$("#dg div").hover(function() {
        $(this).find('p').slideDown();
        }, function () {
      $(this).find('p').slideUp();
        });
	
	
	
	// masque certains éléments au chargement
	masqueElements();

	
$("#onglet").toggle(
function () {$('#sermux').animate({"left":-145});},
function () {$('#sermux').animate({"left":0});}
); 

	


	// affiche les 4 panneaux sur la page d'accueil
	$("#quatre-rubriques img:eq(0), #menu-groupe, #menu-secondaire li:eq(0)").hover(function() {
        $(".premiere").stop().animate({'height':'347px'});
        }, function () {
        $(".premiere").stop().animate({'height':'0'});
        });
	$("#quatre-rubriques img:eq(1), #menu-travaux, #menu-secondaire li:eq(1)").hover(function() {
        $(".deuxieme").stop().animate({'height':'347px'});
        }, function () {
        $(".deuxieme").stop().animate({'height':'0'});
        });
	$("#quatre-rubriques img:eq(2), #menu-industries, #menu-secondaire li:eq(2)").hover(function() {
        $(".troisieme").stop().animate({'height':'347px'});
        }, function () {
        $(".troisieme").stop().animate({'height':'0'});
        });
	$("#quatre-rubriques img:eq(3), #menu-bureau, #menu-secondaire li:eq(3)").hover(function() {
        $(".quatrieme").stop().animate({'height':'347px'});
        }, function () {
        $(".quatrieme").stop().animate({'height':'0'});
        });
		
	// animation du panneau au chargement de la page
	$(' body[class!=paspanneau] #panneau ul').delay(3000).animate({top: '35px'}, 400, 'swing');
			
	$(' body[class=paspanneau] #panneau ul').hover(function() {
        $(this).animate({top: '35px'});
        }, function () {
        $(this).animate({top: '330px'});
        });


// rollover sur le panneau
	$("#panneau ul li:eq(0)").hover(
		function () {$('#panneau ul').css("backgroundPosition", "-154px 0")},
		function () {$('#panneau ul').css("backgroundPosition", "0 0")}
	);			
	$("#panneau ul li:eq(1)").hover(
		function () {$('#panneau ul').css("backgroundPosition", "-308px 0")},
		function () {$('#panneau ul').css("backgroundPosition", "0 0")}
	);			
	$("#panneau ul li:eq(2)").hover(
		function () {$('#panneau ul').css("backgroundPosition", "-462px 0")},
		function () {$('#panneau ul').css("backgroundPosition", "0 0")}
	);			
	$("#panneau ul li:eq(3)").hover(
		function () {$('#panneau ul').css("backgroundPosition", "-616px 0")},
		function () {$('#panneau ul').css("backgroundPosition", "0 0")}
	);			
	$("#panneau ul li:eq(4)").hover(
		function () {$('#panneau ul').css("backgroundPosition", "-770px 0")},
		function () {$('#panneau ul').css("backgroundPosition", "0 0")}
	);			
	$("#panneau ul li:eq(5)").hover(
		function () {$('#panneau ul').css("backgroundPosition", "-924px 0")},
		function () {$('#panneau ul').css("backgroundPosition", "0 0")}
	);			
	$("#panneau ul li:eq(6)").hover(
		function () {$('#panneau ul').css("backgroundPosition", "-1078px 0")},
		function () {$('#panneau ul').css("backgroundPosition", "0 0")}
	);			
	$("#panneau ul li:eq(7)").hover(
		function () {$('#panneau ul').css("backgroundPosition", "-1232px 0")},
		function () {$('#panneau ul').css("backgroundPosition", "0 0")}
	);	
	
	// bloc news
	setInterval('animNews();',2000); 


$("#postuler").toggle(
		function () {$('.form-container').slideDown()},
		function () {$('.form-container').slideUp()}
	);		

$("#organigramme td:not(:empty)").hover(
		function () {$(this).css({'font-size' : '14px', 'backgroundColor' : '#fee000', 'width' : '210px'})},
		function () {$(this).css({'font-size' : '9px', 'backgroundColor' : '', 'width' : '110px'})}
	);	



// flèche de scroll bobine

$("#bobscro").mouseover(function()
{ 

$('#bobine').scrollTo( {top:800, left:0}, 800);
});
$("#monter").mouseover(function()
{ 

$('#bobine').scrollTo( {top:0, left:0}, 800);
});




$("table:nth-child(odd)").addClass("zebra");

//// rajout CLE
		$("#cartesuisse").fancybox({
				'width'				: 1050,
				'height'			: 575,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
		
			$("#postuler-an").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'width'				: 800,
				'height'			: 575,
				'type'				: 'iframe'

			});
			
			
				/// menu des pages emploi en accordeons
			
			$( ".sections" ).accordion({
			autoHeight: false ,
			collapsible: true,
			active: false,
			icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' }
		});
			
			
			$("a.lienpdf").fancybox({
				'width'				: 800,
				'height'			: '90%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
			
			
			
		
//// fin ///


});
