$(function()
{
    // Créé le <p> qui recevra le nom du client
    //$("#utilisateur_create_code_client").after('<span id="clientName" style="margin-left: 20px;"></span>');

    $("#utilisateur_create_code_client").keyup(function()
    {
        var code = $(this).val();

        // Seulement si le code fait 4 caractères ou plus
        if(code.length > 3)
        {
            $("#clientName").empty();
            $("#clientName").load('/pro/name_by_code/'+code);        
        }
        else
        {
            $("#clientName").empty();
        }
    });
    
	/*
	 * ROUNDABOUT
	 * Menu en carousel
	 */

      $('ul#myRoundabout').roundabout({
    	  tilt: -6
      });
      var interval; 
      interval = startAutoPlay(); 
	
      function startAutoPlay() {
		return setInterval(function() {
			$('ul#myRoundabout').roundabout_animateToPreviousChild();
		}, 5000);
	  }
	
      /*
       * ACCORDEON pages statiques
       */
      /*$(document).ready(function() {
	    $("#accordion").accordion();
	  });*/
	    //ACCORDION BUTTON ACTION	
      	$('h3.accordionButton').click(function() {
      		$('div.accordionContent').slideUp('normal');	
      		$(this).next().slideDown('normal');
	  	});
	   
	  	//HIDE THE DIVS ON PAGE LOAD	
	  	$("div.accordionContent").hide();
	  	$("div.first").show();


      
/* DATATABLE
 * Organise la liste des article par catégorie
 */	
    /* DataTable pour la liste des articles par catégories */ 
    $('#list_article_categorie').dataTable( {
    	"aaSorting": [[ 0, "asc" ]],
    	"aoColumns": [null, {"bSortable": false}, null],
        "sPaginationType": "full_numbers",
        "iDisplayLength": 25,
        "oLanguage": { "sUrl": "/js/dataTables/fr.txt" }
    }); 
  
/* EVENTS
 * 
 */	
    //slider des actions et innovations INDEX
    //setInterval( "slideActions()", 3000 );
    //setInterval( "slideInnovations()", 3000 );
    $('.slideshowActions').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 2500,
		speed: 500
	});
    $('.slideshowInnovations').cycle({
		fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		timeout: 3000,
		speed: 500
	});
/*PAS d'actions en cours */
    //Remplace le OnClick directement dans le html pour ouvrir le pdf dans une nouvelle fenêtre
    $('.slideshowActions').click(function() {
    	var url = $(this).attr("rel");
    	window.open(url);
    	//$(location).attr('href', url);
	});

  //Remplace le OnClick directement dans le html pour ouvrir le pdf dans une nouvelle fenêtre
    $('.slideshowInnovations').click(function() {
    	var url = $(this).attr("rel");
    	window.open(url);
    	//$(location).attr('href', url);
	});
    
   
    //Remplace le OnClick directement dans le html pour rediriger sur la fiche produit
    $('tr.article').click(function() {
    	var url = $(this).attr("rel");
    	$(location).attr('href',url);
	});
    
/* TOOLTIP
 * CONFIG Apparition de l'image Article
 */
	
	xOffset = 10;
	yOffset = 30;
	
	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result
	
	/* END CONFIG */
	$("tr.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.lang +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
	},
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
	});	
	$("tr.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});	
/* fin TOOLTIP*/

	/* DIAPORAMA Pickachoose - page article*/
	$("#pikame_user").PikaChoose({user_thumbs:true, show_prev_next:false});
		//Réinitialisation de la slimbox pour le Zoom sur la grand vignette
		$("a[rel^='lightbox']").slimbox({}, null, function(el)
		{
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	}); 
});

