//Fonctions de gestion de la Greybox
function greyBoxCommun(data, close, type){
	greyBoxInsertBlocks(close);
	
	if(type == 'element'){
		content_html = $(data).html();
	}
	if(type == 'html'){
		content_html = data;
	}
	
	if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
		windowHeightIeFix = $(document.body).height();
		if($(document.body).height() == 0){
			var windowHeightIeFix = 670;
		}
		$('#overlay').css('height',windowHeightIeFix+'px');
		$('#overlay').show();
		$('#greyBox').show();
		$(document).scrollTop(0);
		if(type == 'ajax'){
			$('#greyBoxContent').load(data,'',function(){
				pngFix();
				$('select:not(.protect)').each(function(){$(this).hide();});
			});
		}
		else {
			$('#greyBoxContent').html(content_html);
			pngFix();
			$('select:not(.protect)').each(function(){$(this).hide();});
		}
	}
	else{
		$('#overlay').css('opacity','0');
		$('#overlay').show();
		$('#overlay').fadeTo('slow',0.6,function(){
			if(type == 'ajax') {
				$('#greyBoxContent').load(data,'',function(){});
			}
			else {
				$('#greyBoxContent').html(content_html);
			}
			$('#greyBox').show();
			$(document).scrollTop(0);
		});
	}
	
	return false;
}
function greyBoxShow(page, close){
	return greyBoxCommun(page, close, 'ajax');
}
function greyBoxShowHtml(contentHtml, close){
	return greyBoxCommun(contentHtml, close, 'html');
}
function greyBoxShowElement(elementSelector, close){
	return greyBoxCommun(elementSelector, close, 'element');
}
function greyBoxInsertBlocks(close) {
	if(!$('#overlay').length){
		$('body').append('<div id="overlay"></div>');
	}
	if(!$('#greyBox').length){
		$('body').append('<div id="greyBox"><div class="top"></div><div class="content"><div id="greyBoxContent"><div id="greyBoxLoader"></div></div></div><div class="bottom"></div><div onclick="greyBoxHide();" class="close">'+close+'&nbsp;<img src="/medias/img/greybox/close.gif" alt="Fermer cette fenêtre" /></div></div>');
	}
	else
	{
		$('#greyBoxContent').html('<div id="greyBoxLoader"></div>');
	}
}
function greyBoxHide(){
	if(jQuery.browser.msie && jQuery.browser.version=="6.0"){
		$('#overlay').hide();
		$('#greyBox').hide();
		$('select').each(function(){$(this).show();});
	}
	else{
		$('#greyBox').fadeOut('medium',function(){
			$('#overlay').fadeOut('fast');
		});
	}
	
	return false;
}
