
jQuery(document).ready(function(){
    function loginConnexion(){
        var user = document.getElementById('user-connexion').value;
        var pass = document.getElementById('password-connexion').value;
        var url = "/" + user + "/" + pass + "/login.html";
        jQuery.ajax({
            type: "GET",
            url: url,
            dataType : "json",
            beforeSend : function(xhr) {
                 xhr.setRequestHeader('Origine','communes.com');
            },
            success: function(msg) {
                if (msg['error']) {
                    document.getElementById('errormsg-connexion').innerHTML = msg['erroruser'] ? msg['erroruser']:"";
                    document.getElementById('errormsg-connexion').innerHTML = msg['errorpass']? msg['errorpass']:"";
                    document.getElementById('errormsg-connexion').innerHTML = msg['errormsg']? msg['errormsg']:"";
                } else {
                    document.getElementById('user-connexion').value = "";
                    document.getElementById('password-connexion').value = "";
                    setUser(user);
                    location.href="/pageperso.html";
                }
            }
        });
        return false;
    }

    function afficheInitPassword(){
        jQuery('#errormsg').text('') ;
        jQuery('#erroruser').text('') ;
        jQuery('#errorpass').text('') ;

        jQuery('#p_pass').hide();
        jQuery('#ul_connexion').hide();
        jQuery('#bouton-connexion').hide();
        jQuery('#remember').hide();
        jQuery('#span_remember').hide();

        jQuery('#bouton-initPassword').show();
        jQuery('#p_texte').show();

        jQuery('#fond-connexion').fadeIn('normal',function(){
          jQuery('#form-connexion').fadeIn('normal');
          var pageHeight = jQuery('body').height();
          jQuery('#fond-connexion').height(pageHeight);
        })
    }


    jQuery('#bouton-connexion-btm').click(function(){
        loginConnexion();
    });
    jQuery('#href-password').click(function(){
        afficheInitPassword();
        return false;
    });

    jQuery('li','#blog').each(function(){
       var liObj = $(this);
       liObj.find('.extrait').val(0).hover(
           function(){
                liObj.find('p').fadeIn('fast');
           },
           function(){
                liObj.find('p').fadeOut('fast');
           }
       );

       
    });
    

});


function afficherOnglet(idcible,idsource){
  if(jQuery('#'+idcible).is(":hidden")){
    var a = jQuery('.ss-menu-index').filter(function(){
        return jQuery(this).is(":visible");
    }).attr('id');
    if(a){
      jQuery('#'+a).slideUp("normal");
      jQuery('#'+a).queue(function(){
          jQuery('.menu-index li').removeClass('open');
          jQuery('#'+idsource).addClass('open');
          jQuery('#'+idcible).slideDown("normal");
          jQuery('#'+a).dequeue();
      });
    }else{
      jQuery('#'+idsource).addClass('open');
      jQuery('#'+idcible).slideDown("normal");
    }
  }else{
    jQuery('#'+idcible).slideUp("normal",function() {
      jQuery('#'+idsource).removeClass('open');
    });
  }
}


