/* Date de création: 09/04/2008 */
var intervale;
var divPosSet = 0;
var navWidth = null;
var mouseXpos = 0;
var intervalVar = "";
var containerWx = "";
var screenCenter= 0;
var flow;
var divLeft;
var goingTo;
var newMousepos =null;
var halfContainer;
var limiteRight = 0;

//var imgWx = (160+20);
if (isIE) {
  var imgWx = (263+56);// premier chiffre à 224
} else {
  var imgWx = (256+56);// premier chiffre à 224
}

function setScreen(){

	if (isIE) {
		navWidth	= document.getElementsByTagName("HTML")[0].offsetWidth;
	} else {
		navWidth	= window.innerWidth;
	}
	screenCenter = (navWidth/2);

	var flowObj = document.getElementById("flow").getElementsByTagName("img");
	//set width
	document.getElementById("flow").style.width = (imgWx*flowObj.length)+"px";
	
	containerWx = divWidth("innercontainer");
	halfContainer = (containerWx/2);

	flow = divWidth("flow") ;

	limiteRight = ((-1)*(flow-containerWx));//halfContainer

	setDivXPos("flow", ( (-1)*(flow-containerWx)/2));

	divLeft = divActuaLeftPos("flow");
	goingTo = (flow-containerWx)/2;
	if (!divLeft) return;
	pulsate();
}

function setOff(){
	document.onmousemove = function(){
		return;
	}
}
function moveit(way){
	if (way=='left') var val = (divActuaLeftPos("flow")-imgWx);
	else var val = (divActuaLeftPos("flow")+imgWx);
	newMousepos = 1;
//	if (val>(halfContainer-imgWx)) {
	if (val>0) {
		val = 0;//halfContainer-imgWx;
	}
	else if ( val < limiteRight ) val = limiteRight;
	goingTo = val;
	
}

function automoveit(){
	document.onmousemove = function(e) {

		if (window.event) e = window.event;
		var winX = (e.x || e.clientX);
		mouseXpos = Math.round(winX-screenCenter);
		
		newMousepos =  Math.round((-1)*(mouseXpos * (flow/containerWx))) ;

		goingTo =  divLeft + newMousepos;// +(halfContainer);

		if (goingTo>0) goingTo = 0;
		else if ( goingTo < limiteRight ) goingTo = limiteRight;

	}
}
	
function pulsate(){
	clearInterval(intervalVar);
	intervalVar = setInterval("setDivMove()", 10);
}

function setDivMove() {

	var actualPos = divActuaLeftPos("flow");

	var dx =  Math.floor(goingTo - actualPos);
	if (-1*goingTo<halfContainer) {
		var doMath = Math.ceil(goingTo-(0.92*dx));
	} else {
		var doMath = Math.floor(goingTo-(0.92*dx));//Math.ceil((0.3*dx))
	}

	if (newMousepos!=null){
		setDivXPos("flow", doMath);
	} else {
		setDivXPos("flow", 0);
	}
}

function setDivXPos(ID, val){
	document.getElementById(ID).style.left = val+"px";
}

function divActuaLeftPos(id){
	return parseInt(document.getElementById(id).style.left);
}
function divWidth(id){
	return parseInt(document.getElementById(id).offsetWidth);
}
