var gnTimerPage = 0;
var gnRatePage = 0;
var gsPosition = "";
var gsUrl = "";

function loadTranslations( langue )
{
	var anchors = (this.isFrame) ? window.parent.frames[window.name].document.getElementsByTagName('a') : document.getElementsByTagName('a');
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		var relAttribute = String(anchor.getAttribute('rel'));
		if (anchor.getAttribute('href')) {
			if (relAttribute.toLowerCase().match('transition')) {
				if( langue == 'EN' )
				{
					anchor.onclick = function () { disappear( this.id, this.getAttribute('href')+'home-'+this.id+'.htm' ); return false; }
				}
				else
				{
					anchor.onclick = function () { disappear( this.id, this.getAttribute('href')+'accueil-'+this.id+'.htm' ); return false; }
				}
			}
		}
	}
}

function callFadeInPage()
{
   gnRatePage = 0;
	var wrapper = document.getElementById('wrapper');
	gnTimerPage = setInterval("fadeInPage()", 20);
}

function fadeInPage()
{
   var wrapper = document.getElementById('wrapper');
	if (gnRatePage == 0) {
      if (gsPosition == "right" || gsPosition == "left") {
         wrapper.style.left = '';
         wrapper.style.marginLeft = '';
      }
      if (gsPosition == "top" || gsPosition == "bottom") {
         wrapper.style.top = '';
         wrapper.style.marginTop = '';
      }
      wrapper.style.visibility = 'visible';
	}
   gnRatePage += 0.05;
   document.body.style.overflow = 'hidden';
   if (gsPosition == "left") {
      var value = (-490 * gnRatePage);
      wrapper.style.marginLeft = value + "px";
      wrapper.style.left = Math.round(50 + (1 - gnRatePage)*100/2) + "%";
   }
   if (gsPosition == "right") {
      var value = (-490 * gnRatePage);
      wrapper.style.marginRight = value + "px";
      wrapper.style.right = Math.round(50 + (1 - gnRatePage)*100/2) + "%";
   }
   if (gsPosition == "top") {
      var value = (-315 * gnRatePage);
      wrapper.style.marginTop = value + "px";
      wrapper.style.top = Math.round(50 + (1 - gnRatePage)*100/2) + "%";
   }
   if (gsPosition == "bottom") {
      var value = (-315 * gnRatePage);
      wrapper.style.marginBottom = value + "px";
      wrapper.style.bottom = Math.round(50 + (1 - gnRatePage)*100/2) + "%";
   }
   if (gnRatePage >= 1) {
      document.body.style.overflow = 'auto';
	 	clearInterval( gnTimerPage );
		wrapper.style.marginBottom = "";
      wrapper.style.marginRight  = "";
      wrapper.style.marginTop  = "-315px";
		wrapper.style.marginLeft = "-490px";
      wrapper.style.right  = "";
      wrapper.style.left   = "50%";
      wrapper.style.top    = "50%";
      wrapper.style.bottom = "";
   }
}

function appear( asPosition )
{
	gsPosition = asPosition;
   callFadeInPage();
}
	
function callFadeOutPage()
{
   gnRatePage = 1;
   gnTimerPage = setInterval("fadeOutPage()", 20);
}

function fadeOutPage()
{
   var wrapper = document.getElementById('wrapper');
   if (gnRatePage == 1) {
      if (gsPosition == "right" || gsPosition == "left") {
         wrapper.style.left = '';
         wrapper.style.marginLeft = '';
      }
      if (gsPosition == "top" || gsPosition == "bottom") {
         wrapper.style.top = '';
         wrapper.style.marginTop = '';
      }
   }
   gnRatePage -= 0.05;
   document.body.style.overflow = 'hidden';
   if (gsPosition == "left") {
      var value = (-490 * gnRatePage);
      wrapper.style.marginRight = value + "px";
      wrapper.style.right = Math.round(50 + (1 - gnRatePage)*100/2) + "%";
   }
   if (gsPosition == "right") {
      var value = (-490 * gnRatePage);
      wrapper.style.marginLeft = value + "px";
      wrapper.style.left = Math.round(50 + (1 - gnRatePage)*100/2) + "%";
   }
   if (gsPosition == "top") {
      var value = (-315 * gnRatePage);
      wrapper.style.marginBottom = value + "px";
      wrapper.style.bottom = Math.round(50 + (1 - gnRatePage)*100/2) + "%";
   }
   if (gsPosition == "bottom") {
      var value = (-315 * gnRatePage);
      wrapper.style.marginTop = value + "px";
      wrapper.style.top = Math.round(50 + (1 - gnRatePage)*100/2) + "%";
   }
   if (gnRatePage <= 0) {
	  	wrapper.style.display = 'none';
		document.location.href = gsUrl;
      clearInterval( gnTimerPage );
   }
}

function disappear(asPosition, asUrl)
{
   gsUrl = asUrl;
	gsPosition = asPosition;
	callFadeOutPage();
}

