/*
**  Utilisation de la librairie jQuery
**  http://docs.jquery.com/Downloading_jQuery#Download_jQuery
*/

jQuery.noConflict();
jQuery(function($) {

    var langue = $('html').attr('lang');
    var playMusic = 1;

    //Gestion du clearInput (vide les champs texte)
    function clearInput(_item) {
        $(_item).focus(function() {
            if(this.value == this.defaultValue) {
                this.value = "";
            }
        }).blur(function() {
            if(!this.value.length) {
                this.value = this.defaultValue;
            }
        });
    }
    clearInput('.clearInput');

        //Gestion de la navigation
    $('#mainNav > li .sousNav').parent().prepend('<div id="flecheNav"></div>');
    $('#mainNav > li').find('> a').bind('mouseenter', function() {
        var widthLi = $(this).parent().width();
        var posFleche = $(this).prev().css('width', widthLi);
        if($(this).parent().is('.actif') == false) {
            var colonne = $('#mainNav li.actif');
            colonne.find('.sousNav').slideUp('fast');
            colonne.removeClass('actif');
            colonne.find('#flecheNav').hide();
            $(this).parent('li').addClass('actif').find('.sousNav').slideDown('fast').css('left', -(206-widthLi)/2);
            $(this).prev().show();
        }
    }).end()
    .bind('mouseleave', function() {
        if($(this).parent().is('.actif') == false) {
            $('#mainNav li.actif').removeClass('actif').find('.sousNav').slideUp('fast').end()
                                  .find('#flecheNav').hide();
        }
    });

    

    //Gestion du carousel (page d'accueil)
    $('#homeCarousel').carousel({
        manual: false, 
        auto: true,
        navigation: true,
        speed: 1000,
        frequency: 7000
    });
    
    //Gestion de la navigation du carousel en page d'accueil
    $('#homeCarousel').delegate('.navCarousel > a', 'click', function(e) {
        var idNav = $(this).attr('id');
        if($(this).attr('class') != 'on') {
            $('#homeCarousel .navCarousel .on').removeClass('on').addClass('off').find('img').attr('width', 60).attr('height', 40);
            $('#homeCarousel li:visible').fadeOut(0, function() {
                 $('#homeCarousel li.'+idNav).show();
            });
            $(this).removeClass('off').addClass('on').find('img').attr('width', 90).attr('height', 60);
            
        }
        e.preventDefault();
    });
    
    //Gestion des bouton liensDirect en page d'accueil
    $('#content .liensDirect').find('a').hover(
        function() {
            var imgSrc = $(this).find('img').attr('src');
            $(this).find('img').attr('src', imgSrc.replace(/.png$/ig,'-on.png'));
        },
        function() {
            var imgSrcOn = $(this).find('img').attr('src');
            $(this).find('img').attr('src', imgSrcOn.replace(/-on.png$/ig,'.png'));
        }
    );


  /****************************************************************************************
   * GESTION DEPLIAGE GENERIQUE DES BLOCS (plan du site, FAQ)
   ****************************************************************************************/

  $('.blocSlide').hide();
  
  $('a.openBlocSlide').click(function()
  {
    $(this).parent().next().slideToggle();
    return false;
  });
  
  /****************************************************************************************
   * LIENS EXTERNES
   ****************************************************************************************/

  $('.externe').click(function(){window.open($(this).attr('href'));return false;});


  $('#imgMusique').hover(
    function(){
    $(this).attr('src', '/images/bg/' + langue + '-bt-musique-on.png');
    },
    function(){
    $(this).attr('src', '/images/bg/' + langue + '-bt-musique.png');
    }
  );

  function loadSwfVideo(pId, pFlv){
    if ($("#"+pId).length) {
      var flashparams = {
      bgcolor: "#fffffff"
      };
      var flashvars = {
        configxml: "/swf/configxml.xml",
        flv: pFlv
      };
      swfobject.embedSWF("/swf/player_flv_maxi.swf", pId, "630", "412", "9.0.0", "/swf/playerProductInstall.swf", flashvars, flashparams);
    }
  }



  $('.callPrint').click(function(e){
    e.preventDefault();
    $('.article').find('.print').removeClass('print');
    $(this).parents('.subArticle').addClass('print');
    window.print(this.href);
  });

  $('#photosMin').find('a').hover(function(e){
    e.preventDefault();
    var src = $(this).find('img').attr('src');
    $('#photoMax').find('img').attr('src', src.replace(/_mini/ig,'_middle'));
  });

  function openMusique(time)
  {
    if($.cookie('meridionaleMusique')!='1')
    {
      window.open('/lecteurAudio.php','LecteurAudio','resizable=no, location=no, menubar=no, status=no, scrollbars=no, width=430, height=110');
      $.cookie('meridionaleMusique','1',3600);
    }
  }

  if($('#indexAccueil').length){
    openMusique();
  }

}); /* jQuery end */

