//jQuery's noConflict mode
jQuery.noConflict();
//extension de Jquery pour trouver les positions d'un élément.
jQuery.fn.extend({
  findPos : function() {
       var obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
     curleft += obj.offsetLeft
         curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
  }
});


jQuery(document).ready(function(){
    
     //new mainNav rewriting
    jQuery('#mainNav ul.first li a').not('.no-second a').each(function(){
        jQuery(this).after( jQuery('#mainNav ul.second.'+jQuery(this).parent().attr('id')));
    });
    
    jQuery('#leftNav ul.first li a').not('.no-second a').each(function(){
        jQuery(this).after( jQuery('#leftNav ul.second.'+jQuery(this).parent().attr('id')));
    });
    
    jQuery('#leftNav ul.second li a').not('.no-third a').each(function(){
        jQuery(this).after( jQuery('#leftNav ul.third.'+jQuery(this).parent().attr('id')));
    });
    
    
  jQuery('.hover').hover(
    function (){
      hoverIn(this);
    },
    function (){
      hoverOut(this);
    }
  );

  jQuery('.slideNav').hover(
    function (){
      hoverIn(jQuery(this).children('.hover'));
    },
    function (){
      hoverOut(jQuery(this).children('.hover'));
    }
  );
  jQuery('#mainNav .home').hover(
    function (){
      hoverIn(jQuery(this).children('.hover'));
    },
    function (){
      hoverOut(jQuery(this).children('.hover'));
    }
  );

  jQuery('.hover').each(function (){
      hoverOut(this);
    }
    );

  jQuery('.hideMe').each(hideMe);
  jQuery('.empty').html('');
  jQuery('input.empty').attr('value',' ');

  jQuery('.emptyMe').focus(emptyMe);
  jQuery('.emptyMe').blur(fullMe);

  //Insertion de coin arrondi  (chemin CSS, bordure : tl tr br bl, tous les navigateurs)
  //jQuery('.selectStyled').corner('8px');

  //On gère le menu principal
  jQuery('#mainNav ul.first li ul.second').hide();

  jQuery('#mainNav ul.first li').hover(function(){
    jQuery(this).parent().children('li').children('ul.second').hide();
    jQuery(this).children('ul.second').show();
    jQuery(this).addClass('on');
  },function(){
    jQuery(this).removeClass('on');
  });
  jQuery('#mainNav').hover(function(){},function(){
    jQuery(this).children('ul.first').children('li').children('ul.second').hide();
    jQuery(this).removeClass('on');
    jQuery('#mainNav ul.first').removeClass('lastOn');
  });

  //~ jQuery('#mainNav ul.first li.last').hover(function(){
    //~ jQuery('#mainNav ul.first').addClass('lastOn');
  //~ },function(){
    //~ jQuery('#mainNav ul.first').removeClass('lastOn');
  //~ });

  //on gère le slideshow avec image
  setTimeout('fillRgThumbnail();',1000);

  //gestion du hover sur la liste des news
  jQuery('.page #content .newsList .newsSingle a.newsImg').hover(
      function(){jQuery(this).next('.newsInfo').toggleClass("hover");},
      function(){jQuery(this).next('.newsInfo').toggleClass("hover");}
  )

  //gestion du hover sur la liste sumBloc dans les page intérieurs de premier niveau
  jQuery('.page #content .sumBloc .imgBloc').hover(
      function(){jQuery(this).next('.sumContent').toggleClass("hover");},
      function(){jQuery(this).next('.sumContent').toggleClass("hover");}
  )
  jQuery('.yearTab ul li').hover(
      function(){jQuery(this).toggleClass("hover");},
      function(){jQuery(this).toggleClass("hover");}
  )

//affichage du LocationFinder
  jQuery('.page .locationFinder ').css({
      'position'  : 'absolute',
      'top'       : '35px',
      'left'      : '0px'
  });
  jQuery('.page .locationFinder ').hide();

  jQuery('.locationFinderBtn').click(function(){jQuery('.page .locationFinder ').slideToggle();jQuery('.page .finderBox ').slideUp();});


  //affichage du finder
  jQuery('.page .finderBox ').css({
      'position'  : 'absolute',
      'top'       : '35px',
      'left'      : '0px'
  });
  jQuery('.page .finderBox ').hide();

  jQuery('.finderBtn').click(function(){jQuery('.page .finderBox ').slideToggle();jQuery('.page .locationFinder ').slideUp();});
  jQuery('.finderFor').click(function(){jQuery('.page .finderBox ').slideToggle();jQuery('.page .locationFinder ').slideUp();});
  jQuery('.finderBrowser .hidePanel').click(function(){jQuery('.page .finderBox ').slideToggle();});
  jQuery('.finderFooter .hidePanel').click(function(){jQuery('.page .finderBox').slideToggle();});
  jQuery('.finderSubmit .hidePanel').click(function(){jQuery('.page .finderBox').slideToggle();});

  jQuery('#footer .footerSelect').styleIt({
      selectWidth : 174,
      selectWPadding : 5,
      selectHeight : 24,
      selectHPadding : 3,
      listWidht : 162
  });

  jQuery('#footer .footerSelect').click(function() {jQuery(this).siblings('ul').toggle();});

  
  
  
  jQuery('#content .formSelect').styleIt({
      selectWidth     : 200,
      selectWPadding  : 5,
      selectHeight    : 22,
      selectHPadding  : 3,
      listWidht       : 191,
      wrap            : 1
  });


  

  if (jQuery.browser.msie && jQuery.browser.version < 7) {
//~
        //gestion du hover sur la liste des news
  jQuery('.page #content .newsList .newsSingle a.newsInfo').hover(
      function(){jQuery(this).toggleClass("hover");},
      function(){jQuery(this).toggleClass("hover");}
  )
//~ //~
  //gestion du hover sur la liste sumBloc dans les page intérieurs de premier niveau
  jQuery('.page #content .sumBloc .sumContent').hover(
      function(){jQuery(this).toggleClass("hover");},
      function(){jQuery(this).toggleClass("hover");}
  )
  }

  if (!jQuery.browser.msie) {
      jQuery('input[type=radio]').styleIt({
          radioWidth : 12,
          radioHeight : 12
      });
        jQuery('.browserSelect').styleIt({
      selectWidth : 100,
      selectWPadding : 5,
      selectHeight : 24,
      selectHPadding : 3,
      listWidht : 90
  });
  }
    jQuery('input[type=radio]').change(function(){
        jQuery(this).parent('p').addClass('selected');
        jQuery(this).parent('p').siblings('.selected').removeClass('selected');
        jQuery(this).parent('p').parent('div').siblings('div').children('.selected').removeClass('selected');
    });


    //diaporama
    slideQuickAccess();
    slidePublications();
});

