$(document).ready(function()
{
	/**
	 * Gestion des valeurs xtclib dans les menus (xiti)
	 */
	$(".menu_item").each(function()
	{
		var id = $(this).attr("id");
		$(this).attr('xtclib,id');
	});
	/**
	 * déclaration et lancement du slider de home
	 */
	if (('undefined' != typeof asah_slider) && (asah_slider == true))
		$("#promo_home").accessNews(
		{
			speed : "normal",
			slideBy : 1
		});
	/**
	 * déclaration et lancement des datepickers
	 */
	if (('undefined' != typeof asah_datefrom_searchbox) && (asah_datefrom_searchbox == true))
		$("#dateFrom").datepicker(
		{
			minDate : 0,
			maxDate : '+12m +1w'
		});
	if (('undefined' != typeof asah_dateto_searchbox) && (asah_dateto_searchbox == true))
		$("#dateTo").datepicker(
		{
			minDate : 1,
			maxDate : '+12m +1w'
		});
	if (('undefined' != typeof asah_datefrom_advancedsearch) && (asah_datefrom_advancedsearch == true))
		$("#dateFrom").datepicker(
		{
			minDate : 0
		});
	if (('undefined' != typeof asah_dateto_advancedsearch) && (asah_dateto_advancedsearch == true))
		$("#dateTo").datepicker(
		{
			minDate : 0
		});
	if (('undefined' != typeof asah_datefrom_bookingform) && (asah_datefrom_bookingform == true))
		$("#dateFrom").datepicker(
		{
			minDate : 0,
			maxDate : '+12m +1w'
		});
	if (('undefined' != typeof asah_dateto_bookingform) && (asah_dateto_bookingform == true))
		$("#dateTo").datepicker(
		{
			minDate : 1,
			maxDate : '+12m +1w'
		});
	if (('undefined' != typeof asah_datefrom_bookingformpro) && (asah_datefrom_bookingformpro == true))
		$("#dateFrom").datepicker(
		{
			minDate : 0,
			maxDate : '+12m +1w'
		});
	if (('undefined' != typeof asah_dateto_bookingformpro) && (asah_dateto_bookingformpro == true))
		$("#dateTo").datepicker(
		{
			minDate : 1,
			maxDate : '+12m +1w'
		});
	/**
	 * ewego dans les pages residences
	 */
	if ($("#ewego").length)
	{
		$("#ewego").attr('src', '/extension/ash_design/design/ash/images/content/bouton_ewego_v2.jpg');
		$("#ewego").css('cursor', 'pointer');
		$("#ewego").after('<br/><a target="_blank" style="margin:3px 0 0 38px; text-decoration: none; color:#AAAAAA; font-size: 9px;" rel="nofollow" href="http://www.e-wego.com">Service fourni par E-WEGO</a>');
		$("#ewego").hover(function()
		{
			$(this).attr('src', '/extension/ash_design/design/ash/images/content/bouton_ewego_v2_hover.jpg')
		}, function()
		{
			$(this).attr('src', '/extension/ash_design/design/ash/images/content/bouton_ewego_v2.jpg')
		});
		$("#ewego").click(function()
		{
			window.open('http://www.e-wegopro.fr/all-suites-home/popup', "popup_ewego", "width=685,height=700,menubar=yes,toolbar=no,location=yes,status=no,resizable=no,scrollbars=no,directories=no");
		});
	}
	/**
	 * ewego dans les infobox
	 */
	if ($("#ewego2").length)
	{
		$("#ewego_service").parent().css('text-align', 'center');
		$("#ewego_service").attr('href', 'http://www.e-wego.com');
		$("#ewego_service").attr('rel', 'nofollow');
		$("#ewego_service").attr('target', '_blank');
		$("#ewego_service").css('text-decoration', 'none');
		$("#ewego_service").css('color', '#AAAAAA');
		$("#ewego_service").css('font-size', '9px');
		$("#ewego2").attr('src', '/extension/ash_design/design/ash/images/content/bouton_ewego_v2.jpg');
		$("#ewego2").css('cursor', 'pointer');
		$("#ewego2").hover(function()
		{
			$(this).attr('src', '/extension/ash_design/design/ash/images/content/bouton_ewego_v2_hover.jpg')
		}, function()
		{
			$(this).attr('src', '/extension/ash_design/design/ash/images/content/bouton_ewego_v2.jpg')
		});
		$("#ewego2").click(function()
		{
			window.open('http://www.e-wegopro.fr/all-suites-home/popup', "popup_ewego", "width=685,height=700,menubar=yes,toolbar=no,location=yes,status=no,resizable=no,scrollbars=no,directories=no");
		});
	}
});
/**
 * Gestion WCB
 * @return
 */
