// =============================================================================
// ================================ FORMULAIRE  ================================
// =============================================================================
// ====== Réalisé par Thomas Chiroux (www.chiroux.com)
// ======
// ====== v1.0 
// ======       
// ====== Dernières modif : 24/05/2006 : v1.0      
// =============================================================================

// PARAMETRAGE DU SCRIPT
var tjs_delai=20;
var tjs_max=2000;

// ==================================================================================================

function getWindowDim() {
	var x,y;

	if (self.innerHeight) {
		// all except Explorer
		x = self.innerWidth;
		y = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
			// Explorer 6 Strict Mode
			x = document.documentElement.clientWidth;
			y = document.documentElement.clientHeight;
		} else if (document.body) {
				// other Explorers 
				x = document.body.clientWidth;
				y = document.body.clientHeight;
			}
	/* // transformation en prototype : (?)		
	var dimensions = Element.getDimensions( element );
  var x = dimensions.width;
  var y = dimensions.height;
	*/		
	return [x,y];
}

// ==================================================================================================
function getScrollDim() {
	var x,y;
	if (self.pageYOffset) {
		// all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {
			// Explorer 6 Strict
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		} else if (document.body) {
				// all other Explorers
				x = document.body.scrollLeft;
				y = document.body.scrollTop;
			}
	return [x,y];
}

// ==================================================================================================
function getPageDim() {
	var x,y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight

	if (test1 > test2) {
		// all but Explorer Mac
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	} else {
		// Explorer Mac;
		//would also work in Explorer 6 Strict, Mozilla and Safari
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
	return [x,y];
}

// ==================================================================================================
function moveLayer() {

	element=$('infobox');
	if(element) {		
		var WindowDim = getWindowDim();
		var ScrollDim = getScrollDim();
		var PageDim = getPageDim();
		
		var layerTop = (5)+ ScrollDim[1];
		//var layerLeft = (WindowDim[0])-(element.style.width+5); //- (element.style.width+5);
		
		element.style.right = 5 + 'px';

		if (WindowDim[1] <= 1) {
			element.style.top = 5 + 'px';
			//Effect.Move ('infobox',{ x: 0, y: 5, mode: 'absolute'});
		}
		else {
			element.style.top = layerTop +'px';
			//Effect.Move ('infobox',{ x: 0, y: 300, mode: 'absolute'});
		}
	}
}

// ==================================================================================================
function updatePosition(timing) {
	moveLayer();
	
	setTimeout("updatePosition("+timing+")",timing);
}

// ==================================================================================================
function writediv(texte)
{
	element=$('infobox');	
	if(element) {		
		moveLayer();
		
		
		if(texte != '')
		{
        element.innerHTML = texte;
			  Effect.Appear('infobox', {queue:'end'} );

			setTimeout("updatePosition("+tjs_delai+")",tjs_delai);
		} else {

			 Effect.Fade('infobox', { duration : 0.5, queue:'end' });

      //element.innerHTML = texte;
			setTimeout("updatePosition("+tjs_max+")",tjs_max);
		}
	}
}


