/*
 *
 *	@titre: popup.
 *	@description: javascript popup - Le Veau.
 *	@auteur: neov - http://www.neov.net.
 *	@creation: 20090506.
 *	@modification: -.
 *
*/

var fadeTime = 300;
var lastOpen = null;
var test = 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, f)

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

// fermeture popup

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


$(function() {

	// ouverture popup
	$('#envoi-ami').showPop('#pop-envoi-recette');
	$('.affiche-confirmation').showPop('#pop-confirmation');
	$('.popup-plusInfo').showPop('#pop-plusInfo');
	if(pop==1)		{$('.affiche-confirmation').click()};
	
	if(popInfo==1)		{$('.popup-plusInfo').click()};

	// popup pour recette 
	$('#mailPrevisualiser').showPop('#pop-visualisation', test);
	
	//popup pour le veau et la tele
	$('[name^=envoiSon]').showPop('#pop-envoi-radio');
	$('#envoiTele').showPop('#pop-envoi-tele');

	// popup pour comment cuisiner le veau
	$('#envoiAmiCuisineVeau').showPop('#pop-cuisinerVeau');
	
	// popup pour video
	$('.show-video').showPop('#video', createFlash);
	
	// popup pour video
	$('.show-diapo').showPop('#diapo');
	
	// popup pour note
	$('.pop-notez-succes').showPop('#notation');
	//$('#note').showPop('#pop-note');


	// fermeture popup
	$('.pop-video .btn-pop .fermer').hidePop( 'afterHideVideo()' );
	$('.pop-diapo .btn-pop .fermer').hidePop();

	$('.btn-pop .fermer').hidePop();
	$('.annuler').hidePop();
});

// creation du playerTV
function createFlash () {
    swfobject.embedSWF(playerPath, "player-tv", "500", "300", "8.0.35",false, flashvars, parametre);
}

// destruction du flash dans player-tv
function afterHideVideo () {
    $('.pop-video .player-video').children().remove();
    $('.pop-video .player-video').append('<div id="player-tv"></div>'); 
 }