//Variables
var actualOpenDiv = 0;
var divToOpen = 0;
var divToClose = 0;

var isMoving = false;

var divToOpen_height = 0;
var divToClose_height = 0;
var maxHeight = 143;

var closeSpeed = 0;
var openSpeed = 0;

var coeffOpenSpeed = 10;
var coeffCloseSpeed = 4;
var speedBounce = 5;

var ie  = (navigator.appName == "Microsoft Internet Explorer");
var ie6 = (navigator.appVersion.indexOf('MSIE 6.0') == 17);

var scrollerWidth = 1505;
var rightWidth = 940;
var rightHiddenContent;

var currentStep = 1;

document.onkeypress = detectKeys;

makeHelpers();

//Fonctions
function detectKeys(keyStroke) {
  keyNum = (!document.all) ? keyStroke.which : event.keyCode;
  if (keyNum == 13) {
    if (currentStep != 3)
      sendForm(false);
  }
}

function checkResolution() {
  if (screen.width >= 1024)
    document.body.style.overflowX = "hidden";
}

function slice(firstPass) {
  if (scrollerWidth > 1010) {
    if (firstPass) {
      document.getElementById('rightContent').innerHTML = "";
  	}
      
    var scrollerSpeed = Math.ceil((scrollerWidth - 1010) / 10);
    scrollerWidth -= scrollerSpeed;
    document.getElementById('scroller').style.width = scrollerWidth + "px";
    
    var rightSpeed = Math.ceil((rightWidth - 460) / 10);
    rightWidth -= rightSpeed;
    document.getElementById('right').style.width = rightWidth + "px";
    document.getElementById('rightContent').style.width = (rightWidth-22) + "px";
    
    setTimeout("slice(false)", 25);
  } else {
    checkThis(1);
    document.getElementById('rightContent').innerHTML = rightHiddenContent;
    fixIe();
    getOodrive();
    getHotlineStatus();
    getNews();
    getJauge(true);
  }
}

function checkThis(id) {
	if (!isMoving) {
		if (actualOpenDiv == 0) {
			divToOpen = id;
			divToOpen_height = 0;
			enlargeBox();
		} else {
			if (actualOpenDiv == id) {
				divToClose = actualOpenDiv;
				divToClose_height = maxHeight;
				actualOpenDiv = 0;
				shrinkBox();
			} else {
				divToClose = actualOpenDiv;
				divToClose_height = maxHeight;
				divToOpen = id;
				divToOpen_height = 0;
				shrinkBox();
				enlargeBox();
			}
		}
	}
}

function shrinkBox() {
	if (divToClose_height > 0) {
		isMoving = true;
		closeSpeed = Math.ceil(divToClose_height / coeffCloseSpeed);
		divToClose_height -= closeSpeed;
		document.getElementById('moveUp'+divToClose).style.height = divToClose_height+"px";
		setTimeout("shrinkBox()", 25);
	} else {
		isMoving = false;
		divToClose = 0;
	}
}

function enlargeBox() {
	if (divToOpen_height < maxHeight) {
		isMoving = true;
		speed = Math.ceil((maxHeight - divToOpen_height) / coeffOpenSpeed) + speedBounce;
		divToOpen_height += speed;
		document.getElementById('moveUp'+divToOpen).style.height = divToOpen_height+"px";
		setTimeout("enlargeBox()", 25);
	} else {
		document.getElementById('moveUp'+divToOpen).style.height = maxHeight+"px";
		isMoving = false;
		actualOpenDiv = divToOpen;
		divToOpen = 0;
	}
}

function fixIe() {
	//Correction d'un bug IE
	if (ie)
		document.getElementById('right').style.height= "420px";
}

function makeHelpers() {
  var a = document.getElementsByTagName('a');
  var i = 0;
  for (i=0; i < a.length; i++) {
    if (a[i].className == 'helpButton') {
      a[i].innerHTML = "<div>" + a[i].title + "</div>";
      a[i].title = "";
      a[i].style.marginTop = "1px";
      a[i].className = 'helpButton initialized';
      a[i].onmouseover = function() {
        this.getElementsByTagName('div')[0].style.visibility = 'visible';
      }
      a[i].onmouseout = function() {
        this.getElementsByTagName('div')[0].style.visibility = 'hidden';
      }
    }
  }
  setTimeout('makeHelpers()', 1500);
}

function setCookies(id, udi) {
  document.location.href = "try.php?id="+id+"&udi="+udi;
  return false;
  //var today = new Date();
  //var expires = new Date(today.getYear()+1, today.getMonth(), today.getDate());
  //EcrireCookie("supportIdentification_id", id, expires);
  //EcrireCookie("supportIdentification_udi", udi, expires);
}
