function lightbox_onclose()
{
	// 	scan la position du curseur
	if (window.Event){
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = isBrowserIsGoingToBeClosed;
}

function isBrowserIsGoingToBeClosed(e)
{
	var posy = 0;
	var posx = 0;
	if (typeof(posy1) == "undefined" )
	{
		posy1 = 0;
		posy2 = 0;
		posy3 = 0;
	}
	
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	// reajuste la position en fonction du scroll de la fenetre:
	posx -= document.documentElement.scrollLeft;
	posy -= document.documentElement.scrollTop;
	browserWindowWidth = top.window.document.body.offsetWidth;

	// cursor touche la zone de fermeture
	if(posy <= 40 && posx >= (browserWindowWidth/1.3))
	{
		posy3 = posy2;
		posy2 = posy1;
		posy1 = posy;
		// test si le cursor est en train de monter 
		if (posy1 < posy2 && posy1 < posy3)
		{
			show_lightbox();
			//window.location.href ='http://www.extrait-gratiz.com/test/stop.php';
		}
	} else {
		posy1 = 0;
		posy2 = 0;
		posy3 = 0;
	}
}

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;
}

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;
}


function center_lightbox()
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	var lightbox = document.getElementById('lightbox');
	lightbox.style.top = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - lightbox.style.height) / 2) + 'px';
	lightbox.style.left = ((arrayPageSize[0] - 20 - lightbox.style.width) / 2) + 'px';

	var overlay = document.getElementById('overlay');
	overlay.style.height = arrayPageSize[1] + 'px';

	var stop = document.getElementById('stop');
	stop.style.top = arrayPageScroll[1] + 'px';
}

function show_lightbox()
{
	center_lightbox();

	var overlay = document.getElementById('overlay');
	overlay.style.display = 'block';
	overlay.onclick = function () {hide_lightbox(); return false;}

	document.getElementById('lightbox').style.display = 'block';
	document.getElementById('stop').style.display = 'block';
	document.getElementById('video_flv').style.display = 'none';
}

function hide_lightbox()
{
	document.getElementById('stop').style.display = 'none';
	document.getElementById('lightbox').style.display = 'none';
	document.getElementById('overlay').style.display = 'none';
	document.getElementById('video_flv').style.display = 'block';
}

window.onresize = function() {
	center_lightbox();
}

window.onscroll = function() {
	center_lightbox();
}
