$(document).ready(function() {
	$('a.zoom').fancybox({
		'titlePosition'  : 'over',
		'swf': {wmode: 'transparent'}
	});	
	
	$("#cal").fancybox({
		'width': 630,
		'height': 360,
		'autoDimensions': false,
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'swf': {wmode: 'transparent'},
		'onComplete' : function(){
			$('iframe').each(function(){
				var url = $(this).attr("src");
				$(this).attr("src",url+"?wmode=transparent")
			});	
		}
	});
});

(function($){			
	// Affichage des jours
	setDays = function(day, month, year) {
		
		var result = [true, '', ''];	// Par défaut on affiche 
		
		if ((month == 7) || (month== 8)) {		// Eté (juillet et aout)
			result = [true, "", "Parc ouvert"];
		} else {								// Hors saison
			result = [true, "", "Hors saison"]
		}
		
		// Gestion des dates spécifiques saisies dans le calendrier
		var calendrier = $('input[name=dates]').val().split('|');
		for(i=0; i < calendrier.length-1; i++) {
			date = calendrier[i].split("$#");
			if(parseFloat(day) == parseFloat(date[0]) && (parseFloat(month) == parseFloat(date[1]-1)) && parseFloat(year) == parseFloat(date[2])) {
				ferme = '';
				
				/*
				if(date[3] == '200' && date[4] == '200') ferme = 'ampm';
				if(date[3] == '100' && date[4] == '200') ferme = 'pm';
				if(date[3] == '200' && date[4] == '100') ferme = 'am';
				*/
				
				if(date[3] == '100' && date[4] == '200') ferme = 'of'; // ouvert / ferme
				if(date[3] == '100' && date[4] == '300') ferme = 'os'; // ouvert / sur resa
				if(date[3] == '100' && date[4] == '400') ferme = 'or'; // ouvert / avec resa
				
				if(date[3] == '200' && date[4] == '100') ferme = 'fo'; // ferme / ouvert
				if(date[3] == '200' && date[4] == '200') ferme = 'ff'; // ferme / ferme
				if(date[3] == '200' && date[4] == '300') ferme = 'fs'; // ferme / sur resa
				if(date[3] == '200' && date[4] == '400') ferme = 'fr'; // ferme / avec resa
				
				if(date[3] == '300' && date[4] == '100') ferme = 'so'; // sur resa / ouvert
				if(date[3] == '300' && date[4] == '200') ferme = 'sf'; // sur resa / ferme
				if(date[3] == '300' && date[4] == '300') ferme = 'ss'; // sur resa / sur resa
				if(date[3] == '300' && date[4] == '400') ferme = 'sr'; // sur resa / avec resa
				
				if(date[3] == '400' && date[4] == '100') ferme = 'ro'; // avec resa / ouvert
				if(date[3] == '400' && date[4] == '200') ferme = 'rf'; // avec resa / ferme
				if(date[3] == '400' && date[4] == '300') ferme = 'rs'; // avec resa / sur resa
				if(date[3] == '400' && date[4] == '400') ferme = 'rr'; // avec resa / avec resa
				
				result = [true,ferme,date[5]];
			}
		}
									
		return result;
	}
	
	// Sélection d'une journée
	selectedDay = function(day, month, year) {	
		d = '<strong>'+day+'/'+month+'/'+year+' :</strong>';
		if ((month == 7) || (month == 8)) {		// Eté (juillet et aout)
			$("#calendrier p.retour").empty().append(d+"<br />Ouverture 9h-13h et 14h-18h");
		} else {								// Hors saison
			$("#calendrier p.retour").empty().append(d+"<br />Hors saison : ouverture à partir de 6 personnes sur réservation au 06 84 48 26 17");
		}
		
		// Gestion du spécifique
		var calendrier = $('input[name=dates]').val().split('|');
		for(i=0; i < calendrier.length-1; i++) {
			date = calendrier[i].split("$#");
			if(parseFloat(day) == parseFloat(date[0]) && parseFloat(month) == parseFloat(date[1]) && parseFloat(year) == parseFloat(date[2])) {
				$("#calendrier p.retour").empty().append(d+"<br />"+date[5]);
			}
		}
			
		//$("#datepicker").mouseover();
	}
			
	$(function(){
		
		$("#calendrier div").datepicker({
			numberOfMonths: 1,
			stepMonths: 1,
			showButtonPanel: false,
			nextText: "Suivant",
			prevText: "Précédent",
			firstDay: 1,
			dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
			monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
			minDate: new Date(), //du 1 juillet 2009
//			maxDate: new Date(2011,12-1,31), //au 31 décembre 2009
			dateFormat: "dd/mm/yy",
			beforeShowDay: function(date) {
				return setDays(date.getDate(), date.getMonth(), date.getFullYear());
			},
			onSelect: function(dateText) {
				//le format de dateText est donné par l'option dateFormat
				//transforme la date donnée au format texte (08082009) en day (8), month (7), year (2009)
				selectedDay(
					parseInt(dateText.slice(0,2),10),
					parseInt(dateText.slice(3,5),10),
					parseInt(dateText.slice(6),10)
				);
			}
		});
	});	//fin document ready
	
	$(window).load(function(){
		$("#calendrier div").bind("mouseover", function(){
//			if ($("td.important > a", this).eq(0).css("color") != "#FF0000") {
				/*
				$("td.am > a", this).css("background-image", "url(img/ui/am.png)");
				$("td.pm > a", this).css("background-image", "url(img/ui/pm.png)");
				$("td.ampm > a", this).css("background-image", "url(img/ui/ampm.png)");
				*/
				
				$("td.of > a", this).css("background-image", "url(img/ui/of.png)");
				$("td.os > a", this).css("background-image", "url(img/ui/os.png)");
				$("td.or > a", this).css("background-image", "url(img/ui/or.png)");
				
				$("td.fo > a", this).css("background-image", "url(img/ui/fo.png)");
				$("td.ff > a", this).css("background-image", "url(img/ui/ff.png)");
				$("td.fs > a", this).css("background-image", "url(img/ui/fs.png)");
				$("td.fr > a", this).css("background-image", "url(img/ui/fr.png)");
				
				$("td.so > a", this).css("background-image", "url(img/ui/so.png)");
				$("td.sf > a", this).css("background-image", "url(img/ui/sf.png)");
				$("td.ss > a", this).css("background-image", "url(img/ui/ss.png)");
				$("td.sr > a", this).css("background-image", "url(img/ui/sr.png)");
				
				$("td.ro > a", this).css("background-image", "url(img/ui/ro.png)");
				$("td.rf > a", this).css("background-image", "url(img/ui/rf.png)");
				$("td.rs > a", this).css("background-image", "url(img/ui/rs.png)");
				$("td.rr > a", this).css("background-image", "url(img/ui/rr.png)");
//			}
		});
		
		$("#calendrier div").mouseover();
	});	//fin window ready
})(jQuery);
