$(document).ready(function(){
// ***************** *
// PROPOSER UNE PAGE *
// ***************** *
$('#ppp').hover(function(){$(this).css('cursor','pointer');});
$('#ppp').live('click',function(){
   $('#ppp').hide();
   $('#f_ppp').show();
});
// ************
// NEWSLETTER *
// ************
$('#SMN_form_newsletter').click(function(){$(this).attr('value','');});
$('#SMN_form_newsletter_submit').click(function(){
  var nlemail = $('#SMN_form_newsletter').val();
  $.post('scripts/script-newsletter.php?nlemail2='+nlemail,{nlemail:nlemail});
  $(this).remove();
  $('#SMN_form_newsletter_retour').fadeIn(500);
  $('#SMN_form_newsletter').attr('value','merci !');
});
// *******
// RADIO *
// *******
$('#radio').hover(function(){$(this).attr('src','images/radio_off.png');},function(){$(this).attr('src','images/radio_on.png');});
// ********** *
// SLIDE NEWS *
// ********** *
$('.CGA1A_nav_numero').hover(function(){$(this).css('cursor','pointer');});
$('#CG_accueil_1A_flechegauche_img').hover(function(){$(this).css('cursor','pointer');});
$('#CG_accueil_1A_flechedroite_img').hover(function(){$(this).css('cursor','pointer');});
$('.CGA1A_nav_numero').live('click',function(){
  var numeroid = $(this).attr('id');
  $('.CGA1A_nav_numero').each(function(){
   if($(this).attr('id') != numeroid){$(this).addClass('CGA1ANN_plein').removeClass('CGA1ANN_creux');}
   else                              {$(this).addClass('CGA1ANN_creux').removeClass('CGA1ANN_plein');}
  });
  $('.CGA1A_UNEs').each(function(){$(this).hide();});
  $('#UNE_' + numeroid).show();
    $('.CG_accueil_1A_flechegauche').attr('id',''+ numeroid +'');
    $('.CG_accueil_1A_flechedroite').attr('id',''+ numeroid +'');
});
$('#CG_accueil_1A_flechegauche_img').live('click',function(){
  var UNE_actuelle = $(this).parent('div').attr('id');
  if(UNE_actuelle == 1){ var UNE_precedente = 5; }
  else                 { var UNE_precedente = parseInt(UNE_actuelle) - 1; }
  $('.CGA1A_UNEs').each(function(){$(this).hide();});
  $('#UNE_' + UNE_precedente).show();
    $('.CG_accueil_1A_flechegauche').attr('id',''+ UNE_precedente +'');
    $('.CG_accueil_1A_flechedroite').attr('id',''+ UNE_precedente +'');
    
   $('.CGA1A_nav_numero').each(function(){
   if($(this).attr('id') != UNE_precedente){$(this).addClass('CGA1ANN_plein').removeClass('CGA1ANN_creux');}
   else                                    {$(this).addClass('CGA1ANN_creux').removeClass('CGA1ANN_plein');}
  });
});
$('#CG_accueil_1A_flechedroite_img').live('click',function(){
  var UNE_actuelle = $(this).parent('div').attr('id');
  if(UNE_actuelle == 5){ var UNE_suivante = 1; }
  else                 { var UNE_suivante = parseInt(UNE_actuelle) + 1; }
  $('.CGA1A_UNEs').each(function(){$(this).hide();});
  $('#UNE_' + UNE_suivante).show();
    $('.CG_accueil_1A_flechegauche').attr('id',''+ UNE_suivante +'');
    $('.CG_accueil_1A_flechedroite').attr('id',''+ UNE_suivante +'');

   $('.CGA1A_nav_numero').each(function(){
   if($(this).attr('id') != UNE_suivante){$(this).addClass('CGA1ANN_plein').removeClass('CGA1ANN_creux');}
   else                                  {$(this).addClass('CGA1ANN_creux').removeClass('CGA1ANN_plein');}
   });
});
// **** *
// PLUS *
// **** *
$('#A_plus').live('click',function(){
  var pcat  = $('#A_plus_cat').val();
  var pfrom = $('#A_plus_from').val();
  $('.A_plus_chargement').show();
  $('.plus').remove();
    $.post('scripts/script-plus.php',{pcat:pcat,pfrom:pfrom},function(data){
      var xmlData    = data.getElementsByTagName('f')[0];
      var ret        = xmlData.getElementsByTagName('ret')[0].firstChild.nodeValue;
      var xmlContent = xmlData.getElementsByTagName('content')[0].firstChild.nodeValue;
        if(ret){
          $('#sommaire').append(xmlContent);
          $('.A_plus_chargement').fadeOut(1000);}
    },'xml');
    $.post('ga.php?sommaire:' + pcat);
});
// ************************************************ *
// apparition des textes pour les articles relatifs *
// ************************************************ *
$('.CGAR_img').hover(
  function(){
  $(this).css('cursor','pointer');
  var id = $(this).attr('id');
  $('#CGAR_div_fake').hide();
  $('#CGAR_div_' + id).show();
  },
  function(){
  var id = $(this).attr('id');
  $('#CGAR_div_' + id).hide();
  $('#CGAR_div_fake').show();
  }
);
// ***********************
// recherche dans google *
// ***********************
$('#SMN_form_recherche_submit').hover(function(){$(this).css('cursor','pointer');});
$('#SMN_form_recherche').keypress(function(e){
      if(e.keyCode == 13){
        e.preventDefault();
        var frs_lien = $('#SMN_form_recherche').val();
        window.open('out.php?url=http://www.google.fr/search?q=site%3Abrain-magazine.com+' + frs_lien);
        return false;
       }
});
$('#SMN_form_recherche_submit').live('click',function(){
    var frs_lien = $('#SMN_form_recherche').val();
    window.open('out.php?url=http://www.google.fr/search?q=site%3Abrain-magazine.com+' + frs_lien);
    return false;
});
// ****************************************************************** *
// Correction de la hauteur des vidéos YouTube :                      *
// width = 100%, height = auto                                        *
// mais les dimensions ne s'adaptent, donc elles sont corrigées ainsi *
// ********************************************************************
$('iframe').each(function(){
  if($(this).attr('rel') != 'slogan'){
  // réadaptation automatique du CSS des vidéos youtube
  $(this).css('width','100%').css('height','auto');
  // définition de la hauteur en fonction de la largeur
  var LargeurVideo = $(this).width();
  if(LargeurVideo > 580) $(this).height(327);
  if(LargeurVideo < 580) $(this).height(150);
  if(LargeurVideo = 420) $(this).width(420).height(315);
  }
});
$('.CG_article_img').css('margin','10px auto 30px auto');
// ****************************************************** *
// display : derniers articles, plus populaires, archives *
// ****************************************************** *
$('#AJX_plus_populaires').live('click',function(){
  $('#CD_liste_span_gauche').css({opacity:0.5});
  $('#CD_liste_span_droite').css({opacity:1});
  $('#L_derniers_articles').css('display','none');
  $('#L_archives').css('display','none');
  $('#L_plus_populaires').fadeIn(2000).css('display','block');
  $('.CD_liste').jScrollPane({showArrows:true,horizontalGutter: 10});
});
$('#AJX_derniers_articles').live('click',function(){
  $('#CD_liste_span_droite').css({opacity:0.5});
  $('#CD_liste_span_gauche').css({opacity:1});
  $('#L_plus_populaires').css('display','none');
  $('#L_archives').css('display','none');
  $('#L_derniers_articles').fadeIn(2000).css('display','block');
  $('.CD_liste').jScrollPane({showArrows:true,horizontalGutter: 10});
});
$('#AJX_archives').live('click',function(){
  $('#CD_liste_span_gauche').css({opacity:0.5});
  $('#CD_liste_span_droite').css({opacity:1});
  $('#L_derniers_articles').css('display','none');
  $('#L_plus_populaires').css('display','none');
  $('#L_archives').fadeIn(2000).css('display','block');
  $('.CD_liste').jScrollPane({showArrows:true,horizontalGutter: 10});
});
// *********************** *
// correction des curseurs *
// *********************** *
//
$('#logo_facebook').hover(function(){$(this).attr('src','images/logo-facebook_omo.png');},
                          function(){$(this).attr('src','images/logo-facebook.png');});
$('#logo_twitter').hover(function(){$(this).attr('src','images/logo-twitter_omo.png');},
                         function(){$(this).attr('src','images/logo-twitter.png');});
$('#logo_rss').hover(function(){$(this).attr('src','images/logo-rss_omo.png');},
                     function(){$(this).attr('src','images/logo-rss.png');});
$('#AJX_derniers_articles').live("mouseenter",function(){
  $(this).css('cursor','pointer');
  $('#CD_liste_span_gauche').css({opacity:1});
  }).live("mouseleave",function(){
  if($('#L_derniers_articles').css('display') == 'none') $('#CD_liste_span_gauche').css({opacity:0.5});
  });
//
$('#AJX_plus_populaires').hover(function(){$(this).css('cursor','pointer');
  $('#CD_liste_span_droite').css({opacity:1});
  }).live("mouseleave",function(){
  if($('#L_plus_populaires').css('display') == 'none') $('#CD_liste_span_droite').css({opacity:0.5});
  });
//
$('#AJX_archives').hover(function(){$(this).css('cursor','pointer');
  $('#CD_liste_span_droite').css({opacity:1});
  }).live("mouseleave",function(){
  if($('#L_archives').css('display') == 'none') $('#CD_liste_span_droite').css({opacity:0.5});
  });
//
});
