$(document).ready(function(){
	//$("a[rel='fancy']").fancybox();
	$("a.external-link").click(function(event){
		event.preventDefault();
		window.open($(this).attr("href"));
	});
	
	$("div.offres ul li")
	.mouseover(function()
	{
		$(this).stop();
		$(this).animate({backgroundColor: "#f27510", color: "#000000"},350);
		$(this).find("a").stop();
		$(this).find("a").animate({color: "#000000"},350);
	})
	.mouseout(function()
	{
		$(this).stop();
		$(this).animate({backgroundColor: "#050505", color: "#ffffff"},350);
		$(this).find("a").stop();
		$(this).find("a").animate({color: "#ffffff"},350);
	});
	
	$("a.activitySelector").click(function(event)
	{
		event.preventDefault();
		var $el = $(this).parent().find("ul");
		if(!$el.is(":animated"))
			$el.slideToggle();
	});
	
	
	$("form#newsletter-suscribe input[name='FIELD_email']").one("click",function(event)
	{
		$(this)
		$(this).val("");
	});
	
	/**
	 * Form projets
	 */
	
	$("div.select").not("div#chooseHotel").click(function()
	{
		var $ul = $(this).find("ul");
		$("div.select ul:visible").slideUp({
			duration: 200,
			easing: "easeOutCirc"
		});
		if(!$ul.is(":visible"))
		{
			$ul.slideDown({
				duration: 800,
				easing: "easeOutCirc"
			});
		}
	});
	
	$("div#choosePays ul li").click(function()
	{
		$("div#choosePays").find("span").text($(this).text());
		$("input[name='FIELD_pays']").val($(this).text());
		$("div#chooseHotel").find("span").text('--');
		fillHotelListFromCountry($(this).text());
	});

	$("div#chooseHotel").click(function(e)
	{
		if($(this).find("ul.selected").is(":visible"))
		{
			$("ul.selected", this).slideUp();
		}
		else
		{
			fillHotelListFromCountry($("div#choosePays").find("span").text());
			$("ul.selected", this).slideDown();		
		}
		e.stopPropagation();
	});
	
	$("div#chooseHotel ul li").click(function(e)
	{
		$("div#chooseHotel").find("span").text($(this).text());
		$("input[name='FIELD_hotel']").val($(this).text());
		$("div#chooseHotel ul.selected").slideUp();
		e.stopPropagation();
	});
	
	$("div#choosePays ul li, div#chooseHotel ul li")
	.live("mouseover",function()
	{
		$(this).stop();
		$(this).animate({backgroundColor: "#666", color: "#dadada"},350);
	})
	.live("mouseout",function()
	{
		$(this).stop();
		$(this).animate({backgroundColor: "#fff", color: "#666"},350);
	});
	
	/**
	 * Newsletter
	 */
	$("form#newsletter-suscribe").submit(function(event)
	{
		event.preventDefault();
		var $this = $(this);
		var email = $("input[name='FIELD_email']", $this).val();
		var emailValid = $this.find("input[name='newsletter-validate']").val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var iInterval;
		if(email != "" && email != emailValid && emailReg.test(email))
		{
			$this.find("input[type='submit']").attr("disabled","disabled");
			$.post("scripts/xhrdata/newsletter-suscribe.php",$this.serialize(),
			function(data)
			{
				$this.find("input[type='submit']").removeAttr("disabled");
				$this.fadeOut(function()
				{
					$this.parent().find("#success").fadeIn();
					setTimeout(function()
					{
						$this.parent().find("#success").fadeOut(function()
						{
							$this.fadeIn();
						});
					},5000); 
					
				});
			});
			
		}
		else
		{
			$("input[name='FIELD_email']", $this)
			.css("color","#ff0000")
			.val(emailValid);
			
			$("form#newsletter-suscribe input[name='FIELD_email']").one("click",function(event)
			{
				$(this).removeAttr("style");
				$(this).val("");
			});
			
		}
	});
	
	/** Push Charte Qualite **/
	$("div.push-charte-qualite")
	.mouseover(function(){
		$(this).css('cursor', 'pointer');
	})
	.click(function(e){
		document.location.href='engagement-qualite.html';
	});
	/** Push Témoignages **/
	$("div.push-clients")
	.mouseover(function(){
		$(this).css('cursor', 'pointer');
	})
	.click(function(e){
		document.location.href='nos-clients-temoignent.html';
	});
	
	/** Nos tarifs comprennent **/
	$("a.show_jHidden").click(function(e){
		e.preventDefault();
		$this = $(this);
		var Ul = $(this).parent().parent().find('ul');
		if(Ul.is(':hidden'))
		{
			Ul.slideDown();
			$this.text('refermer...');
		}
		else
		{
			Ul.slideUp();
			$this.text('voir plus...');
		}
		
	})
	

});

//Z-index bug fix for crappy ie 7 :-(
$(function() {
	if($.browser.msie && parseInt($.browser.version) == 7)
	{
		var zIndexNumber = 1000;
		$('div').each(function() {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		});
	}
});

function fillHotelListFromCountry(textVal)
{
	var listItem = $("div#choosePays ul li").filter(function(index)
	{
		return ($(this).text() == textVal);
	});
	var iIndex = $("div#choosePays ul li").index(listItem);
	$("div#chooseHotel ul").removeAttr("class","selected").eq(iIndex).attr("class","selected");
}