function checkCallBack()
{
	var url = $("#embed_callback_form").attr('action');
	var data = $("#embed_callback_form").serialize();
	var result = checkformField($("#embed_callback_form").attr('id'), $("#embed_callback_form").find('input.telephone').attr('id'), false);
	if (result)
	{
		/**
		 * on soumet le formulaire
		 */
		$.post(url, data);
		/**
		 * on modifie l'apparence du wcb
		 */
		$("#embed_callback_form").find('input.telephone').remove();
		$("#embed_callback_form").find('img.submitWCBInformation').remove();
		$("#img_rappel").attr('src', '/extension/ash_design/design/ash/images/wcb/asah_merci.jpg').after('<p id="merci">Un conseiller va vous rappeler rapidement.</p>');
	}
	return false;
}
if (document.body.className.match(/residence/) || document.body.className.match(/suite/))
{
	/**
	 * Classe de gestion du slider JS
	 * @param $_imgsContainerDomId
	 * @param $_name
	 * @return
	 */
	function homeSlideResidence($_imgsContainerDomId, $_name)
	{
		/**
		 * Nom de la variable JS pour les rappels
		 * @var string
		 */
		this.name = $_name;
		/**
		 * Slides
		 * @var Array
		 */
		this.slides = new Array();
		/**
		 * Index du slide en cours
		 * @var int
		 */
		this.index = -1;
		/**
		 * Index du contrôle de slide en cours
		 * @var int
		 */
		this.ctrlIndex = -1;
		/**
		 * Indique qu'il faut continuer ou non
		 * @var bool
		 */
		this.run = false;
		/**
		 * Contient l'objet de timer
		 * @var bool
		 */
		this.timer = false;
		/**
		 * Méthode pour passer au slide suivant
		 * @return void
		 */
		this.nextSlide = function nextSlide()
		{
			if (this.index >= 0)
			{
				/**
				 * On masque le slide en cours
				 */
				$(this.slides[this.index]).fadeOut('slow', function()
				{
					$(this).css('display', 'none');
				});
				/**
				 * On détermine l'index du slide suivant
				 */
				if (this.index == this.slides.length - 1)
					this.index = 0;
				else
					this.index = this.index + 1;
				/**
				 * On affiche le slide suivant
				 */
				$(this.slides[this.index]).fadeIn('slow', function()
				{
					$(this).css('display', '');
				});
				/**
				 * Auto
				 */
				if (this.run)
					this.start();
			}
		};
		/**
		 * Fonction pour passer au précédent
		 * @return void
		 */
		this.prevSlide = function prevSlide()
		{
			if (this.index >= 0)
			{
				/**
				 * On masque le slide en cours
				 */
				$(this.slides[this.index]).fadeOut('slow', function()
				{
					$(this).css('display', 'none');
				});
				/**
				 * On détermine l'inde du slide suivant
				 */
				if (this.index == 0)
					this.index = this.slides.length - 1;
				else
					this.index = this.index - 1;
				/**
				 * On affiche le slide suivant
				 */
				$(this.slides[this.index]).fadeIn('slow', function()
				{
					$(this).css('display', '');
				});
				/**
				 * Auto
				 */
				if (this.run)
					this.start();
			}
		};
		/**
		 * Fonction pour stopper
		 * @return void
		 */
		this.stop = function stop()
		{
			clearTimeout(this.timer);
			return (this.run = false);
		};
		/**
		 * Fonction pour démarrer
		 * @return void
		 */
		this.start = function start()
		{
			if (this.run)
				this.timer = setTimeout(this.name + '.auto()', 5000);
		};
		/**
		 * Fonction appelée automaquement
		 * @return voir
		 */
		this.auto = function auto()
		{
			if (this.run)
				this.nextSlide();
		};
		/**
		 * Défilements des images vers le haut pour afficher celles d'en bas
		 */
		this.ctrlDn = function ctrlDn()
		{
			if (this.ctrlIndex >= 0)
			{
				var ctrls = $('#slides-ctrl li');
				/**
				 * On monte de la hauteur et de la marge entre images
				 */
				var marginTop = (ctrls.first().height() + 3) * -1;
				if (this.ctrlIndex < ctrls.length)
				{
					$(ctrls[this.ctrlIndex]).animate(
					{
						'margin-top' : marginTop + 'px'
					});
					$('#slider-ctrl-up').removeClass('disabled');
					this.ctrlIndex++;
					/**
					 * On doit toujours avoir 3 vignettes affichées
					 */
					if (this.ctrlIndex == ctrls.length - 3)
						$('#slider-ctrl-down').addClass('disabled');
				}
				else
					$('#slider-ctrl-down').addClass('disabled');
			}
		};
		/**
		 * Défilements des images vers le bas pour afficher celles d'en haut
		 */
		this.ctrlUp = function ctrlUp()
		{
			if (this.ctrlIndex >= 0)
			{
				var ctrls = $('#slides-ctrl li');
				/**
				 * On descend de la hauteur et de la marge entre images
				 */
				var marginTop = 0;
				if (this.ctrlIndex < ctrls.length)
				{
					this.ctrlIndex--;
					$(ctrls[this.ctrlIndex]).animate(
					{
						'margin-top' : marginTop + 'px'
					});
					$('#slider-ctrl-down').removeClass('disabled');
					if (this.ctrlIndex == 0)
						$('#slider-ctrl-up').addClass('disabled');
				}
				else
					$('#slider-ctrl-up').addClass('disabled');
			}
		};
		/**
		 * Affichage de la vignette associée
		 */
		this.clickCtrl = function clickCtrl($_link)
		{
			if ($_link.id)
			{
				$('#slides-img li').css('display', 'none');
				$('#slides-img li#img-li-' + $_link.id.replace(/ctrl-a-/, '')).css('display', '');
				$('#slides-ctrl li').removeClass('selected');
				$('#slides-ctrl li#li-a-' + $_link.id.replace(/ctrl-a-/, '')).addClass('selected');
			}
		};
		/**
		 * Fonction d'initialisation
		 * @param $_imgsContainerDomId string l'id contenant la liste ul>li>a>img du slide
		 * @return
		 */
		this.init = function init($_imgsContainerDomId)
		{
			if (document.getElementById($_imgsContainerDomId))
			{
				var imgs = document.getElementById($_imgsContainerDomId).getElementsByTagName('li');
				var nbImgs = imgs.length;
				/**
				 * Si plus d'un élément
				 */
				if (nbImgs > 1)
				{
					var me = this;
					/**
					 * Enregistrement des éléments du slider
					 */
					for ( var i = 0; i < nbImgs; i++)
						this.slides.push(imgs.item(i));
					this.index = 0;
					//this.run = true;
					//this.start();
				}
				/**
				 * Contrôles
				 */
				var me = this;
				$('#slider-ctrl-up').click(function()
				{
					me.ctrlUp();
					return false;
				});
				$('#slider-ctrl-down').click(function()
				{
					me.ctrlDn();
					return false;
				});
				$('#slides-ctrl li a').click(function()
				{
					me.clickCtrl(this);
					return false;
				});
				this.ctrlIndex = 0;
			}
		};
		this.init($_imgsContainerDomId);
		/**
		 * Fix IE7 empêchant le footer de remonter lors du changement d'image du slider
		 */
		if ($.browser && $.browser.msie === true && $.browser.version <= 7)
			$('#layout').css('height', $('#layout').height() + 'px');
	}
	/**
	 * Création du slide
	 */
	if (document.getElementById('flashblock') || document.getElementById('resid_flashblock'))
		var home_slider = new homeSlideResidence('slides-img', 'home_slider');
}
else
{
	/**
	 * Classe de gestion du slider JS
	 * @param $_imgsContainerDomId
	 * @param $_name
	 * @return
	 */
	function homeSlide($_imgsContainerDomId, $_name)
	{
		/**
		 * Nom de la variable JS pour les rappels
		 * @var string
		 */
		this.name = $_name;
		/**
		 * Slides
		 * @var Array
		 */
		this.slides = new Array();
		/**
		 * Index du slide en cours
		 * @var int
		 */
		this.index = -1;
		/**
		 * Indique qu'il faut continuer ou non
		 * @var bool
		 */
		this.run = false;
		/**
		 * Contient l'objet de timer
		 * @var bool
		 */
		this.timer = false;
		/**
		 * Méthode pour passer au slide suivant
		 * @return void
		 */
		this.nextSlide = function nextSlide()
		{
			if (this.index >= 0)
			{
				/**
				 * On masque le slide en cours
				 */
				$(this.slides[this.index]).fadeOut('slow', function()
				{
					$(this).css('display', 'none');
				});
				/**
				 * On détermine l'inde du slide suivant
				 */
				if (this.index == this.slides.length - 1)
					this.index = 0;
				else
					this.index = this.index + 1;
				/**
				 * On affiche le slide suivant
				 */
				$(this.slides[this.index]).fadeIn('slow', function()
				{
					$(this).css('display', '');
				});
				/**
				 * Auto
				 */
				if (this.run)
					this.start();
			}
		};
		/**
		 * Fonction pour passer au précédent
		 * @return void
		 */
		this.prevSlide = function prevSlide()
		{
			if (this.index >= 0)
			{
				/**
				 * On masque le slide en cours
				 */
				$(this.slides[this.index]).fadeOut('slow', function()
				{
					$(this).css('display', 'none');
				});
				/**
				 * On détermine l'inde du slide suivant
				 */
				if (this.index == 0)
					this.index = this.slides.length - 1;
				else
					this.index = this.index - 1;
				/**
				 * On affiche le slide suivant
				 */
				$(this.slides[this.index]).fadeIn('slow', function()
				{
					$(this).css('display', '');
				});
				/**
				 * Auto
				 */
				if (this.run)
					this.start();
			}
		};
		/**
		 * Fonction pour stopper
		 * @return void
		 */
		this.stop = function stop()
		{
			clearTimeout(this.timer);
			return (this.run = false);
		};
		/**
		 * Fonction pour démarrer
		 * @return void
		 */
		this.start = function start()
		{
			if (this.run)
				this.timer = setTimeout(this.name + '.auto()', 5000);
		};
		/**
		 * Fonction appelée automaquement
		 * @return voir
		 */
		this.auto = function auto()
		{
			if (this.run)
				this.nextSlide();
		};
		/**
		 * Fonction d'initialisation
		 * @param $_imgsContainerDomId string l'id contenant la liste ul>li>a>img du slide
		 * @return
		 */
		this.init = function init($_imgsContainerDomId)
		{
			if (document.getElementById($_imgsContainerDomId))
			{
				var imgs = document.getElementById($_imgsContainerDomId).getElementsByTagName('li');
				var nbImgs = imgs.length;
				/**
				 * Si plus d'un élément
				 */
				if (nbImgs > 1)
				{
					var me = this;
					/**
					 * Enregistrement des éléments du slider
					 */
					for ( var i = 0; i < nbImgs; i++)
						this.slides.push(imgs.item(i));
					this.index = 0;
					this.run = true;
					this.start();
				}
			}
		};
		this.init($_imgsContainerDomId);
		/**
		 * Fix IE7 empêchant le footer de remonter lors du changement d'image du slider
		 */
		if ($.browser && $.browser.msie === true && $.browser.version <= 7)
			$('#layout').css('height', $('#layout').height() + 'px');
	}
	/**
	 * Création du slide
	 */
	if (document.getElementById('flashblock') || document.getElementById('resid_flashblock'))
		var home_slider = new homeSlide(document.getElementById('resid_flashblock') ? 'resid_flashblock' : 'flashblock', 'home_slider');
}
