
function axEnableSubmit() {
$('#uidialog form').submit( function() {
    _var_url = $(this).attr('action');
    $.ajax({
      type: "POST",
      url: _var_url,
      data: $(this).serialize(),
      success: function(msg) {
        r = msg.split('|');
        if( r[0]=='#success') {
          $('#uidialog').empty().html(r[1]);
          var el = $('#uidialog h2:first');
          if (el) { el.empty().remove(); }
        } else {
          $('#uidialog').html(msg);
          var el = $('#uidialog h2:first');
          if (el) { el.empty().remove(); }          
          axEnableSubmit();
        }
        
      }
    });
    return false;
  });
}

function axPopup(msg)   {
  $('#uidialog').hide().html(msg);
  var titre = null;
  var el = $('#uidialog h2:first');
  if (el) { titre = el.html(); el.empty().remove(); }
  $('#uidialog').dialog('destroy');
  $('#uidialog').dialog({title: titre,modal: true ,iframe:true,resizable: true,width:'400px'});
  if( !$('#uidialog').dialog( 'isOpen' )) $('#uidialog').dialog('open');
  axEnableSubmit();
}


function redir(el) {
		href = el.attr('href');
		if(href !='#') { setTimeout('location.href="'+href+'"',200); }
		return false;
}
// exécution une fois le chargement de la page effectué


$(document).ready(function() {
  
  // fonction texte+ et texte-
  if ($('#content').size()) {
      $('.txt_plus').click(function(){
      var ourText = $('#content');
      if(ourText.size()) {
        var currFontSize = ourText.css('fontSize');
        var finalNum = parseFloat(currFontSize, 10);
        var stringEnding = currFontSize.slice(-2);
        finalNum *= 1.2;
        finalNum = parseInt(finalNum);
        ourText.animate({fontSize: finalNum + stringEnding},300);
      }
      return false;
      });

      $('.txt_moins').click(function(){
      var ourText = $('#content');
      if(ourText.size()) {
        var currFontSize = ourText.css('fontSize');
        var finalNum = parseFloat(currFontSize, 10);
        var stringEnding = currFontSize.slice(-2);
        finalNum /=1.2;
        ourText.animate({fontSize: finalNum + stringEnding},300);
      }
      return false;
      });
  }
    
  // activation hilight sur map
  if($('#cartefrance').size()) {
    $('#cartefrance').maphilight({stroke:false,fillColor: '999999'});
  }

  // slide sur les sous-rubriques de la sidebar
  $('.sidebar .normal').each( function() {
    var sub = $(this).parent().find('div.submenu');
    if(sub.size()) {
      $(this).find('a').not('.current').click(function() { sub.slideDown('normal');return false;});
    }
  });
  
  $('.headermenu').each( function() {
    var sub = $(this).find('div.submenu');
    if(sub.size()) {
      $(this).find('a:first').not('.current').click(function() { 
        var el=$(this);
        sub.slideDown('normal',function() { redir(el); });
        return false;});
    }
  });
  

  // traitement spécifique à la homepage
  if($('body').attr('id')=='homepage') {
    $('.intro').not('#home_defaut').hide();
     $('.items-intro li a').hover(function() {       
       
       if( $(this).parent().hasClass('link-autres')) {
          $('#home_defaut').hide();
          $('#home_autres').show();
          $(this).stop().animate( {'width':(207+64)+'px'},{queue:false,duration:250});
       } else {
        if( $(this).parent().hasClass('link-oniam')) {
          $('#home_defaut').hide();
          $('#home_oniam').show();          
          $(this).stop().animate( {'width':(118+64)+'px'},{queue:false,duration:250});
        } else {
          $('#home_defaut').hide();
          $('#home_crci').show();          
          $(this).stop().animate( {'width':(99+64)+'px'},{queue:false,duration:250});
        }
       }
     },function() {
       if( $(this).parent().hasClass('link-autres')) {
        $('#home_autres').hide();
        $('#home_defaut').show();
        $(this).stop().animate( {'width':'207px'},{queue:false,duration:250});
       } else {
        if( $(this).parent().hasClass('link-oniam')) {
          $('#home_oniam').hide();
          $('#home_defaut').show();
          $(this).stop().animate( {'width':'118px'},{queue:false,duration:250});
        } else {
          $('#home_crci').hide();
          $('#home_defaut').show();
          $(this).stop().animate( {'width':'99px'},{queue:false,duration:250});
        }
       }
     });

     $('.missions li').hover(
        function() { $(this).addClass('hover');},
        function() { $(this).removeClass('hover'); });

     $('.missions li').click(function() {
       location.href = $(this).find('a:first').attr('href');
       return false;
     });
  }
  
  // page des mots clés
  if($('body').attr('id')=='mots-cles') {
       $('div.liste_mots_cles div.article').not(':first').hide();
       $('a.visu_motcle').click(function() {
         link = $(this).get(0).hash;
         $('div.article').not(link).slideUp();
         $(link).not(':visible').slideDown();
         return false;
       });
  }
     
  // un peu de fun, mise à la même taille des blocs gauche & droite
  _g = $('.bloc_gauche #content').height();
  _d = $('.bloc_droite').height();
  if(_d>_g) $('.bloc_gauche #content').css('min-height',(parseInt(_d)+'px'));
});
