$(document).ready(function(){

	// Fondu
	$("#fonduImg").innerfade({
		speed: 750,
		timeout: 3000,
		type: 'sequence'
	});

	/* Affichage des volets de sous-menu */
	$('#btn1')
    .mouseover(function(){
        $('#sMenu1').stop().animate({
            height:"80px"
            },{queue:true,duration:200}
         );
    })
	.mouseout(function(){
        $('#sMenu1').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	$('#sMenu1')
	.mouseover(function(){
		$(this).stop().height("80px");
	})
	.mouseout(function(){
        $('#sMenu1').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	
	/* Sous Menu 2 */
	$('#btn2')
    .mouseover(function(){
        $('#sMenu2').stop().animate({
            height:"80px"
            },{queue:true,duration:200}
         );
    })
	.mouseout(function(){
        $('#sMenu2').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	$('#sMenu2')
	.mouseover(function(){
		$(this).stop().height("80px");
	})
	.mouseout(function(){
        $('#sMenu2').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	
	/* Sous Menu 3 */
	$('#btn3')
    .mouseover(function(){
        $('#sMenu3').stop().animate({
            height:"80px"
            },{queue:true,duration:200}
         );
    })
	.mouseout(function(){
        $('#sMenu3').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	$('#sMenu3')
	.mouseover(function(){
		$(this).stop().height("80px");
	})
	.mouseout(function(){
        $('#sMenu3').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	
	/* Sous Menu 4 */
	$('#btn4')
    .mouseover(function(){
        $('#sMenu4').stop().animate({
            height:"80px"
            },{queue:true,duration:200}
         );
    })
	.mouseout(function(){
        $('#sMenu4').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	$('#sMenu4')
	.mouseover(function(){
		$(this).stop().height("80px");
	})
	.mouseout(function(){
        $('#sMenu4').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })


	/* Sous Menu 5 */
	$('#btn5')
    .mouseover(function(){
        $('#sMenu5').stop().animate({
            height:"140px"
            },{queue:true,duration:200}
         );
    })
	.mouseout(function(){
        $('#sMenu5').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	$('#sMenu5')
	.mouseover(function(){
		$(this).stop().height("140px");
	})
	.mouseout(function(){
        $('#sMenu5').stop().animate({
            height:"0px"
            },{queue:true,duration:50}
         );
    })
	
	// masque tous les jsSlide
	$('.jsSlide').addClass("close");
	
	$('.jsSlide')
	.click(function(){
		if($(this).css("height")=="7px"){
			$(this).removeClass("close",200);
		}else{
			$(this).addClass("close",200);
		}
	})

	// Affichage du texte panier
	txtPanier();

});



// Gestion du mini panier
// ----------------------------------------------------------------------------------
function addCart(idArticle){
	if(idArticle>0){
		
		// Affichage de l'overlay
		var overlay =  document.getElementById('fullOverlay');
		overlay.className='open';
		
		// Affichage du popup
		var urlPop = "http://"+document.domain+"/ajouteArticlePanier.php?addArticle="+idArticle;
		
		var xhr = getXhr();
        
        // On défini ce qu'on va faire quand on aura la réponse
		xhr.onreadystatechange = function()
		{
			// On ne fait quelque chose que si on a tout recu et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				overlay.innerHTML = xhr.responseText;
			}
		}

		// Objet à remplir
		xhr.open("GET", urlPop, true);
		// Fermeture
		xhr.send(null);
		
		// Affiche txtPanier
		txtPanier();
	}
	
}
// ----------------------------------------------------------------------------------


// Fermeture du mini panier
// ----------------------------------------------------------------------------------
function closeCart(idArticle){
	overlay =  document.getElementById('fullOverlay');
	overlay.className='';
}
// ----------------------------------------------------------------------------------

// Affichage du texte panier
// ----------------------------------------------------------------------------------
function txtPanier(){
		// Affichage de l'overlay
		txtPanierItem =  document.getElementById('txtPanier');
		
		// Affichage du popup
		var urlPop = "http://"+document.domain+"/txtPanier.php";
		
		var xhr = getXhr();
        
        // On défini ce qu'on va faire quand on aura la réponse
		xhr.onreadystatechange = function()
		{
			// On ne fait quelque chose que si on a tout recu et que le serveur est ok
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				txtPanierItem.innerHTML = xhr.responseText;
			}
		}

		// Objet à remplir
		xhr.open("GET", urlPop, true);
		// Fermeture
		xhr.send(null);
}
// ----------------------------------------------------------------------------------


// Fonction de paiement SPPLUS
// ----------------------------------------------------------------------------------
function paiementSpPlus(){
  
  //  Enregistre la note
  var idCommande;
  idCommande = document.getElementById('idCommande').value;
  
  if(idCommande>0){
  	note(idCommande);
   }
   
  var win;
  win=window.open('','SPPLUS','width=750,height=560,status=1');
  win.focus();
}
// ----------------------------------------------------------------------------------

// Fonction qui verifie l'etat de la case a cocher CGV + Alert
// ----------------------------------------------------------------------------------
function verifChkCgv(){
    if(document.getElementById('cgvChk').checked==false){
        alert("Vous devez accepter les conditions générales de vente");
    }
}
// ----------------------------------------------------------------------------------

// Activation des boutons de paiement
// ----------------------------------------------------------------------------------
function etatBtnPaye(){
    // si la case n'est pas cochée
    if (document.getElementById('cgvChk').checked==false){
        document.getElementById('btnSpplus').style.display='none';
        document.getElementById('imgSpplus').style.display='block';
        document.getElementById('btnPayPal').style.display='none';
        document.getElementById('imgPayPal').style.display='block';
    }else{
        document.getElementById('btnSpplus').style.display='block';
        document.getElementById('imgSpplus').style.display='none';
        document.getElementById('btnPayPal').style.display='block';
        document.getElementById('imgPayPal').style.display='none';

        //on active les valeures paypal
        payePayPal('formPayPal');
    }
}
// ----------------------------------------------------------------------------------

// Fonction popup CVG
// ----------------------------------------------------------------------------------
function popCgv(url){
    win=window.open(url,'CGV','width=750,height=560,status=1,scrollbars=yes');
}
// ----------------------------------------------------------------------------------

// Fonction qui update la commande
// -----------------------------------------------------------------------------
function note(idCommande)
{
	note = document.getElementById("noteMessage").value;

	var xhr = getXhr()
	url = "ajax.php?idCommande="+idCommande+"&note="+note+"&media=noteCommande";
       
	// On défini ce qu'on va faire quand on aura la réponse
	xhr.onreadystatechange = function()
	{
		// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
		if(xhr.readyState == 4 && xhr.status == 200)
		{
        }
	}

	// Objet à remplir
	xhr.open("GET", url, true);
	// Fermeture
	xhr.send(null);
}
// -----------------------------------------------------------------------------


// Gestion du mdp
// ----------------------------------------------------------------------------------
function popMdp() {
    window.open ("http://"+document.domain+"/client/pop_passw.php", "mdp","menubar=no, status=no, scrollbars=no, menubar=no, width=350, height=400");
}
// ----------------------------------------------------------------------------------

// Fonction AJAX
// ----------------------------------------------------------------------------------
function getXhr()
{
	var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
		xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject)
	{ // Internet Explorer 
		try 
		{
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else 
	{ // XMLHttpRequest non supporté par le navigateur 
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		xhr = false; 
	} 
	return xhr
}
// ----------------------------------------------------------------------------------
