// JavaScript Document
// Appel jquery

var fadeTime = 300;
var lastOpen = null;

function afficherMasque()
{
	var w = $('body').width();
	var mh = $('body').height();
	var ih = $(document).height();

	if ( mh < ih ) mh = ih;		

	$('#masque')
		.css({width: w + 'px', height: mh +'px', opacity: 0.5, filter:'Alpha(Opacity=50)'})
		.fadeIn(fadeTime);

}

// affichage popup

$.fn.showPop = function(el, _zFunctionCall)

{
	
	$(this).each(
		function()
		{
			$(this).click(
				function()
				{

					
					eval (_zFunctionCall) ;
					//if (f) f.call () ;

					var extraPos = 0;
					if( $(window).height() < $(el).height() ) extraPos = 150;
					var tPos = ( $(window).height() - $(el).height() )/2 + $(window).scrollTop() + extraPos;
					var lPos = ( $(window).width() - $(el).width() )/2;
					if (lastOpen != null) $(lastOpen).fadeOut(fadeTime);
					$(el)
						.fadeIn(fadeTime)
						.css({ top: tPos + 'px', left: lPos + 'px' });
					afficherMasque();
					lastOpen = el;
					return false;
				}
			);
		}
	);
	
}

$.fn.showElem = function(url)
{ 
	var tPos = ( $(window).height() - $(this).height() )/2 + $(window).scrollTop();
	var lPos = ( $(window).width() - $(this).width() )/2;
	
	$(this)
		.fadeIn(fadeTime)
		.css({ top: tPos + 'px', left: lPos + 'px' });
	
	afficherMasque();

	return false;
}



$.fn.hidePop = function()
{
	$(this).each(
		function()
		{
			$(this).click(
				function()
				{
					$('#masque').fadeOut(fadeTime);
					$(lastOpen).fadeOut(fadeTime);
					return false;
				}
			);
		}
	);
}

function hidePseudoPopup ()
{
	$('#masque').fadeOut(fadeTime);
	$(lastOpen).fadeOut(fadeTime);
	return false;
}

$(function() {
	
	// ouverture popup photo
	// $('.popUp-photos').showPop('#pop-evenement');
	// $('.photo').showPop('#zoom-photo');
	// $('.btn-mosaique').showPop('#pop-evenement');
	
	// ouverture popup video
	// $('.popUp-videos').showPop('#pop-listvideo');
	// $('.video').showPop('#lecteur-video');
	// $('.video-mosaique').showPop('#pop-listvideo');
	
	// fermeture popup
	// $('.btn-fermer-pop').hidePop();
			
});