/*****
****** Fonctions  Génériques qui gère  le hover des images de class '.hover'qui gère  le hover des images de class '.hover'
*****/
function fillRgThumbnail(){
  jQuery('.SS_withTumbnail .rgslideshow .rgsnest').removeAttr('style');
  var tabImg = new Array();
  jQuery('.SS_withTumbnail #slideshownewsteaser a img').each(function(){
    tabImg.push(jQuery(this).parent().html());
  });
  var cpt=0;
  jQuery('.SS_withTumbnail .rgslideshownav .rgsnav2 .rgsbrowser .rgsbrowserEl').each(function(){
    jQuery(this).html(tabImg[cpt]);
    jQuery(this).children('img').removeAttr('style');
    cpt++;
  });
  tabImg = new Array();
}

/*****
****** Fonctions  Génériques qui gère  le hover des images de class '.hover'qui gère  le hover des images de class '.hover'
*****/
function hoverIn(el){
   if(!jQuery(el).hasClass('active')){
      var srcName = jQuery(el).attr('src');
    srcName = srcName.replace('off','over');
    jQuery(el).attr({src:srcName});
   }
}

function hoverOut(el){
   if(!jQuery(el).hasClass('active')){
    var srcName = jQuery(el).attr('src');
    srcName = srcName.replace('over','off');
    jQuery(el).attr({src:srcName});
   }
}

/*****
****** Fonction  Générique qui cache les champs
*****/
function hideMe(){
   jQuery(this).hide();
}



/*****
****** Fonctions  Génériques qui vide et reremplit les éléments de formulaire
*****/
var tmp_empty='';
function emptyMe(){
   tmp_empty = jQuery(this).val();
  jQuery(this).val('')
}
function fullMe(){
   if(jQuery(this).val()=='')
      jQuery(this).val(tmp_empty);
}



/*****
****** Fonctions  gérant le slide show quickAccess
*****/
  // gestion du diaporama



var slideWidth_QuickAccess  =190;
var blocWidth_QuickAccess   =960;
var blocNbr_QuickAccess     =1;
var nbrContent_QuickAccess  =0;
var blocFound_QuickAccess   =0;
var numShow_QuickAccess     =0
var title_QuickAccess       = '';

