/*

 @titre: banque de france - geode
 @description: layout javascript
 @auteur: Neov - www.neov.net
 @creation: 20090119
 @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.6, filter:'Alpha(Opacity=60)'})
		.fadeIn(fadeTime);
	
	if ( $.browser.msie && $.browser.version < 7 ) {
		$('#srch-faq').css({visibility: 'hidden'});
		$('#srch-article').css({visibility: 'hidden'});
	}
}

// affichage popup
$.fn.showPop = function(el) { 
	$(this).each(
		function() {
			$(this).click(
				function() {
					var tPos = ( $(window).height() - $(el).height() )/2 + $(window).scrollTop();
					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;
				}
			);
		}
	);
	
}

// fermeture popup
$.fn.hidePop = function() {
	$(this).each(
		function() {
			$(this).click(
				function() {
					$('#masque').fadeOut(fadeTime);
					$(this).parent().parent().fadeOut(fadeTime);
					
					$('#masque').queue(
						function()
						{
							if ( $.browser.msie && $.browser.version < 7 ) {
								$('#srch-faq').css({visibility: 'visible'});
								$('#srch-article').css({visibility: 'visible'});
							}
							
							$(this).dequeue();
						}
					);
					
					return false;
				}
			);
		}
	);
}

// popup remerciement
$.fn.showElem = function(url) { 
	var tPos = ( $(window).height() - $(this).height() )/2 + $(window).scrollTop();
	var lPos = ( $(window).width() - $(this).width() )/2;
	
	var txtValid1 = 'Votre formulaire a bien été envoyé.<br /> Nous prendrons contact avec vous dans les plus brefs délais';
	var txtValid2 = 'Votre formulaire a bien été envoyé.';
	
	switch(url) {
		case '1' :
			$(this).find('p').html(txtValid1);
			break;
		
		case '2' :
			$(this).find('p').html(txtValid2);
			break;
		
		default :
			return false;
			break;
	}
	
	$(this)
		.fadeIn(fadeTime)
		.css({ top: tPos + 'px', left: lPos + 'px' });
		
	afficherMasque();
	
	return false;
}

$(function() {
		   
	// ouverture popup
	$('.mail').showPop('.popup-envoi');
	$('.contribution a').showPop('.popup-remarque');
	
	// fermeture popup
	$('.fermer').hidePop();
	
	// popup remerciement
	var url = $.getURLParam('m');
	if (url) $('.pop-envoi-valid').showElem(url);
	
});