$(document).ready(function() {
		
	/* Connexion / Mot de passe perdu */
	
	$('#FormLoggerUtilisateur input').focus(function() { $('#LoggerUtilisateur_Err').slideUp('fast'); });
	
	$('#FormMDPUtilisateur input').focus(function() { $('#MDPUtilisateur_Err').slideUp('fast');	});
	
	$('#GoMDP').click(function() {
		InitialiserFormLoggerUtilisateur();
		InitialiserFormMDPUtilisateur();
		$('#LoggerUtilisateur').slideUp('fast', function() {
			$('#MDPUtilisateur').slideDown('fast');
		});
	});
	
	$('#GoLogger').click(function() {
		InitialiserFormLoggerUtilisateur();
		InitialiserFormMDPUtilisateur();
		$('#MDPUtilisateur').slideUp('fast', function() {
			$('#LoggerUtilisateur').slideDown('fast');
		});
	});
	
	/* 	
	$('#FormLoggerUtilisateur input').attr('readonly','readonly');
	$('div.BoxConnexion').fadeTo(0, 0.5);
	*/
		
	/* Initialisation */
	InitialiserFormLoggerUtilisateur();
	InitLabels();
		
	/* Stuff */
	jQueryUI();
	jFancy();
	InitializeCufon();
});

function jQueryUI() {
	$("button.uiButton").button().mouseout(function() { $(this).removeClass('ui-state-focus'); });	
	$(".RadioSet").buttonset();
	
	$('.tooltip, .tooltip-s, .tooltip-n, .tooltip-w, .tooltip-e, .tooltip-ne, .tooltip-nw, .tooltip-se, .tooltip-sw').mouseover(function() { $(this).css('cursor', 'help'); });
	
	$('.tooltip').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 's'});
	$('.tooltip-s').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 's'});
	$('.tooltip-n').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 'n'});
	$('.tooltip-w').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 'w'});
	$('.tooltip-e').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 'e'});
	
	$('.tooltip-ne').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 'ne'});
	$('.tooltip-nw').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 'nw'});
	
	$('.tooltip-se').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 'se'});
	$('.tooltip-sw').tipsy({title: 'alt', delayIn: 500, offset: 5, gravity: 'sw'});
	
	$('.maskTelephone').setMask('09 99 99 99 99');
	$('.maskDate').setMask('39/19/9999');
}

function jFancy() {
	$('a.fancy').fancybox({ title: $('img',this).attr('alt') ,titlePosition : 'inside', 'zoomOpacity'	: true,	'zoomSpeedIn'	: 500, 'zoomSpeedOut'	: 500 , centerOnScroll : true});
	
	$('a.zoomable').each(function() {
		$(this).prepend('<div class="fancyMagnifier"></div>');
	});
	$('a.zoomable').hover(function() {
		$('.fancyMagnifier', this).show();
	}, function() {
		$('.fancyMagnifier', this).hide();
	});
}

/* CUFON */
function InitializeCufon()
{		
	if ((Cufon != "undefined") && (true)) {

		Cufon.set('forceHitArea',true);
		
		/* Navigation */
		Cufon.replace($('#header-navigation .btn'), { fontFamily: 'NettoOT-Bold', textTransform: 'uppercase', hover: { color: '#267C17' } });
		
		/* Slider */
		Cufon.replace($('.header-slider-big-informations-titre, .header-slider-big-informations-sstitre'), { fontFamily: 'NettoOT-Bold', textTransform: 'uppercase' });
		Cufon.replace($('.header-slider-big-informations-texte1, .header-slider-big-informations-texte2'), { fontFamily: 'NettoOT-Bold', textTransform: 'uppercase' });
		Cufon.replace($('.header-slider-big-informations-lien-titre, .header-slider-big-informations-lien-sstitre'), { fontFamily: 'NettoOT-Bold', textTransform: 'uppercase' });
		Cufon.replace($('.header-slider-sml-title'), { fontFamily: 'NettoOT-Bold', textTransform: 'uppercase' });
		
		/* Titles */
		Cufon.replace($('.ActualitesBoxAccListItemTitle, .ActualitesBoxAccListItemInfo'), { fontFamily: 'NettoOT-Bold', textTransform: 'uppercase' });
		Cufon.replace($('.VVeryBigTitle, .VVeryBigSubTitle, .VBigTitle, .VBigSubTitle, .VTitle, .VSubTitle, .VMidTitle, .VMidSubTitle, .VSmlTitle, .VSmlSubTitle, .VMidTitleBlack, .VMidSubTitleBlack'), { fontFamily: 'NettoOT-Bold', textTransform: 'uppercase' });

		/* Links */
		Cufon.replace($('.GreyLink'), { fontFamily: 'NettoOT-Bold', textTransform: 'uppercase', hover: { color: '#267C17' } });
	}
}

