var oExpertiseFlag = true;

function showExpertiseName(pThis, pNom) {
  oExpertiseFlag = true;
	pThis.ExpertiseName = document.createElement("div");
	pThis.ExpertiseName.className = "expertiseNameDiv";
	pThis.ExpertiseName.style.top = (getY(pThis) - 80) + "px";
	pThis.ExpertiseName.style.right = document.body.clientWidth - (getX(pThis) + pThis.offsetWidth) + "px";
	pThis.ExpertiseName.innerHTML = pNom;
	
	pThis.ExpertiseNamePointe = document.createElement("div");
	pThis.ExpertiseNamePointe.className = "expertisePointe";
	pThis.ExpertiseNamePointe.style.top = (getY(pThis) - 56) + "px";
	pThis.ExpertiseNamePointe.style.right = document.body.clientWidth - (getX(pThis) + pThis.offsetWidth) + 16 + "px";

  if(oExpertiseFlag) {
    document.body.appendChild(pThis.ExpertiseNamePointe);
    document.body.appendChild(pThis.ExpertiseName);
  }
}

function hideExpertiseName(pThis) {
  oExpertiseFlag = false;
  if(pThis.ExpertiseName.parentNode) {
	  document.body.removeChild(pThis.ExpertiseName);
  }
  if(pThis.ExpertiseNamePointe.parentNode) {
	  document.body.removeChild(pThis.ExpertiseNamePointe);
  }
}

function showExpertise(pThis) {
    ClearExpertise();

    window.currentImg = pThis;
    window.currentImg.onmouseout = ClearExpertise;

    window.currentImg.parentNode.parentNode.style.backgroundColor = "#8d793e";
    for(var i = 0; i < $('expertises').getElementsByTagName("tr")[1].getElementsByTagName("td").length; i++) {
      $('desc' + (String((i+1)).length == 1 ? "0" + (i + 1) : (i + 1))).style.color = "white";
    }
    $(window.currentImg.id.replace(/img/, "desc")).style.color = "#e7b436";
    $('expertises').getElementsByTagName("tr")[1].style.visibility = "visible";

    window.MaxExpertiseFrames = 20;
    window.ExpertiseFrames = window.MaxExpertiseFrames;
    window.ExpertiseInterval = window.setInterval("MoveDiv();", 10);
}

function MoveDiv() {
  var oTop = 280;
  var oLeft = 250;
  var oWidth = 500;
  var oHeight = 300;
  var oOpacity = 40;

  if(window.ExpertiseFrames < 0) {
    window.clearInterval(window.ExpertiseInterval);
  } else {
    var tmpOpacity = (100 * window.ExpertiseFrames / window.MaxExpertiseFrames) + (oOpacity * (1 - window.ExpertiseFrames / window.MaxExpertiseFrames));

    for(var i = 1; i < 11; i++) {
      var oImages = $('img' + (String(i).length == 1 ? "0" + i : i));
      if(oImages != window.currentImg) {
        oImages.style.filter = "alpha(opacity=" + tmpOpacity + ")";
        oImages.style.MozOpacity = tmpOpacity / 100;
        oImages.style.opacity = tmpOpacity / 100;
      }
    }
  }
  window.ExpertiseFrames--;
}

function ClearExpertise() {

  if(window.ExpertiseInterval) {
    window.clearInterval(window.ExpertiseInterval);
    window.ExpertiseInterval = null;
  }

  for(var i = 1; i < 11; i++) {
    var oImages = $('img' + (String(i).length == 1 ? "0" + i : i));
    oImages.style.filter = 100;
    oImages.style.MozOpacity = 100;
    oImages.style.opacity = 100;
  }

  if(window.currentImg) {
    window.currentImg.parentNode.parentNode.style.backgroundColor = "transparent";
    window.currentImg = null;
  }

  $('expertises').getElementsByTagName("tr")[1].style.visibility = "hidden";

  if(window.ExpertiseTimeout) {
    window.clearTimeout(window.ExpertiseTimeout);
  }
}

function ChangePicture(pPhotoId) {
	$('expertiseImg').style.backgroundImage = 'url(' + URL_FICHIER + pPhotoId + ')';
}

var oSmallExpertiseDiv = null;
var oSmallExpertiseDivLeft = null;
var oCurrentHighlight = null;
function showSmallExpertiseName(pThis) {
	if(!pThis.onmouseout) {
		pThis.onmouseout = hideSmallExpertiseName;
	}
	
	var nBodyLength = document.body.offsetWidth - getX(pThis);
	
	oSmallExpertiseDiv = document.createElement("div");
	oSmallExpertiseDiv.innerHTML = $('smallExpertise' + pThis.id.substring(pThis.id.indexOf('img') + 3, pThis.id.length)).value;
	oSmallExpertiseDiv.style.position = "absolute";
	oSmallExpertiseDiv.style.top = (getY(pThis) - 16) + "px";
	oSmallExpertiseDiv.style.left = (getX(pThis) + 4) + "px";
	oSmallExpertiseDiv.style.height = "20px";
	oSmallExpertiseDiv.style.paddingRight = "6px";
	oSmallExpertiseDiv.style.background = "url(pages/images/expertises/small_expertise_right.gif) no-repeat top right";
	oSmallExpertiseDiv.style.whiteSpace = "nowrap";
	
	oSmallExpertiseDivLeft = document.createElement("div");
	oSmallExpertiseDivLeft.style.width = "6px";
	oSmallExpertiseDivLeft.style.height = "20px";
	oSmallExpertiseDivLeft.style.background = "url(pages/images/expertises/small_expertise_left.gif) no-repeat";
	oSmallExpertiseDivLeft.style.position = "absolute";
	oSmallExpertiseDivLeft.style.top = (getY(pThis) - 16) + "px";
	oSmallExpertiseDivLeft.style.left = (getX(pThis) - 2) + "px";
	
	document.body.appendChild(oSmallExpertiseDiv);
	document.body.appendChild(oSmallExpertiseDivLeft);
	
	if(oSmallExpertiseDiv.offsetWidth > nBodyLength) {
		oSmallExpertiseDiv.style.left = oSmallExpertiseDiv.offsetLeft - (oSmallExpertiseDiv.offsetLeft + oSmallExpertiseDiv.offsetWidth - document.body.offsetWidth) + "px";
		oSmallExpertiseDivLeft.style.left = (oSmallExpertiseDiv.offsetLeft - 6) + "px";
	}
	
	if((pThis.style.filter && pThis.style.filter.alpha && pThis.style.filter.alpha.opacity == 100) || pThis.style.MozOpacity == 1 || pThis.style.opacity == 1) {
		oCurrentHighlight = pThis;
	}
	
	if(oCurrentHighlight != pThis) {
	  pThis.style.filter = "alpha(opacity=100)";
	  pThis.style.MozOpacity = "1";
	  pThis.style.opacity = "1";
	}
}

function hideSmallExpertiseName() {
	try {
		document.body.removeChild(oSmallExpertiseDiv);
		document.body.removeChild(oSmallExpertiseDivLeft);
	} catch(ex) {}
		
	
	if(oCurrentHighlight != this) {
  	this.style.filter = "alpha(opacity=25)";
  	this.style.MozOpacity = "0.25";
  	this.style.opacity = "0.25";
  }
}
