jQuery(document).ready(function() {
	
	$(document).click(function(){
		$('.FB_Link').attr('target', '_new');
		return true;
	});
	
	if(getCookieVal('bookmarked').length>0){
		$('.myfav').show();	
	} else {
		$('.myfav').hide();	
	};

	$("#header li a").click(function(){
		$("#header li a").removeClass("on");
		$(this).addClass("on");
	});

	$(".uncarreparun a").hover(function(){
		$(this).children(".uncarreparunhighlight").show();
	},function(){
		$(this).children(".uncarreparunhighlight").hide();
	});

	$(".deuxcarrepardeux a").hover(function(){
		$(this).children(".deuxcarrepardeuxhighlight").animate({bottom:0}, 100);
	},function(){
		$(this).children(".deuxcarrepardeuxhighlight").animate({bottom:"-22px"}, 100);
	});

	$('.momentexception').click(function(){
		showPopinParticipate();
	});
	
	
	$('.link_legals').click(function(){
		var title = $(this).html();		
		$.get("/web/html/popins/" + C + "/" + l + "/legals.html", function(content){
			content = "<div class=\"maxsizepopin\"><div id=\"innerPopin\">" + content + "</div></div>";
			showCustomAlert(title, content, false);
			return false;
		});
	});
	
	$('#recevoirlastmoment').click(function(){
		optinFormContent = $('#optinTpl').html();
		optinTitle = $('#optinTpl').attr('rel');
		showCustomAlert(optinTitle, optinFormContent, false);
		$('.optindialog input').keyup(function(){
			chkOptinForm();	
		});
		$('#optinAgree').click(function(){
			chkOptinForm();	
		});
		$('.optindialog .buttoncontainer .btformulaire a').click(function(){
			sendOptinRegistration();
		});
		initOptinFields();
		return false;
	});
	
	$.History.bind(	function(state){
		activeMoment = state;
		if(state!=''){
			$('.fichesconteneur').html("");
			$('.fichesconteneurtransparent').hide();
			$('.fichesconteneur').css('width','0');
			$('.fichesconteneurtransparent').show();
			if(state!='moment-write-A') {
				$('.fichesconteneurtransparent').addClass("fichesconteneurtransparentmulti");
				url = "/" + C + "/" + l + "/moment/" + state + "?a=true";
				popwidth = 896;
				speed = 500;
			} else {
				url = "/" + C + "/" + l + "/" + state;
				popwidth = 446;
				speed = 250;
			}
			$('.fichesconteneur').load(url, function(){
				$('.fichesconteneurtransparent').show();
				$('.fichesconteneur').css('width',popwidth);
				$('.fichesconteneur').show();
				$('.fichesconteneur').css('width','');
				FB.init('<?php echo FB_API_KEY; ?>', '/web/html/xd_receiver.htm');
			});
		} else {
			//$('.fichesconteneurtransparent').hide();
			//$('.fichesconteneurtransparentinter').html('');
		}
	});
	
	jQuery('#mycarousel').jcarousel();
	
	$('#customalert .close').click(function(){
		$('#customalert').hide();
	});
	
	$('.removeFavorite a').click(function(){
		removeCookieVal('bookmarked', $(this).attr('rel'));
	});
	
		
	/* DEBUT CUFON */
	
	Cufon.replace('h2', { fontFamily: 'helvetica' });
	Cufon.replace('h3', { fontFamily: 'helvetica' });
	Cufon.replace('.fontfamily', { fontFamily: 'helvetica' });
	
	Cufon.replace('h2', { fontFamily: 'helvetica' });
	Cufon.replace('h3', { fontFamily: 'helvetica' });
	Cufon.replace('.fontfamily', { fontFamily: 'helvetica' });
	
	/* FIN CUFON */
	


/*	
	$('#homePushPerfume').click(function(){
		var content = "<script type=\"text/javascript\">var flashvars = { xml:'/web/xml/video.xml'}; var attributes = { id:'videoPlayer' }; var params = { quality:'best', menu:'false', scale:'noscale', bgColor:'#FFFFFF', wmode:'transparent' }; swfobject.embedSWF(\"web/swf/video_player.swf\", \"customalert_msg\", \"400\", \"300\", \"9\", \"web/swf/expressInstall.swf\", flashvars, params, attributes); </script>";		
		showCustomAlert(' ', content, false)
	});
*/
	/* Code a revoir : gere l'affichage de la popin de participation qui s'affiche par défaut sur le site */
	if( $.cookie("popinParticipate") != "true") {showPopinParticipate(); }
	$.cookie("popinParticipate", "true", { path:'/', domain: '.'+document.location.hostname});
	//showPopinParticipate();
});

function showPopinParticipate(){

	$('.fichesconteneur').html("");
		$('.fichesconteneurtransparent').hide();
		$('.fichesconteneur').css('width','0');
		$('.fichesconteneurtransparent').show();
		$('.fichesconteneur').load('/'+C+'/'+l+"/moment-write-A/", function(){
			$('.fichesconteneur').animate({width:446}, 250, "linear", function(){
				$('.fichesconteneur').css('width','');
			});
		});
}

function closeIntro(){
	$('#flashcontainer').remove();
}

function switchPerfume(){
	$('.motifB .parfum1').toggle();
	$('.motifB .parfum2').toggle();
}

function setCookieVal(cookieName, val){
	$.cookie(cookieName, val, { expires: 2000, path:'/', domain: '.'+document.location.hostname});
	return false;
}
function removeCookieVal(cookieName, val){
	var newCookieVal = getCookieVal(cookieName).replace('|' + val + '|',"")
	setCookieVal(cookieName,newCookieVal);
	if(newCookieVal=='') document.location.href = '/';
	else document.location.reload();
}

function addCookieVal(cookieName, val){
	setCookieVal(cookieName, getCookieVal(cookieName) + '|' + val + '|');
	return false;
}
		
function getCookieVal(cookieName){
	return ($.cookie(cookieName)==null) ? '' : $.cookie(cookieName);
}

function isInCookie(cookieName, val){
	if(getCookieVal(cookieName)==null){
		return false;
	}
	else {
		return (getCookieVal(cookieName).indexOf('|'+val+'|')>=0);
	}
}

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   return reg.test(email);
}

function showCustomAlert(title, msg, autoHide){
	title = (title!='' && msg!='') ? title+'<br/><br/>' : '';
	$('#customalert .title').html(title);
	$('#customalert .msg').html(msg);
	$('#customalert').show();
	$('#innerPopin').css('visibility','hidden');
	setTimeout("jQuery('#innerPopin').jScrollPane(); $('#innerPopin').css('visibility','visible');", 20);
	if(autoHide) setTimeout("$('#customalert').hide()",4500);
	return true;
}

function isdefined( variable){
    return (typeof(window[variable]) == "undefined")?  false: true;
}