function InitLabels()
{
	$(".Watermarked").each(function(){
		$(this).Watermark($(this).attr('title'),"#848484");
	});

	/* $("input[type=password]").each(function(){
		$(this).hide();
		$(this).after('<input type=text style="width:'+$(this).width()+'px" class="fakePassword" trueField="'+$(this).attr('id')+'" name="fake_'+$(this).attr('name')+'" id="fake_'+$(this).attr('id')+'" value="'+$(this).attr('title')+'">');
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).hide();
			$('#fake_'+$(this).attr('id')).val('Mot de passe').show();
		}
	});
	
	$('.fakePassword').click(function(){
		var trueField = $(this).attr('trueField');
		$(this).hide();
		$('#'+trueField).val('').show().focus();
	}); */
	
}

function TelechargerDocument(id_document)
{
	// Execution du formulaire
	$.ajax({
	  type: "POST",
	  url: "./p_documents.php",		  
	  data: '&FormAction=TelechargerDocument&id_document='+id_document,
	  dataType : 'html',
	  cache: false,
	  async: true,
	  success: function(data) {	eval(data); return(false); },      
	  error: function() { Boxy.alert('Une erreur est survenue. Veuillez réessayer à nouveau.<br>Si le problème persiste veuillez contacter l\'administrateur du système.', null, {title: 'Information'}); }
	 });
}

// Visionner une video
function VisionnerVideo(id_video)
{
	// Execution du formulaire
	$.ajax({
	  type: "POST",
	  url: "./p_videos.php",		  
	  data: '&FormAction=VisionnerVideo&id_video='+id_video,
	  dataType : 'html',
	  cache: false,
	  async: true,
	  success: function(data) {	$.fancybox(data, {overflow:'hidden'}); return(false); },      
	  error: function() { Boxy.alert('Une erreur est survenue. Veuillez réessayer à nouveau.<br>Si le problème persiste veuillez contacter l\'administrateur du système.', null, {title: 'Information'}); }
	 });
}

function InitialiserFormLoggerUtilisateur() {					
	$('#LoggerUtilisateur_Err').slideUp('fast');
	/* $('#LoggerUtilisateurIdentifiant').val('Identifiant');
	$('#LoggerUtilisateurMDP').val('motdepasse'); */
}

function LoggerUtilisateur(gotoURL) {			
	
	// Formatage les données
	var dataString = $("form#FormLoggerUtilisateur").serialize();		
	dataString += "&FormAction=LoggerUtilisateur";
	if (gotoURL != "") dataString += "&gotoURL="+gotoURL+"&";	

	// Execution du formulaire
	$.ajax({
	  type: "POST",
	  url: "./op_connexion.php",
	  beforeSend: function() { $('#FormLoggerUtilisateurForm').hide(0, function () { $('#FormLoggerUtilisateurLoad').show(); } );  },
	  data: dataString,
	  dataType : 'html',
	  cache: false,
	  async: true,
	  success: function(data) {  eval(data); return(false); },      
	  error: function() { Boxy.alert('Une erreur est survenue. Veuillez réessayer à nouveau.<br>Si le problème persiste veuillez contacter l\'administrateur du système.', null, {title: 'Information'}); }
	 });
 
	return false;
}

function InitialiserFormMDPUtilisateur() {					
	$('#MDPUtilisateur_Err').slideUp('fast');
	$('#MDPUtilisateurEmail').val('Adresse e-mail');
}

function MDPUtilisateur() {			
	// Formatage les données
	var dataString = $("form#FormMDPUtilisateur").serialize();		
	dataString += "&FormAction=MDPUtilisateur";		
		
	// Execution du formulaire
	$.ajax({
	  type: "POST",
	  url: "./op_connexion.php",
	  beforeSend: function() { $('#FormMDPUtilisateurForm').hide(0, function () { $('#FormMDPUtilisateurLoad').show(); } );  },
	  data: dataString,
	  dataType : 'html',
	  cache: false,
	  async: true,
	  success: function(data) { $('#FormMDPUtilisateurLoad').hide(0, function () { $('#FormMDPUtilisateurForm').show(); } ); eval(data); return(false); },      
	  error: function() { Boxy.alert('Une erreur est survenue. Veuillez réessayer à nouveau.<br>Si le problème persiste veuillez contacter l\'administrateur du système.', null, {title: 'Information'}); }
	 });
 
	return false;
}


function Deconnexion(gotoURL)
{
	var dataString = "FormAction=Deconnexion&";		
	if (gotoURL != "") dataString += "gotoURL="+gotoURL+"&";
		
	// Execution du formulaire
	$.ajax({
		type: "POST",
		url: "./op_deconnexion.php",
		data: dataString,
		dataType : 'html',
		cache: false,
		async: true,
		success: function(data) { eval(data); return(false); }/* ,
		error: function() { Boxy.alert('Une erreur est survenue. Veuillez réessayer à nouveau.<br>Si le problème persiste veuillez contacter l\'administrateur du système.', null, {title: 'Information'}); }
	 */});
	
	return false;
}

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

