var GaybizExitWidth = 600;
var GaybizExitHeight = 450;
var GaybizExitOpened = false;
var GaybizMouseIsin = false;
var GaybizExitTable = null;
var GaybizExitOverlay = null;
var GaybizNrp = -1;
var GaybizNrpShow = 1;

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function addResizeEvent(func) {
    var oldonresize = window.onresize;
    if (typeof window.onresize != 'function') {
        window.onresize = func;
    } else {
        window.onresize = function() {
            if (oldonresize) {
                oldonresize();
            }
            func();
        }
    }
}

function addScrollEvent(func) {
    var oldonscroll = window.onscroll;
    if (typeof window.onscroll != 'function') {
        window.onscroll = func;
    } else {
        window.onscroll = function() {
            if (oldonscroll) {
                oldonscroll();
            }
            func();
        }
    }
}

function addMouseOverEvent(func) {
    var oldonmousemove = document.onmousemove;
    if (typeof document.onmousemove != 'function') {
        document.onmousemove = func;
    } else {
        document.onmousemove = function() {
            if (oldonmousemove) {
                oldonmousemove();
            }
            func();
        }
    }
}

function GaybizGetPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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 if (document.documentElement && document.documentElement.scrollHeight){ // Explorer 6 & Mozilla strict mode
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	} else { // Explorer Mac...would also work in Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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 = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	return [pageWidth,pageHeight];
}

var GaybizWindowWidth = 0;
var GaybizWindowHeight = 0;
function GaybizGetClientSize(){
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			GaybizWindowWidth = document.documentElement.clientWidth; 
		} else {
			GaybizWindowWidth = self.innerWidth;
		}
		GaybizWindowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		GaybizWindowWidth = document.documentElement.clientWidth;
		GaybizWindowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		GaybizWindowWidth = document.body.clientWidth;
		GaybizWindowHeight = document.body.clientHeight;
	}	
	return true;
}

var GaybizWindowScroll = 0;
function GaybizGetScrollTop(){
	if (self.pageYOffset) {
		GaybizWindowScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		GaybizWindowScroll = document.documentElement.scrollTop;
	} else if (document.body) { // all other Explorers
		GaybizWindowScroll = document.body.scrollTop;
	} else {
		GaybizWindowScroll = 0; 
	}
	return true;
}

function GaybizMouseMove(e){
	if(GaybizExitOpened){return true;}
	var GaybizPointerY = 0;
	if(!e){var e = window.event;}
	if(e.pageY){
		GaybizPointerY = e.pageY;
	} else if(e.clientY){
		GaybizPointerY = (e.clientY + GaybizWindowScroll);
	}
	if(GaybizPointerY < (10 + GaybizWindowScroll)){
		if(!GaybizMouseIsin){GaybizNrp++;}
		GaybizMouseIsin = true;
		openGaybizExit(); 
		return true;
	} else {GaybizMouseIsin = false;}
	return true;
}
	
