// ------------------------------ //
// ALIGNEMENT VERTICAL DE LA PAGE //
// ------------------------------ //

var verticalAlign = {

	// ECOUTEUR
	addEvent: function(global, evnt, fctn, capture) {
		return document.addEventListener ?
		global.addEventListener(evnt, fctn, capture): global.attachEvent ?
		global.attachEvent('on' + evnt, fctn): false;
   },

	// ALIGNEMENT
	align: function() {
		var global = document.getElementById('global');
		var container = document.documentElement;
	
		// Récupération des hauteurs de la page et du conteneur "global"
		if (global && container) {
			
			// Hauteur de la page
			var containerHeight;
			if (container.innerWidth) {
				containerHeight = container.innerHeight;		// innerHeight : tout navigateur moderne excepté IE 6...
			}
			else {
				containerHeight = container.clientHeight;		// ... qui lui utilise : clientHeight...
			}
			
			// Hauteur du conteneur "global"
			var globalHeight;
			if (global.innerWidth) {
				globalHeight = global.innerHeight;			// IE
			}
			else {
				globalHeight = global.offsetHeight;			// tout navigateur moderne
			}
			
			// Récupération de l'entier supérieur le plus proche
			var y = Math.ceil((containerHeight - globalHeight) / 2);
			if (y < 0) {
				y = 0;
			}
			
			// Application
			global.style.position = "relative";
			global.style.top = y + "px";
		}
   },

};

// APPEL
verticalAlign.addEvent(window, 'resize', verticalAlign.align, false);
verticalAlign.addEvent(window, 'load', verticalAlign.align, false);
