var oPopupWait = null;
var oPopup = null;

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

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

function initWait(){
	lightbox_Loading
}

function initWaitPopup(){
	//if( oPopupWait == null){
		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();
	//if( oPopup == null){
		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(){
		//alert('view'),
		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 recup 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'});
		//alert(width+"/"+height);
	}

	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')
	{
		width = '910px';
		widthIE = '920px';
		height = '680px';
		heightIE = '6683px';
	}
	else
	{
		width = '340px';
		widthIE = '350px';
		height = '542px';
		heightIE = '545px';
	}
	
	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>');
	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();
		$("overlay").show();
		oPopup.show();
		oPopup.onResize();
	});
	return false;
}

Prototype.Browser.activateFlashOverlappingFix();