var f = false;
$(document).ready(function(){
    $('a.show-inf').click(function(){
        if ($.browser.msie && $.browser.version == '6.0') $('select').css({display:'none'});
        $('div.fader').css({opacity:0.5, display:'block'});
        $('div.lightbox').css({display:'none'}).fadeIn(400);
        poupUp_height();
        f = true;
    })
    $('div.lightbox .close').click(function(){
        $('div.lightbox').fadeOut(400, function(){
            $('div.fader').css({display:'none'});
             if ($.browser.msie && $.browser.version == '6.0') $('select').css({display:'block'});
        });
    })
});

$(window).resize(function(){
    if (f) poupUp_height();
});


function poupUp_height()
{
        if ($('div.lightbox').length && $('div.fader').length)
	var _lightbox = $('div.lightbox').get(0);
	var _popup_table = $('div.fader').get(0);
	var _minWidth = document.getElementsByTagName('div')[0].offsetWidth;
	
	
	var _height = 0;
	var _width = 0;
	if (window.innerHeight) {
		_height = window.innerHeight;
		_width = window.innerWidth;
	} else {
		_height = document.documentElement.clientHeight;
		_width = document.documentElement.clientWidth;
	}
	var _page = document.getElementsByTagName("body")[0];
	if (_lightbox && _popup_table && _page) {
		if (_height > _page.offsetHeight) _popup_table.style.height = _height + "px";
		else _popup_table.style.height = _page.offsetHeight + "px";
		if (_width < _minWidth) {_popup_table.style.width = _minWidth + "px";} else {_popup_table.style.width = '100%'}
		
		if (_height > _lightbox.offsetHeight) {
			if (!window.innerHeight) {
				_lightbox.style.position = "absolute";
				_lightbox.style.top = document.documentElement.scrollTop + (_height - _lightbox.offsetHeight) / 2 + "px"
			} else {
				_lightbox.style.position = "fixed";
				_lightbox.style.top = (_height - _lightbox.offsetHeight) / 2 + "px";
			}
		}
		else {
			_lightbox.style.top = "0px";
			_lightbox.style.position = "absolute";
		}
		if (_width > _lightbox.offsetWidth) _lightbox.style.left = (_width - _lightbox.offsetWidth) / 2 + "px";
		else {_lightbox.style.left = "0px";_lightbox.style.position = "absolute";}
	}
}


//force l'affichage de la LightBox. *
//Ex appel : DisplayLightBox('plop', 'divMess', 'Message de test', 'BtnFermeture');
// ou splayLightBox('plop', 'divMess', 'Message de test', '');
function DisplayLightBox(IDDivLightBox, IDDivMessage, Message, IDCloseButton)
{
	IDDivMessage = "#" + IDDivMessage;
	IDDivLightBox = "#" + IDDivLightBox;
	IDCloseButton = "#" + IDCloseButton;
	
	$(IDDivLightBox).addClass("lightbox");
		
	$(IDDivMessage).html(Message) ;
	
	if ($.browser.msie && $.browser.version == '6.0') $('select').css({display:'none'});
	$('div.fader').css({opacity:0.3, display:'block'});
	$(IDDivLightBox).css({display:'none'}).fadeIn(400);
	poupUp_height();
	f = true;
	
	if(IDCloseButton != '')
	{
		$(IDCloseButton).click(function(){
        $(IDDivLightBox).fadeOut(400, function(){
            $('div.fader').css({display:'none'});
            	 if ($.browser.msie && $.browser.version == '6.0') $('select').css({display:'block'});
        	});
    	})
	}
}


