// Scroll: Configuration (Commandes de défilement)
var currentSection = "accueil"; // Chargement de la page par default
var tabTag = "-tab";
var paneTag = "-pane";

// Scroll manuellement la page de la position de l'élément «lien», passé jusqu'à nous.
function ScrollSection(link, scrollArea, offset) {

	// Remet la dernière section, et met à jour la section en cours.
	if (currentSection == link) {
		return;
	}
	lastSection = currentSection;
	currentSection = link;
	    
	// obtient l'élément que je veux faire défiler, et obtient la position de l'élément pour faire défiler jusque la	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));

	// Obtient la position du 1ere div.
	// Montant de compansation lors du defilement	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	scrollStart(theScroll, theScroll.scrollLeft, position[0], "horiz");
	// retourne false;
}

// Animation : Scroll Functions
// Scrolls est synchrones à un seul à un moment.
var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end, direction) {
	//console.log("scrollStart from "+start+" to "+end+" in direction "+direction);
	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 80;
	scrollanim.element = elem;
	
	if (direction == "horiz") {
		scrollanim.timer = setInterval("scrollHorizAnim();", 15);
	}
	else {
		scrollanim.timer = setInterval("scrollVertAnim();", 15);
	}
}

function scrollVertAnim() {
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollTop = move; 
		scrollanim.time++;
	}
}

function scrollHorizAnim() {
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollLeft = move;
		scrollanim.time++;
	}
}


