var oPopupWait = null;
var oPopup = null;

function CloseWait(){
	oPopupWait.hide();
}

function CloseImg(){
	oPopup.hide();
}

function initWait(){
	lightbox_Loading
}

function initWaitPopup(){
	oPopupWait = new Popup('lightbox_Loading', {
		fadeBackground: true,
		fadeBackgroundOption: {
			backgroundColor: '#888',
			onClick: function() {
				CloseWait();
			}
	 	}
	});
}

function initImagePopup(src){
	$('lightbox_Content').update('<div id="lighbox_ContentImage"><a href="javascript:;" onClick="CloseImg();" ><img id="imageFullScreen" style="border:none;" src="' + src + '"/></a></div>');
	$('lightbox_Content').hide();

	oPopup = new Popup('lightbox_Content', {
		fadeBackground: true,
		fadeBackgroundOption: {
			backgroundColor: '#888',
			onClick: function() {
				CloseImg();
			}
	 	}
	});
}

function ShowImage(srcImg) {
	//Prototype popup
	initWaitPopup();
	oPopupWait.show();

	initImagePopup(srcImg);
	$('imageFullScreen').observe('load', function() {
		oPopupWait.hide();
		oPopup.show();

		//on affiche l'image et on la resize
		$('lightbox_Content').show();
		ResizePopup(this);
		oPopup.onResize();
	}.bindAsEventListener($('imageFullScreen')));

	return false;
}

function ResizePopup(image){
	var width = image.width;
	var height = image.height;
	widthToRemove = 15;
	heightToRemove = 50;

	// Hack IE pour récupérer la taille
	if(Prototype.Browser.IE) {
		$('imageFullScreen').setStyle({ visibility: 'hidden' });
		$('imageFullScreen').show();

		imgSize = image.getDimensions();
		width = imgSize.width;
		height = imgSize.height;
		
		$('imageFullScreen').hide();
		$('imageFullScreen').setStyle({ visibility: 'visible' });
	}

	size=Prototype.Browser.getDimensions();

	if(width + widthToRemove > size.clientWidth) {
		height = height * (size.clientWidth - widthToRemove) / width;
		width = size.clientWidth - widthToRemove;
	}

	if(height + heightToRemove > size.clientHeight) {
		width = width * (size.clientHeight - heightToRemove) / height;
		height = size.clientHeight - heightToRemove;
	}

	// On modifie la taille de l'image afficher
	image.width = width;
	image.height = height;

	$('imageFullScreen').show();
}

function ouvrirVente(sAdresse, bAfficherPlaces, sHideDiv)
{
	if(bAfficherPlaces == 'true' || true)
	{
		width = '910';
		widthIE = '920';
		height = '680';
		heightIE = '683';
	}
	else
	{
		width = '340';
		widthIE = '350';
		height = '542';
		heightIE = '545';
	}

	if($(sHideDiv))
		$(sHideDiv).hide();

	initWaitPopup();
	oPopupWait.show();
//	$('lightbox_Content').update('<iframe scrolling="no" id="overlay" style="display: none; width: ' + width + ' !important; width: ' + widthIE + '; height: ' + height + ' !important; height: ' + heightIE + '; overflow: hidden; scroll: none;"></iframe>');

	if (Prototype.Browser.IE) {
		$('lightbox_Content').update('<iframe width="' + widthIE + '" height="' + heightIE + '" scrolling="no" id="overlay" style="display: none; overflow: hidden; scroll: none;"></iframe>');
		$('lightbox_Content').setStyle({
			'width': widthIE + 'px',
			'height': heightIE + 'px'
		});
	} else {
		$('lightbox_Content').update('<iframe width="' + width + '" height="' + height + '" scrolling="no" id="overlay" style="display: none; overflow: hidden; scroll: none;"></iframe>');
		$('lightbox_Content').setStyle({
			'width': width + 'px',
			'height': height + 'px'
		});
	}

	oPopup = new Popup('lightbox_Content', {
	 	fadeBackground: true,
	 	fadeBackgroundOption: {
	 		backgroundColor: '#888',
			onClick: function() {
				CloseImg();
				if($(sHideDiv))
					$(sHideDiv).show();
			}
		},
		shadow: true,
		onHide: function() {
			$('lightbox_Content').update('');
		}
	 });

//	oPopup=new Popup('lightbox_Content', {
//		fadeBackground: true,
//		fadeBackgroundOption: {
//			backgroundColor: '#888',
//			onClick: function() {
//		    	CloseImg();
//				if($(sHideDiv))
//					$(sHideDiv).show();
//	   		}
//	 	}
//	});

	$('overlay').src=sAdresse;
	$('overlay').observe('load', function() {
		oPopupWait.hide();
		oPopup.show();
		$('overlay').show();
		//oPopup.onResize();
	});

	return false;
}

Prototype.Browser.activateFlashOverlappingFix();