	var nbopen = false;
	var nbconfitv;

	var INPUT_NOM = "Nom";
	var INPUT_PRENOM = "Prénom";
	var INPUT_SOCIETE = "Société";
	var INPUT_MAIL = "E-mail";

	var NEWS_ERROR = "On manque d'entra&icirc;nement au Scrabble&nbsp;? V&eacute;rifier vos informations.";
	var NEWS_CONFIRM = "MERCI&nbsp;! Vous recevrez tr&egrave;s bient&ocirc;t des nouvelles de Funktrip.";
	var NEWS_SERVEUR_ERROR = "Une erreur est survenue.<br/>Veuillez rééssayer ultérieurement.";

	function initNewsFields() {
		if($('#nbnom').val()=="") $('#nbnom').val(INPUT_NOM);
		if($('#nbprenom').val()=="") $('#nbprenom').val(INPUT_PRENOM);
		if($('#nbsociete').val()=="") $('#nbsociete').val(INPUT_SOCIETE);
		if($('#nbmail').val()=="") $('#nbmail').val(INPUT_MAIL);
	}

	function resetNewsFields() {
		$('#nbnom').val(INPUT_NOM);
		$('#nbprenom').val(INPUT_PRENOM);
		$('#nbsociete').val(INPUT_SOCIETE);
		$('#nbmail').val(INPUT_MAIL);
		$('#nbmsg').html("");
	}

	function testNewsFields() {
		var err = false;
		if($('#nbnom').val()=="" || $('#nbnom').val()==INPUT_NOM) err = true;
		if($('#nbprenom').val()=="" || $('#nbprenom').val()==INPUT_PRENOM) err = true;
		if($('#nbmail').val()=="") err = true;

		var verif = /^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/
		if (verif.exec($('#nbmail').val().toLowerCase()) == null) err = true;

		return (err==false);
	}

	function init() {
		$('#tbnews').click(function() {
			if (!nbopen) {
				initNewsFields();
				$("#newsbar").animate({"margin-top":"0px"},{"duration": 700, "easing": "easeOutQuad"});
				$("#background").animate({"height": $("#background").height()-50+"px"},{"duration": 500, "easing": "easeOutQuad"});
				nbopen = true;
			}
			else {
				exitNewsbar();
			}
			exitSocial();
		});

		$('#nbclose a').click(function(){
			exitNewsbar();
		});

		$('#nbok a').click(function(){
			if (testNewsFields()) {

				var param = new Object();
				param.mode = "news";
				if ($('#nbnom').val() != "" && $('#nbnom').val() != INPUT_NOM) param.nom = $('#nbnom').val();
				if ($('#nbprenom').val() != "" && $('#nbprenom').val() != INPUT_PRENOM) param.prenom = $('#nbprenom').val();
				if ($('#nbsociete').val() != "" && $('#nbsociete').val() != INPUT_SOCIETE) param.societe = $('#nbsociete').val();
				if ($('#nbmail').val() != "" && $('#nbmail').val() != INPUT_MAIL) param.email = $('#nbmail').val().toLowerCase();

				$.post('http://www.funktrip.com/wp-content/themes/funktrip/lib/record.php', param,
					  function(data) {
						  if (data=="ok") {
							  $('#nbmsg').html(NEWS_CONFIRM);
							  $('#nbmsg').css("color","#525252");
							  nbconfitv = window.setInterval(function() {
								  exitNewsbar();
							  },2000);
						  } else {
								$('#ctalert').html(NEWS_SERVEUR_ERROR);
								$('#ctalert').css("color","#f00085");
								nbconfitv = window.setInterval(function() {
								  exitNewsbar();
								},2000);
						  }
					  });
			} else {

				$('#nbmsg').html(NEWS_ERROR);
				$('#nbmsg').css("color","#f00085");
			}
		});

		$('#tbsoc a').click(function() {
			if (!socopen) {
				$('#social').fadeIn();

				$('#social').mouseout(function() {
					socover = false;
				});
				$('#social').mouseover(function() {
					socover = true;
				});
				soclitv = window.setTimeout("startSocExitItv()",1000);
				socopen = true;
			} else {
				exitSocial();
			}

			exitNewsbar();
		});
	}




	var socopen = false;
	var soclitv;
	var socitv;
	var socover = false;

	function startSocExitItv() {
		window.clearTimeout(soclitv);
		soclitv = null;
		socitv = window.setInterval(function() {
			if (!socover) exitSocial();
		},500);
	}



	function initNewsbar() {


		$('#inputs').find('input').focus(function() {

			initNewsFields();

			if ($(this).val()==INPUT_NOM || $(this).val()==INPUT_PRENOM || $(this).val()==INPUT_SOCIETE || $(this).val()==INPUT_MAIL) {
				$(this).attr("value", "");
			}

		});

		$('#inputs').find('input').blur(function() {

			if($(this).val() == "") {
                 if($(this).attr("name") == "nom") $(this).val(INPUT_NOM);
                 if($(this).attr("name") == "prenom") $(this).val(INPUT_PRENOM);
                 if($(this).attr("name") == "societe") $(this).val(INPUT_SOCIETE);
                 if($(this).attr("name") == "email") $(this).val(INPUT_MAIL);
            };

		});

	}

	function initSocial() {
		$('#socfb a').click(function(){
			exitSocial();
		});
		$('#soctw a').click(function(){
			exitSocial();
		});
		$('#socrss a').click(function(){
			exitSocial();
		});
	}

	function exitNewsbar() {
		if (nbopen) {
			if (nbconfitv){
				window.clearInterval(nbconfitv);
				nbconfitv = null;
			}
			$("#newsbar").animate({	"margin-top": "-50px"}, {"duration": 500,"easing": "easeOutQuad"});
			$("#background").animate({"height": $("#background").height() + 50 + "px"}, {"duration": 700,"easing": "easeOutQuad"});
			nbopen = false;

			resetNewsFields();
		}
	}

	function exitSocial(){
		if (socopen) {
			window.clearInterval(socitv);
			socitv = null;

			if (soclitv) {
				window.clearTimeout(soclitv);
				soclitv = null;
			}

			$('#social').fadeOut();
			socopen = false;
			socover = false;
			$('#social').mouseout(null);
			$('#social').mouseover(null);

		}
	}

	function replaceFooter() {
		var hauteur = Math.max($(window).height(), $(document).height());
		var decal = ($(document).height()<=$(window).height()) ? $('#footer').height()-40 : 50;

		$('#footer').css("margin-top", (hauteur+decal)+"px");
	//	alert(hauteur+decal);
	}

	function resizeBg() {

		var hauteur = Math.max($(window).height(), $(document).height());

		if (nbopen) $("#background").css("height",(hauteur - 50) + "px");
		else $("#background").css("height",hauteur + "px");
	}
	function resizeGfxEvt() {
		$("#gfxevent").css("width",$(window).width()-($("#page").position().left-($("#page").width()/2))+"px");
	}

	$(window).resize(function(){
		resizeBg();
		resizeGfxEvt();
	});
