
/*********************************
 * PEM EFFECTS @ 2008
 *********************************/


/*********************************************
*   FONCTION killEvent( event )
**********************************************/
function killEvent( event ){
  if ( !event ) event = window.event;

  if (event.stopPropagation) {
    event.stopPropagation();
  }
  event.cancelBubble = true;

}


/*********************************************
*   FONCTION getLeft(l)
**********************************************/
function getLeft(l) {
  // si et tant que nous trouvons un parent, nous additionnons les "LEFT" de tous les parents
  if (l.offsetParent) return (l.offsetLeft + getLeft(l.offsetParent));
  // sinon nous renvoyonsle LEFT
  else return (l.offsetLeft);
}


/*********************************************
*   FONCTION getTop(l)
**********************************************/
function getTop(l) {
  // si et tant que nous trouvons un parent, nous additionnons les "TOP" de tous les parents
  if (l.offsetParent) return (l.offsetTop + getTop(l.offsetParent));
  // sinon nous renvoyonsle TOP
  else return (l.offsetTop);
}


/*********************************************
*   FONCTION hideMe
**********************************************/
function hideMe( zeEl ){
  zeEl.style.display = 'none';
}

/*********************************************
*   FONCTION showMe
**********************************************/
function showMe( zeEl ){
  zeEl.style.display = 'block';
}

/*********************************************
*   FONCTION fadeElement
**********************************************/
function fadeElement( ElId ){
  // récupération de l'élément
  var myel = document.getElementById(ElId);
  // si un argument à été passé en paramètre (pour forcer la durée de timeout)
  if ( arguments.length > 1 ){
    // alors nous le récupérons
    i = arguments[1];
  }else{
    // sinon nous appliquons la valeur par défaut
    // en fonction du navigateur, la transparence n'est pas gérée de la même façon
    if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5){
      i = (myel.style.MozOpacity) * 100;
    }else{
      var op = myel.style.filter;
      op = op.substr( 14, ( op.length  - 15 ) );
      i = op * 1;
    }
//    alert( i );
    /*i = 100;*/
  }
  // en fonction du navigateur, la transparence n'est pas gérée de la même façon
  if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5){
    myel.style.MozOpacity = ( i / 100 );
  }else{
    myel.style.filter = "alpha(opacity=" + i + ")";
  }
	// si i est = 0, alors nous effaçons directement le fenêtre
	if ( i == 0 ) {
    // nous annulons le timeout si il y en a un
    clearTimeout(to_disappear);
    i = 100;
    myel.innerHTML = '';
    // en fonction du navigateur, la transparence n'est pas gérée de la même façon
    if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5){
      myel.style.MozOpacity = ( i / 100 );
    }else{
      myel.style.filter = "alpha(opacity=" + i + ")";
    }
    myel.style.display = 'none';
    return true;
  }
  // ensuite nous démarrons notre timer
	to_disappear = setTimeout( 'fadeElement( \''+ElId+'\', '+( i-1 )+')', 10 );
}


/*********************************************
*   FONCTION showPopupAnimation( myDiv, zeContent )
**********************************************/
function showPopupAnimation( myDiv, zeContent ){

  showModal();

  document.getElementById(myDiv).innerHTML = zeContent;
/*  document.getElementById(myDiv).style.overflow = 'hidden';*/
  document.getElementById(myDiv).style.visibility = 'hidden';
  document.getElementById(myDiv).style.display = 'block';
/*
  document.getElementById(myDiv).style.top = '30%';
  document.getElementById(myDiv).style.left = '45%';
*/
	array_page_size = getPageSize();
	array_page_scroll = getPageScroll();

	var middleHeight = ( ( array_page_size[3] * 1 ) / 2 ) - ((maxHeight * 1)/1.5);
	document.getElementById(myDiv).style.top = array_page_scroll[1]+middleHeight+'px';// 200 pour la marge top
	document.getElementById(myDiv).style.left = array_page_size[0]/2-((maxWidth * 1)/2)+'px';

  // en fonction du navigateur, la transparence n'est pas gérée de la même façon
  if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5){
    var maxWidth  = document.getElementById(myDiv).offsetWidth * 1 - 2;
    var maxHeight = document.getElementById(myDiv).offsetHeight * 1 - 2;
  }else{
    var maxWidth  = document.getElementById(myDiv).offsetWidth * 1;
    var maxHeight = document.getElementById(myDiv).offsetHeight * 1;
  }

  document.getElementById(myDiv).style.height = '0px';
  document.getElementById(myDiv).style.width  = '0px';

  document.getElementById(myDiv).style.visibility = 'visible';

  var ratio = ( maxWidth / maxHeight );

  animate( myDiv, maxWidth, maxHeight, ratio, 0, 1 );
}


