$(document).ready( function () { 
    // On cache les sous-menus : 
     $(".navigation ul.subMenu").hide(); 
    // On sélectionne tous les items de liste portant la classe "toggleSubMenu" 
 
    // et on remplace l'élément span qu'ils contiennent par un lien : 
    $(".navigation li.toggleSubMenu span").each( function () { 
        // On stocke le contenu du span : 
        var TexteSpan = $(this).text(); 
        $(this).replaceWith('<a href="" title="Afficher le sous-menu">' + TexteSpan + '<\/a>') ; 
    } ) ; 
 
    // On modifie l'évènement "click" sur les liens dans les items de liste 
    // qui portent la classe "toggleSubMenu" : 
    $(".navigation li.toggleSubMenu > a").click( function () { 
        // Si le sous-menu était déjà ouvert, on le referme : 
        if ($(this).next("ul.subMenu:visible").length != 0) { 
            $(this).next("ul.subMenu").slideUp("normal"); 
        } 
        // Si le sous-menu est caché, on ferme les autres et on l'affiche : 
        else if($(this).next("ul.subMenu2:visible").length != 0){
          $(this).next("ul.subMenu2").slideUp("normal"); 
        }else{ 
            $(".navigation ul.subMenu").slideUp("normal");
            $(".navigation ul.subMenu2").slideUp("normal"); 
            $(this).next("ul.subMenu").slideDown("normal"); 
            $(this).next("ul.subMenu2").slideDown("normal"); 
        } 
        // On empêche le navigateur de suivre le lien : 
        return false; 
    });     
 
 
} ) ; 




// Pagination





/**
 * Callback function that displays the content.
 *
 * Gets called every time the user clicks on a pagination link.
 *
 * @param {int} page_index New Page index
 * @param {jQuery} jq the container with the pagination links as a jQuery object
 */
 
 
function pageselectCallback(page_index, jq){
    
    // This selects 9 elements from a content array
        $('#Searchresult').empty();
        for(var i=(page_index*9);i<((page_index*9)+9);i++) {
            var new_content = jQuery('#hiddenresult div.prod_prev:eq('+i+')').clone();
            $('#Searchresult').append(new_content);
        }
        $('#Searchresult').append("<hr/>");
        
        

			$("#form").fancybox(
			{

        'titleShow'		: false,
				'width'				: 450,
				'height'			: 510,
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});
			
			$("#form2").fancybox(
			{

        'titleShow'		: false,
				'width'				: 450,
				'height'			: 510,
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});
			
			$(".form3").fancybox(
			{

        'titleShow'		: false,
				'width'				: 680,
				'height'			: 540,
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});

        return true;
}




/** 
 * Initialisation function for pagination
 */
function initPagination() {
    // count entries inside the hidden content
    var num_entries = jQuery('#hiddenresult div.prod_prev').length;
    // Create content inside pagination element
    if(isNaN(parseInt(window.location.hash.substring(1)))){
        var page_loaded = 0;
    }else{
      var page_loaded = (parseInt(window.location.hash.substring(1))-1);
    }
    
    $("#Pagination").pagination(num_entries, {
        callback: pageselectCallback,       
        current_page: page_loaded,
        link_to:"#__id__",
        items_per_page:9, // Show only one item per page
        prev_text:"Pr&eacute;c&eacute;dent",
        next_text:"Suivant"
        
    });
 }


// When document is ready, initialize pagination
$(document).ready(function(){
        $(window).hashchange(function() { initPagination() });
        initPagination();
});






$(function() {
  $('#product #details .img_box a').lightBox();
  
});

// ibox

$(document).ready(function() {
			
	


			$("#form").fancybox(
			{

        'titleShow'		: false,
				'width'				: 450,
				'height'			: 510,
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});
			
			$("#form2").fancybox(
			{

        'titleShow'		: false,
				'width'				: 450,
				'height'			: 510,
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});
			
			$(".form3").fancybox(
			{

        'titleShow'		: false,
				'width'				: 680,
				'height'			: 540,
				'autoScale'			: false,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'type'				: 'iframe'
			});


			
});

   	
