$(document).ready( function() {
  
  // Pour chacun des post des galleries différentes d'images
  $('.post').each(function(){
      $('.zsbImg', this).lightBox();
  });
  
});



function emailFriendsShow( hauteur )
{  
  if ( document.getElementById( 'emailFriendsForm' ).style.display == 'block' )
  {
    document.getElementById( 'emailFriendsForm' ).style.display = 'none';
    document.getElementById( 'emailFriendsForm' ).style.height = 0+'px';
    document.getElementById( 'emailFriends' ).style.backgroundColor ='#EEEEEE';
    document.getElementById( 'formEmailFriends' ).style.display = 'none';
  }
  else
  {
    document.getElementById( 'emailFriendsForm' ).style.display = 'block';
    document.getElementById( 'emailFriendsForm' ).style.height = hauteur+'px';
    document.getElementById( 'emailFriends' ).style.backgroundColor ='#d3eefa';
    document.getElementById( 'formEmailFriends' ).style.display = 'block';
  }
}

function emailFriendsShowEffetMenu( cpt, menuHauteurMax )
{  
  var testDisplay = document.getElementById( 'formEmailFriends' ).style.display;
   
  if ( cpt <= menuHauteurMax && testDisplay != 'block' )
  {    
    document.getElementById( 'emailFriendsForm' ).style.display = 'block';
    document.getElementById( 'emailFriendsForm' ).style.height = cpt+'px';
    document.getElementById( 'formEmailFriends' ).style.display = 'none';

    setTimeout( function(){emailFriendsShowEffetMenu( cpt, menuHauteurMax ); }, 1 );
    cpt+=10;
  }
  if ( cpt >= menuHauteurMax )
    document.getElementById( 'formEmailFriends' ).style.display = 'block';
  
  document.getElementById( 'emailFriends' ).style.backgroundColor ='#d3eefa';
}


// Fonction Ajax permettant d'envoyer un mail à des amis
function ajaxEnvoyerEmailAmi() 
{
  var emailFriendsFrom  = document.getElementById( 'emailFriendsFrom' ).value;
  var emailFriendsTo    = document.getElementById( 'emailFriendsTo' ).value; 
  var emailFriendsText  = document.getElementById( 'emailFriendsText' ).value;
  var billetId          = document.getElementById( 'billetId' ).value;
  //var emailFriendsURLBillet  = document.getElementById( 'emailFriendsURLBillet' ).value;
  
//  var emailFriendsLienType  = document.getElementById( 'emailFriendsLienType' ).value;
 // var emailFriendsLienTitre = document.getElementById( 'emailFriendsLienTitre' ).value;
	var maxStr = 500;
	       
	if ( emailFriendsFrom.length < maxStr 
  && emailFriendsTo.length < maxStr 
  && emailFriendsText.length < maxStr 
  && billetId > 0 ) 
	{
    var xhr_object = null;
  	         
  	if(window.XMLHttpRequest) // Firefox
  		xhr_object = new XMLHttpRequest();
  	else if(window.ActiveXObject) // Internet Explorer
  		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
  	else { // XMLHttpRequest non supporté par le navigateur
  		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
  		return;
  	}
                           
  	xhr_object.open("POST", "http://www.zatras.com/~share/trouvailles/inc/ajax_envoyer_email_amis.php", true);
                           
  	xhr_object.onreadystatechange = function anonymous() {
  		if(xhr_object.readyState == 4)
  			eval(xhr_object.responseText);
  	}
                       
  	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	var data = "emailFriendsFrom="+escape(emailFriendsFrom)+"&emailFriendsTo="+escape(emailFriendsTo)+"&emailFriendsText="+escape(emailFriendsText)+"&billetId="+escape(billetId);
  				         
  	xhr_object.send(data);
  	
	}
	else
	{
	 alert('Le commentaire est trop long');
  }
}

