
$(document).ready( function () {
	$("ul.subMenu:not('.open_at_load')").hide();
	// On selectionne tous les items de liste portant la classe "toggleSubMenu"

	// et on remplace l'element span qu'ils contiennent par un lien :
	$("li.toggleSubMenu span").each( function () {
		// On stocke le contenu du span :
		var TexteSpan = $(this).text();
		$(this).replaceWith('<a href="" class="sousMenu" title="Afficher le sous-menu">' + TexteSpan + '</a>') ;
	} ) ;

	// On modifie l'evenement "click" sur les liens dans les items de liste
	// qui portent la classe "toggleSubMenu" :
	$("li.toggleSubMenu > a").click( function () {
		// Si le sous-menu etait deja ouvert, on le referme :
		if ($(this).next("ul.subMenu:visible").length != 0) {
			$(this).next("ul.subMenu").slideUp("normal", function () { $(this).parent().removeClass("open") } );
		}
		// Si le sous-menu est cache, on ferme les autres et on l'affiche :
		else {
			$("ul.subMenu").slideUp("normal", function () { $(this).parent().removeClass("open") } );
			$(this).next("ul.subMenu").slideDown("normal", function () { $(this).parent().addClass("open") } );
		}
		// On empéche le navigateur de suivre le lien :
		return false;
	});    
} ) ;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
// Jcarousel
   
function mycarousel_itemLoadCallback(carousel, state) {
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last)) {
        return;
    }

    jQuery.get(
        'dynamic_ajax_php.php',
        {
            first: carousel.first,
            last: carousel.last
        },
        function(xml) {
            mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
        },
        'xml'
    );
};

function mycarousel_itemAddCallback(carousel, first, last, xml)
{
    // Set the size of the carousel
    carousel.size(parseInt(jQuery('total', xml).text()));

    jQuery('image', xml).each(function(i) {
        carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
    });
};

/**
 * Item html creation helper.
 */

/* // visibilité du block mon panier
Event.domReady.add(function() {;
	
	$("#global form #ajoutpanier_btn").click(function(event){
	  $("#commnande-detail").replaceWith("<div id='commnande-detail' style='height:160px; width:908px; margin:5px; background:#fff;'><img src='Img_clicpostal/Img_site/Lightbox/loader.gif' /></div>");
	  $.ajax({
      type: "POST",
      url: "ajax_ajout_panier.php",
      data: "client="+$('#client').val()+"&produit="+$('#produit').val()+"&quantite="+$('#quantite').val()+"&papier="+$('#papier').val()+"&echantillon="+$('#echantillon').val()+"&album="+$('#album').val(),
      success: function(a){
        $("#commnande-detail").replaceWith(a);
		$("#shadow").toggle();
        $("#panier_acces").css("display", "block");
		$("#panier_acces").css("z_index", "3002");
		$('#mycarousel').jcarousel({scroll:2});
      }
    });
	});
}); */