function slideQuickAccess(){

  jQuery('.quickAccessSlide ul li').each(function(i){
    blocFound_QuickAccess++;
  });

  nbrContent_QuickAccess = Math.ceil((blocFound_QuickAccess/blocNbr_QuickAccess));
  jQuery('.quickAccessSlide ul').width( (slideWidth_QuickAccess*nbrContent_QuickAccess) );

  //~ if (blocFound_QuickAccess == 5){
      //~ jQuery('.quickAccessSlide a.slideNav.prev').css('visibility','hidden');
      //~ jQuery('.quickAccessSlide a.slideNav.next').css('visibility','hidden');
  //~ }

  if (nbrContent_QuickAccess > 1){

    jQuery('.quickAccessSlide a.slideNav.prev').click(
      function(){
        if (numShow_QuickAccess > 0){
          jQuery(".quickAccessSlide ul").animate({"left": "+="+slideWidth_QuickAccess+"px"}, "slow");
          numShow_QuickAccess--;
        }
        else {
           jQuery(".quickAccessSlide  ul").animate({"left": -(slideWidth_QuickAccess*nbrContent_QuickAccess)+slideWidth_QuickAccess*5+"px"}, "slow");
           numShow_QuickAccess = nbrContent_QuickAccess-5
        }
      }
    );

    jQuery('.quickAccessSlide a.next').click(
      function(){
        if (nbrContent_QuickAccess > (numShow_QuickAccess+5)){
          jQuery(".quickAccessSlide ul").animate({"left": "-="+slideWidth_QuickAccess+"px"}, "slow");
          numShow_QuickAccess++;
        }
        else {
           jQuery(".quickAccessSlide ul").animate({"left": "0px"}, "slow");
           numShow_QuickAccess = 0;
        }
      }
    );

    //~ setInterval(
      //~ function(){
          //~ if (nbrContent_QuickAccess > (numShow_QuickAccess+5)){
            //~ jQuery(".quickAccessSlide  ul").animate({"left": "-="+slideWidth_QuickAccess+"px"}, "slow");
            //~ numShow_QuickAccess++;
          //~ }
          //~ else {
             //~ jQuery(".quickAccessSlide  ul").animate({"left": "0px"}, "slow");
             //~ numShow_QuickAccess = 0;
          //~ }
      //~ },5000);

  }
}


/*****
****** Fonctions  gérant le slide publications
*****/
  // gestion du diaporama



var slideWidth_Publications  =210;
var blocWidth_Publications   =210;
var blocNbr_Publications     =1;
var nbrContent_Publications  =0;
var blocFound_Publications   =0;
var numShow_Publications     =0
var title_Publications       = '';

function slidePublications(){

  jQuery('.publicationsSlide ul li').each(function(i){
    blocFound_Publications++;
  });

  nbrContent_Publications = Math.ceil((blocFound_Publications/blocNbr_Publications));
  jQuery('.publicationsSlide ul').width( (slideWidth_Publications*nbrContent_Publications) );

  if (nbrContent_Publications > 1){

    jQuery('.publicationsSlide a.slideNav.prev').click(
      function(){
        if (numShow_Publications > 0){
          jQuery(".publicationsSlide ul").animate({"left": "+="+slideWidth_Publications+"px"}, "slow");
          numShow_Publications--;
        }
        else {
           jQuery(".publicationsSlide ul").animate({"left": -(slideWidth_Publications*nbrContent_Publications)+slideWidth_Publications+"px"}, "slow");
           numShow_Publications = nbrContent_Publications-1
        }
      }
    );

    jQuery('.publicationsSlide a.next').click(
      function(){
        if (nbrContent_Publications > (numShow_Publications+1)){
          jQuery(".publicationsSlide ul").animate({"left": "-="+slideWidth_Publications+"px"}, "slow");
          numShow_Publications++;
        }
        else {
           jQuery(".publicationsSlide ul").animate({"left": "0px"}, "slow");
           numShow_Publications = 0;
        }
      }
    );

    setInterval(
      function(){
          if (nbrContent_Publications > (numShow_Publications+1)){
            jQuery(".publicationsSlide  ul").animate({"left": "-="+slideWidth_Publications+"px"}, "slow");
            numShow_Publications++;
          }
          else {
             jQuery(".publicationsSlide  ul").animate({"left": "0px"}, "slow");
             numShow_Publications = 0;
          }
      },5000);

  }
}