function GaybizExitInit(){
	if(GaybizExitOpened){closeGaybizExit();}
	var y = document.createElement('div');
	y.setAttribute('id','GaybizExitOverlay');
	y.style.position = 'absolute'; 
	y.style.top = 0; 
	y.style.left = 0; 
	y.style.width = 0; 
	y.style.height = 0; 
	y.style.zIndex = '90';
	y.style.background = "url('http://script.hysteriq.com/img/popup_overlay.png')";
	y.style.display = 'block';
	document.body.appendChild(y);
	var x = document.createElement('div');
	x.setAttribute('id','GaybizExitTable');
	x.style.position = 'absolute';
	x.style.left = '-1000px';
	x.style.top = '-1000px';
	x.style.width = (GaybizExitWidth+11) + 'px';
	x.style.height = (GaybizExitHeight+57) + 'px';
	x.style.display = 'block';
	y.appendChild(x);
	var xtext = '';
	xtext +='  <table width="'+ (GaybizExitWidth+11) +'" border="0" cellspacing="0" cellpadding="0">'; 
	xtext +='    <tr>';  
	xtext +='      <td><img src="http://script.hysteriq.com/img/popup_coin_hg.gif" width="5" height="30"></td>'; 
	xtext +='      <td style="background:url(http://script.hysteriq.com/img/popup_haut_bg.gif); width:'+ (GaybizExitWidth-23) +'px;"><nobr><img src="http://script.hysteriq.com/img/popup_spacer_hg.gif" width="10" height="30" align="absmiddle"><font face="arial" size="2" style="width:90%; color:#FFFFFF; filter:DropShadow(color=#000000, offx=1, offy=1)"><b>Avant de quitter ce site...</b></font></nobr></td>'; 
	xtext +='      <td style="background:url(http://script.hysteriq.com/img/popup_haut_bg.gif); width:23px; cursor:hand"><a href="#null" onclick="closeGaybizExit(); return false;"><img src="http://script.hysteriq.com/img/popup_haut_close.gif" width="23" height="30" border="0"></a></td>'; 
	xtext +='      <td><img src="http://script.hysteriq.com/img/popup_coin_hd.gif" width="6" height="30"></td>'; 
	xtext +='    </tr>'; 
	xtext +='    <tr>';  
	xtext +='      <td background="http://script.hysteriq.com/img/popup_gauche_bg.gif"></td>';
	xtext +='      <td colspan="2" bgcolor="#FFFFFF"><a href="http://acces.hysteriq.com/zone-dial_home.fr?ID=1107373676&amp;ref=dqGplanete&amp;size=DontQuit+600x450" target="_blank"><img src="http://promo.hysteriq.com/zone-dial_600x450_fr.biz" width="'+ GaybizExitWidth +'" height="'+ GaybizExitHeight +'" border="0" alt=""></a></td>'; 
	xtext +='      <td background="http://script.hysteriq.com/img/popup_droite_bg.gif"></td>'; 
	xtext +='    </tr>'; 
	xtext +='    <tr>';  
	xtext +='      <td><img src="http://script.hysteriq.com/img/popup_coin_bg.gif" width="5" height="27"></td>'; 
	xtext +='      <td style="background:url(http://script.hysteriq.com/img/popup_bas_bg.gif) right; width:'+ (GaybizExitWidth-23) +'px">&nbsp;</td>'; 
	xtext +='      <td style="background:url(http://script.hysteriq.com/img/popup_bas_bg.gif) left; width:23px"><img src="http://script.hysteriq.com/img/popup_spacer_bd.gif" width="23" height="27"></td>'; 
	xtext +='      <td><img src="http://script.hysteriq.com/img/popup_coin_bd.gif" width="6" height="27"></td>'; 
	xtext +='    </tr>'; 
	xtext +='  </table>';
	x.innerHTML = xtext;
	GaybizExitTable = x;
	GaybizExitOverlay = y;
}
	
function openGaybizExit(){
	if(GaybizExitOpened){return false;}
	if(GaybizNrp%GaybizNrpShow != 0){GaybizExitOpened = false; return false;}
	GaybizGetClientSize();
	var x = GaybizExitTable;
	x.style.left = ((GaybizWindowWidth/2) - ((GaybizExitWidth+11)/2)) + 'px';
	x.style.top = ((GaybizWindowHeight/2) - ((GaybizExitHeight+57)/2) + GaybizWindowScroll) + 'px';
	x.style.display = 'block';
	var y = GaybizExitOverlay;
	y.style.position = 'absolute';
	y.style.top = '0px';
	y.style.left = '0px';
	var arrayPageSize = GaybizGetPageSize();
	y.style.width = arrayPageSize[0] + 'px';
	y.style.height = arrayPageSize[1] + 'px';
	y.style.zIndex = '999';
	y.style.display = 'block';
	document.body.style.height = '100%';
	GaybizExitOpened = true;
	return false;
}

function closeGaybizExit(){
	if(!GaybizExitOpened){return false;}
	GaybizExitTable.style.display = 'none';
	GaybizExitOverlay.style.display = 'none';
	GaybizExitOpened = false;
	return false;
}

addLoadEvent(GaybizExitInit);
addResizeEvent(closeGaybizExit);
addScrollEvent(GaybizGetScrollTop);
addMouseOverEvent(GaybizMouseMove);
