$(document).ready(function()
{
	$(function () {
		$(".encart_cycle").carousel(
		{
			nextBtn: '<span role="button" class="bouton-suivant"><img src="../xprod/img_web/suivant.png" alt="" title="" /></span>',
			prevBtn: '<span role="button" class="bouton-precedent"><img src="../xprod/img_web/precedent.png" alt="" title="" /></span>',
			autoSlide : true,
			delayAutoSlide : 100,
			autoSlideInterval : 9000,
			dispItems : 3,
			loop: true,
			animSpeed: 2000
		});
	});
	
	$(function () {
		$(".cycle_photos").carousel(
		{
			nextBtn: '<span role="button" class="bouton-suivant-photo"><img src="../xprod/img_web/suivant_photo.png" alt="" title="" /></span>',
			prevBtn: '<span role="button" class="bouton-precedent-photo"><img src="../xprod/img_web/precedent_photo.png" alt="" title="" /></span>',
			dispItems : 5,
			loop: false,
			animSpeed: 600
		});
	});
	
	/* alternance 6 sec */
	$('#alternance6').cycle({
		fx: 'fade',speed:  300, timeout: 10000 // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
        
                        /* value btn valider newsletter */
                        $('#encart-newsletter .spip_bouton input').attr('value','ok');
	
	
	/* Ouverture des pdf dans un autre onglet */
	$('a.spip_out,a.spip_url,a.spip_documents').attr("target", "_blank");
	$("a.spip_in[href$!=spip.php]").attr("target", "_blank");
	$('a[type=application/*]').attr("target", "_blank");
	$('.lien_ext').attr("target", "_blank");
	$('.spip_documents a').attr("target", "_blank");
	
	/* rajouter le # pour l'ouverture de la box */
	$("a.link_formbox").each(function(){
		attr_href = $(this).attr('href');
		$(this).attr('href','#'+attr_href);
	}); 
	if($('span.erreur').html() == 'Ce champ doit être rempli.'){
		$("a.link_formbox").trigger('click');
	}
	

	/* initialisation animation accueil */
	$('#panel1 div a.big').css('display','none');
	$('#panel2 div a.little').css('display','none');
	$('#panel3 div a.big').css('display','none');
        
        
                        $(".carousel-wrap ul li").mouseout(function(e){
		$('#zoom_photo').css('display','none');
		$('#zoom_photo').html('');
	});
	/* réduction taille .mini_img (espace presse) */
	$('.mini_img').css('width','100px');
	$('.mini_img').css('height','');
	$('.mini_img').removeAttr('height');
        
    $("a.spip_in[href$!=spip.php]").attr("target", "_blank");
    $('a[type=application/*]').attr("target", "_blank");
    $('a.spip_out,a.spip_url,a.spip_documents').attr("target", "_blank");
    
    /* accordeon perso sur la page trophees innovation */
    $("#listing_trophees .accordion h3").click(function(){
        if($(this).hasClass('current')){
            $(this).next().css('display','none');
            $('#listing_trophees .accordion h3').removeClass('current');
        } else {
            $('#listing_trophees .accordion .pane').css('display','none');
            $(this).next().css('display','block');
            $('#listing_trophees .accordion h3').removeClass('current');
            $(this).addClass('current');
        }
    });
    /*var nb_current_h3=0;
    $("#listing_trophees .accordion h3").each(function(){
        if($(this).hasClass('current')){
            nb_current_h3++;
        }
    });
    if(nb_current_h3 ==0){
        $("#listing_trophees .accordion h3:first").addClass('current');
        $("#listing_trophees .accordion .pane:first").css('display','block');
    }*/
   $('#listing_trophees .overlay').each(function(){
       var widthOrigine = $('.left img',this).attr('width');
       var heightOrigine = $('.left img',this).attr('height');
       if(widthOrigine > 150){
           var heightNew = (150*heightOrigine/widthOrigine);
           heightNew = Math.round(heightNew);
           $('.left img',this).css('width','150px');
           $('.left img',this).css('height',heightNew+'px');
       }
   });
   $('#listing_trophees div.line').click(function(){
       $data = $(this).next('.overlay').html();
       $('#listOverlay .content').empty().html($data);
       $('#listOverlay .content .left').next().css('width','320px');
       $('#listOverlay').toggleClass('active').fadeIn();
   });
   $('#listOverlay a.trophees_close').click(function(){
       $('#listOverlay').toggleClass('active').fadeOut('fast');
   });
    /* FIN accordeon perso sur la page trophees innovation */
    
}); // fin document.ready


/* fonction appli sommaire */
function exchange(a,b){
	var contenu1 = $("#panel"+a).html();
	var contenu2 = $("#panel"+b).html();
	$("#panel"+b).html(contenu1);
	$("#panel"+a).html(contenu2);
	$('#panel1 div a.little').css('display','block');
	$('#panel1 div a.big').css('display','none');
	$('#panel2 div a.little').css('display','none');
	$('#panel2 div a.big').css('display','block');
	$('#panel3 div a.little').css('display','block');
	$('#panel3 div a.big').css('display','none');
}
function affiche(a,b){
	$("#panel"+a+" div").animate({opacity:"1"},1000);
	$("#panel"+b+" div").animate({opacity:"1"},1000);
}
function slide_salon(a,b){
	$("#panel"+a+" div").animate({opacity:"0"},1000);
	$("#panel"+b+" div").animate({opacity:"0"},1000);
	setTimeout("exchange("+a+","+b+")",1000);
	setTimeout("affiche("+a+","+b+")",1000);
}
/* fin fonction appli sommaire */





/* Détection plugin flash */
var flashinstalled = 0;
var flashversion = 0;
MSDetect = "false";
if (navigator.plugins && navigator.plugins.length){
	x = navigator.plugins["Shockwave Flash"];
	if (x){
		flashinstalled = 2;
		if (x.description){
			y = x.description;
			flashversion = y.charAt(y.indexOf('.')-1);
		}
	}
	else{flashinstalled = 1;}
	if (navigator.plugins["Shockwave Flash 2.0"]){
		flashinstalled = 2;
		flashversion = 2;
	}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length){
	x = navigator.mimeTypes['application/x-shockwave-flash'];
	if (x && x.enabledPlugin){flashinstalled = 2;}
	else{flashinstalled = 1;}
}
else{MSDetect = "true";}

function no_plugin(){
	if (flashinstalled == 1){
		document.getElementById('dl_plugin_flash').innerHTML = '<b>Ce contenu requiert le Flash Player.</b><p>Pour visionner ce contenu, la derni&egrave;re version d\'Adobe Flash Player doit &ecirc;tre install&eacute;e.</p><br /><p><a href="http://www.adobe.com/go/getflashplayer" title="T&eacute;l&eacute;chargez le Flash Player" target="_blank">T&eacute;l&eacute;chargez gratuitement Flash Player (1,83 Mo)</a></p><a target="_blank" href="http://www.adobe.com/go/getflashplayer" title="T&eacute;l&eacute;chargez le Flash Player"><img height="33" width="112" border="0" alt="T&eacute;l&eacute;chargez Adobe Flash Player" src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"/></a>';
	}
}




/* script ajouter aux favoris */
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}



///////////////////////////////////////////////////////////////////////
// imageScroller (1.1), Copyright (C) 2008 - 2009 Max Kiusso
//
// Autor :		Max Kiusso - kiussoATgmailDOTcom
// Date :		2008 12 01
// Modified:	2009 11 23
//
// REQUIRES jQuery 1.2+ <http://jquery.com/>
//
// Features:
// 		This software provide to create a multidirectional image
//		scroller with mouse events
//
// Configuration:	$( "#div" ).imageScroller( {options} )
//					
//					options:	speed (millisecond)
//								loading (text)
//								direction (left, right, top, bottom)
//
// New in release 1.1:
//		- bug fix for preload images
///////////////////////////////////////////////////////////////////////

( function( $ ) {
	$.fn.imageScroller = function ( options ) {
		return this.each( function() {
			var $this = $( this );
			var loadImgs = 0;
			
			var opt = $.extend( 
				{ 
					  speed: "2000"
					, loading: "Loading images..." 
					, direction: "left"
				}
				, options || {}
			);
			
			$this.children().hide();
			$this.append(
				"<div style='clear:both; padding: 0px; margin: 0px;'>" + 
				"<div id='loading'>" + opt.loading + "</div>" + 
				"</div>"
			);
			
			$( "img" , $this ).each(
				function () {
					var img = new Image();
					var soc = $( this ).attr( 'src' );
					
					$( img ).load(
						function () {
							loadImgs++;
						}
					).attr( "src" , soc );
				}
			);
			
			var intVal = window.setInterval(
				function () {
					if ( loadImgs == $( "img" , $this ).length ) {
						window.clearInterval( intVal );
						$( "#loading" ).remove();
						$this.children().show();
						var totImg = 0;
			
						$.each(
							  $this.children( ":not(div)" )
							, function () {
								switch ( opt.direction ) {
									case 'left':
									case 'right':
										if ( $( this ).children().length ) {
											$( this ).width( $( this ).children( ":eq(0)" ).width() );
										}
										totImg += $( this ).width();
										break;
									case 'top':
									case 'bottom':
										$( this ).css( "display" , "block" );
										if ( $( this ).children().length ) {
											$( this ).height( $( this ).children( ":eq(0)" ).height() );
										}
										totImg += $( this ).height();
										break;
								}
								
								$( this ).css({
									  margin:  "0px"
									, padding: "0px"
									, clear:   "both"
								});
								
								$( this ).bind(
									  "mouseover"
									, function () {
										$( "div:eq(0)" , $this ).stop();
									}
								).bind(
									  "mouseout"
									, function () {
										scrollStart( $( "div:eq(0)" , $this ) , opt );
									}
								);
								
								$( "div:eq(0)" , $this ).append( $( this ) );
							}
						);
						
						switch ( opt.direction ) {
							case 'left':
								$( "div:eq(0)" , $this ).css( "width" , totImg + "px" );
								break;
							
							case 'right':
								$( "div:eq(0)" , $this ).css( "width" , totImg + "px" );
								$( "div:eq(0)" , $this ).css({
									marginLeft: -( totImg - $this.width() ) + "px"
								});
								break;
								
							case 'top':
								$( "div:eq(0)" , $this ).css( "height" , totImg + "px" );
								break;
								
							case 'bottom':
								$( "div:eq(0)" , $this ).css( "height" , totImg + "px" );
								$( "div:eq(0)" , $this ).css({
									marginTop: -( totImg - $this.height() ) + "px"
								});
								break;
						}
	
						scrollStart( $( "div:eq(0)" , $this ) , opt );
					}
				}
				, 100
			);
			
			function scrollStart ( $scroll , opt ) {
				switch ( opt.direction ) {
					case 'left':
						var pos = -( $scroll.children( ":eq(0)" ).width() );
						var spd = opt.speed - ( Math.abs ( parseInt( $scroll.css( "marginLeft" ) ) ) * ( opt.speed / $scroll.children( ":eq(0)" ).width() ) );
						break;
						
					case 'right':
						var pos = -( $scroll.width() - $scroll.parents( "div:eq(0)" ).width() ) + $scroll.children( ":last" ).width();
						var spd = opt.speed - ( ( $scroll.children( ":last" ).width() - ( Math.abs ( parseInt( $scroll.css( "marginLeft" ) ) ) - Math.abs ( pos ) ) ) * ( opt.speed / $scroll.children( ":last" ).width() ) );
						break;
						
					case 'top':
						var tos = -( $scroll.children( ":eq(0)" ).height() );
						var spd = opt.speed - ( Math.abs ( parseInt( $scroll.css( "marginTop" ) ) ) * ( opt.speed / $scroll.children( ":eq(0)" ).height() ) );
						break;
						
					case 'bottom':
						var tos = -( $scroll.height() - $scroll.parents( "div:eq(0)" ).height() ) + $scroll.children( ":last" ).height();
						var spd = opt.speed - ( ( $scroll.children( ":last" ).height() - ( Math.abs ( parseInt( $scroll.css( "marginTop" ) ) ) - Math.abs ( tos ) ) ) * ( opt.speed / $scroll.children( ":last" ).height() ) );
						break;
				}
				
				$scroll.animate(
					{
						  marginLeft: ( pos || "0" ) + "px"
						, marginTop: ( tos || "0" ) + "px"
					}
					, spd
					, "linear"
					, function () {
						switch ( opt.direction ) {
							case 'left':
								$scroll.append( $( this ).children( ":eq(0)" ) );
								$scroll.css( "marginLeft" , "0px" );
								break;
								
							case 'right':
								$scroll.prepend( $( this ).children( ":last" ) );
								$scroll.css( "marginLeft" , -( $scroll.width() - $scroll.parents( "div:eq(0)" ).width() ) + "px" );
								break;
								
							case 'top':
								$scroll.append( $( this ).children( ":eq(0)" ) );
								$scroll.css( "marginTop" , "0px" );
								break;
								
							case 'bottom':
								$scroll.prepend( $( this ).children( ":last" ) );
								$scroll.css( "marginTop" , -( $scroll.height() - $scroll.parents( "div:eq(0)" ).height() ) + "px" );
								break;
						}
						
						scrollStart( $scroll , opt );
					}
				);
			};
		});
	};
})(jQuery);





/* Script pour photothèque 
function suivre_souris0(e){
	windowx = $(window).width();
	windowy = $(window).height();
	if (navigator.appName=="Netscape"){
		var x =  e.pageX;
		var y =  e.pageY;
		decal_x = 0;
		if (x+460 > windowx){decal_x = -460;}
		else {decal_x = 110;}
		left = x+decal_x;
		decal_y = 0;
		if (y+235 > windowy){decal_y = -310;}
		else {decal_y = 0;}
		top = y+decal_y;
		$('#zoom_photo').css('left',left);
		$('#zoom_photo').css('top',top);
	} else {
		left = Math.round(windowy/2);
		$('#zoom_photo').css('left',left+"px");
	}
}
*/


function open_ext_link() 
{ 
    var liens = document.getElementsByTagName('a'); 
    // On récupère tous les liens (<a>) du document dans une variable (un array), ici liens. 
    // Une boucle qui parcourt le tableau (array) liens du début à la fin. 
    for (var i = 0 ; i < liens.length ; ++i)  { 
        // Si les liens ont un nom de class égal à lien_ext, alors on agit. 
        if (liens[i].className == 'lien_ext')  { 
            liens[i].title = 'S\'ouvre dans une nouvelle fenêtre'; 
            // Au clique de la souris. 
            liens[i].onclick = function()  { 
                window.open(this.href); 
                return false; // On ouvre une nouvelle page ayant pour URL le href du lien cliqué et on inhibe le lien réel. 
            }; 
        } 
    } 
} 
window.onload = open_ext_link; 
// Au chargement de la page, on appelle la fonction.

function open_ext_link2() 
{ 
    var liens = document.getElementsByTagName('a'); 
    // On récupère tous les liens (<a>) du document dans une variable (un array), ici liens. 
    // Une boucle qui parcourt le tableau (array) liens du début à la fin. 
    for (var i = 0 ; i < liens.length ; ++i)  { 
        // Si les liens ont un nom de class égal à lien_ext, alors on agit. 
        if (liens[i].className == 'spip_in')  { 
            liens[i].title = 'S\'ouvre dans une nouvelle fenêtre'; 
            // Au clique de la souris. 
            liens[i].onclick = function()  { 
                window.open(this.href); 
                return false; // On ouvre une nouvelle page ayant pour URL le href du lien cliqué et on inhibe le lien réel. 
            }; 
        } 
    } 
} 
window.onload = open_ext_link2; 
