    var slideId = 1;
    //speed of animation
    var animateSpeed = 500;
    //interval between animation
    var slideInterval = 5000;//5000
    //protect for not running multiple settimeout
    var doTimeout = false;
    //protect for not running multiple animate
    var doAnim = true;
    
    var slideTimer;
    var slideDelay;
    
   

$(document).ready(function(){
    
     $.validator.addMethod('passCheck',function(value, element) {
	
	regTest = /^[a-zA-Z0-9]+$/;
	
	if (regTest.test(value) && value.length>=5 && value.length<=15) return true;
	else return false;
            
	}, "Caractères alphanumériques autorisés, min:5, max:10");

    $("#indexFormInscript").validate({

		rules: {
		    password: {required: true,passCheck:true},
                        email: {required: true,email: true},
			prenom: {required: true}
			
		
		}
	});
    
    
    
    //slider animation
        //set a delay after page load before launching the anim
        slideDelay = setTimeout("autoDelay()",2000);
        
        //stop the animation on mousenter on menu or content of slider
        $(".slider div.items div.itemslist").mouseenter(function(){
            if(doAnim){
                clearTimeout(slideTimer);
                doTimeout = true;
            }
        });
        
        $(".slider ul.slides").mouseenter(function(){
            if(doAnim){
                clearTimeout(slideTimer);
                doTimeout = true;
            }
        });
        

        //restart the animation when exiting the area with the mouse
        $(".slider div.items div.itemslist").mouseleave(function(){
            //call the interval launcher if not already called before
            if(doTimeout && doAnim) launchSlideTimeout();
        });
        $(".slider ul.slides").mouseleave(function(){
            //call the interval launcher if not already called before
            if(doTimeout && doAnim) launchSlideTimeout();
        });
      

        //pick the animation to display if clicking on the left menu
        $(".slider div.items div.itemslist").click(function(){
            //only trigger if the previous anim finished
            if(doAnim){
                var id = this.id.replace("item","");
        
                //set the current slide viewed as reference
                slideId = Number(id);
                
                //reset auto change
                clearTimeout(slideTimer);
              
                //launch the anim starting from the selected one, without the auto interval
                slideChange(id,false);
            }
        
            return false;
        });
    /////////////////
    
    //hide the placeholders if the login fields are not empty
    $("div.register input").each(function(){
        if($(this).val() != "")
        {
            var idPlaceholder = this.id.replace("input","placeholder");
            if(idPlaceholder!='') $("#"+idPlaceholder).hide();
        }
    });
    
    //hide the placeholders when focus entering login or password
    $("div.register input").focus(function(){
            var idPlaceholder = this.id.replace("input","placeholder");
            
            if(idPlaceholder!='') $("#"+idPlaceholder).hide();
    });
    
    //manage the placeholder for login area on top of the sidebar
        //hide the placeholder on top of the input box
        $("div.register div.placeholder").click(function(){
            var idInput = this.id.replace("placeholder","input");
            
            $(this).hide();
            $("#"+idInput).focus();
        });
        
        //put back placeholders if necessary when exiting input box        
        $("div.register input").blur(function(){
            var idPlaceholder = this.id.replace("input","placeholder");
            
            if($(this).val() == "")
            {
                if(idPlaceholder!='') $("#"+idPlaceholder).show();
            }
        });
    ////////////
    
    //3 latest blog articles display
    var blogItem;
    var currItem=0;

    blogItem = $(".blog_last p").hide().size();
    $(".blog_last p:eq("+currItem+")").fadeIn();
    setInterval(tickBlog,5000); //time in milliseconds
    
    //function hiding/showing 1 blog artcile at a time
    function tickBlog(){
        $(".blog_last p:eq("+currItem+")").hide();
        currItem = ++currItem%blogItem;
        $(".blog_last p:eq("+currItem+")").fadeIn();
    } 

});



//function, for slides, to launch the timer for auto change after page loading (create a small delay)
function autoDelay(){
    doTimeout = true;
    launchSlideTimeout();
}

//function, for slides, launching the timer with intervals
function launchSlideTimeout(){
    if(doTimeout) {
        doTimeout = false;
        slideTimer = setTimeout("launchSlide()",slideInterval);
    }
}

//function launching the slider change
function launchSlide(){
    slideId += 1;
    if(slideId > slideNumber) slideId = 1;
    
    //call the function dealing with the slider display
    slideChange(slideId,true);
}

//function dealing with slides display
//id=>id of the div to show, timer => true/false if we want to launch the interval timer after display
function slideChange(id,timer)
{
    if(doAnim)
    {
        doAnim = false;
        
        var itemSelector = "#item"+id;
        var slideSelector = "#slide"+id;
                
        //remove the class "on" for all the left menu
        $(".itemslist").each(function(){
            if($(this).hasClass("on")){
                $(this).removeClass("on");
            }
        });
        
        //add the class "on" for the active menu
        $(itemSelector).addClass("on");
        
        //animate the apparition of content
        $("ul.slides").animate({
            opacity:0.1
            }, animateSpeed, function(){
                
                //hide all other li
                $("ul.slides li").each(function(){
                    $(this).hide();
                });
                //show the li we want to display
                $(slideSelector).show();
                
                //set back opacity to 1
                $("ul.slides").animate({
                        opacity:1
                        }, animateSpeed, function(){
                            doAnim = true;
                            doTimeout = true;
                            if(timer)
                            {
                                //launch the next slider
                                launchSlideTimeout();
                            }
                        }
                    );
            }
        );
    }
}



