$(document).ready(function() { //when the document is ready...

	//save selectors as variables to increase performance
	var $window = $(window);
	var $firstBG = $('#general');
	var fondparallaxbg = $("#general #fond-parallax-bg");
	var fondparallax = $("#general #fond-parallax");
	
	var windowHeight = $(window).height(); //get the height of the window
	
	// Pour le canoe
	var windowWidth = $(window).width(); //get the width of the window
	
	
	//apply the class "inview" to a section that is in the viewport
	$('#general').bind('inview', function (event, visible) {
		if (visible == true) {
		$(this).addClass("inview");
		} else {
		$(this).removeClass("inview");
		}
	});

	function newPos(x, windowHeight, pos, adjuster, inertia){
		var npos = x + "% " + (-((windowHeight + pos) - adjuster) * inertia) * (windowHeight / 800)  + "px";
		return npos;
	}
	
	function newPosCanoe(x, windowWidth, pos, adjuster, inertia){
		var npos = (x - (pos / 11)) + "% " + (-((windowWidth + pos) - adjuster) * inertia) + "px";
		return npos;
	}

	function Move(){ 
		var pos = $(window).scrollTop(); //position of the scrollbar

		//if the first section is in view...
		if($firstBG.hasClass("inview")){
			if(windowHeight<=700){
				fondparallaxbg.css({'backgroundPosition': newPos(50, windowHeight, pos, 800, 0.2)});
				fondparallax.css({'backgroundPosition': newPos(50, windowHeight, pos, 0, 0.8)});
				
			}else if((windowHeight>700)&&(windowHeight<=800)){
				fondparallaxbg.css({'backgroundPosition': newPos(50, windowHeight, pos, 800, 0.2)});
				fondparallax.css({'backgroundPosition': newPos(50, windowHeight, pos, 60, 0.5)});
				;
			}else if((windowHeight>800)){
				fondparallaxbg.css({'backgroundPosition': newPos(50, windowHeight, pos, 800, 0.2)});
				fondparallax.css({'backgroundPosition': newPos(50, windowHeight, pos, 300, 0.5)});
			}
		}
	}

	$(window).resize(function(){ //if the user resizes the window...
		windowHeight = $(window).height();
		Move(); //move the background images in relation to the movement of the scrollbar
	});		
	
	$(window).bind('scroll', function(){ //when the user is scrolling...
		Move(); //move the background images in relation to the movement of the scrollbar
		
		var pos = $(window).scrollTop(); //position of the scrollbar

		if (pos > 0 && pos < 1200) {
			//show_tooltip('premier');
		}
	});

	var current = '';
	var tooltip_locked = false;

});