/*********************************************
*   FONCTION hidePopupAnimation( Elem )
**********************************************/
function hidePopupAnimation( Elem ){

//  document.getElementById(Elem).style.overflow = 'hidden';

  // en fonction du navigateur, la transparence n'est pas gérée de la même façon
  if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5){
    var maxWidth  = document.getElementById(Elem).offsetWidth * 1 - 2;
    var maxHeight = document.getElementById(Elem).offsetHeight * 1 - 2;
  }else{
    var maxWidth  = document.getElementById(Elem).offsetWidth * 1;
    var maxHeight = document.getElementById(Elem).offsetHeight * 1;
  }

  var ratio = ( maxWidth / maxHeight );

  if ( maxWidth >= maxHeight ){
    var i = maxHeight - 1;
  }else{
    var i = maxWidth - 1;
  }

  animate( Elem, maxWidth, maxHeight, ratio, i, 0 );

}


/*********************************************
*   FONCTION animate( myDiv, maxWidth, maxHeight, ratio, i, direction )
**********************************************/
function animate( myDiv, maxWidth, maxHeight, ratio, i, direction ){

  if ( maxWidth >= maxHeight ){
    if ( i >= maxHeight ) {
      document.getElementById(myDiv).style.height = maxHeight  + 'px';
      document.getElementById(myDiv).style.width  = maxWidth   + 'px';
      clearTimeout(tod);
      return true;
    }
    if ( direction == 0 && i <= 5 ){
        document.getElementById(myDiv).style.visibility = 'hidden';
        document.getElementById(myDiv).style.height  = maxHeight + 'px';
        document.getElementById(myDiv).style.width   = maxWidth  + 'px';
        document.getElementById(myDiv).style.display = 'none';
        document.getElementById(myDiv).innerHTML = '';
        clearTimeout(tod);
        return true;
    }
    document.getElementById(myDiv).style.height = i + 'px';
    document.getElementById(myDiv).style.width  = Math.round( i * ratio ) + 'px';

  }else{
    if ( i >= maxWidth ) {
      document.getElementById(myDiv).style.height = maxHeight  + 'px';
      document.getElementById(myDiv).style.width  = maxWidth   + 'px';
      clearTimeout(tod);
      return true;
    }
    if ( direction == 0 && i <= 5 ){
        document.getElementById(myDiv).style.visibility = 'hidden';
        document.getElementById(myDiv).style.height  = maxHeight + 'px';
        document.getElementById(myDiv).style.width   = maxWidth  + 'px';
        document.getElementById(myDiv).style.display = 'none';
        document.getElementById(myDiv).innerHTML = '';
        clearTimeout(tod);
        return true;
    }
    document.getElementById(myDiv).style.width   = i + 'px';
    document.getElementById(myDiv).style.height  = Math.round( i * ratio ) + 'px';
  }


  if ( direction == 1 ){
    i = i + 20;
  }else{
    i = i - 20;
  }
  tod = setTimeout( 'animate( \''+myDiv+'\', '+maxWidth+', '+maxHeight+', '+ratio+', '+i+', '+direction+' )', 1 );

}

// -----------------------------------------------------------------------------------
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
// Code by Lokesh Dhakar
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Code by Lokesh Dhakar
// Edit for Firefox by pHaez
//
function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}