/*



 @titre: unicef/baygon

 @description: popup javascript

 @auteur: Neov - www.neov.net

 @creation: 20090317

 @modification:



*/

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)

{ 
	$(this).each(
		function()
		{
			$(this).click(
				function()
				{
					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;
}

// fermeture popup

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

// fermeture popup video player

function closevideo()
{
	$('#masque').fadeOut(fadeTime);
	if(lastOpen) $(lastOpen).fadeOut(fadeTime);
	
}

function openVideoPush()
{
	afficherMasque();
	lastOpen = null;
}

$(function() {

	// ouverture popup
	$('#popcredit').showPop('#credit');
	$('#popcondition').showPop('#condition');
	$('#popprotection').showPop('#protection');
	$('.voircharte').showPop('#protection');
	$('.video-distrib').showPop('#video-distribution');
	$('.video-consult').showPop('#video-consultation');
	$('.partager-ami').showPop('#share');

	// fermeture popup
	$('.popup .btn_fermer a').hidePop();
		
});