var G_fichier_action="actions.php";

/*
function openPayements(txt)
{
	window.open("panier,"+txt, "popPay");
}
*/

$(function()
{
	if ($("#pageHome").length==1)
	{
		
	}
	else
	if ($("#pagePhotos").length==1)
	{
		var referenceLink = $('#selectionPhotos+ul a');
		referenceLink.mouseover(function(){$(this).stop(true, true).fadeTo('fast', 0.85);}).mouseout(function(){$(this).stop(true, true).fadeTo('fast', 1);});
		
		$("#album").change(function(){
			
			document.location.href="photos,"+$(this).val()+",1,0";
		})
	}
	else
	if ($("#pageContact").length==1)
	{
		$('form#emContact p:eq(1)').hide();
		
		inputFocusBlur($("#nom2, #pre2, #ema2, #tel2, #pays2, #titre2, #com"));
		
		$("form#emContact").bind('submit', function()
		{
			return frmSubmit(this, G_fichier_action, "contact");
		})
		
		emails();
	}
	else
	if ($("#pageDetails.commande").length==1)
	{//commande
		$('form#emCommande p:eq(1)').hide();
		
		inputFocusBlur($("#nom2, #pre2, #ema2, #tel2, #pays2, #com"));

		$("form#emCommande").bind('submit', function()
		{
			if ($("#optContact").val()==1)
			{
				var datas = {
					
					action:			"commande2",
					voy:				$("#voy").val(),
					tab:				$("#tab").val(),
					
					optContact:	$("#optContact").val(),
					
					nom2:				jQuery.trim($('#nom2').val()),
					pre2:				jQuery.trim($('#pre2').val()),
					ema2:				jQuery.trim($('#ema2').val()),
					tel2:				jQuery.trim($('#tel2').val()),
					pay2:				jQuery.trim($('#pays2').val())
				};
				
				ajaxSyncr2(G_fichier_action, datas);
				
				return false
			}
			
			return frmSubmit(this, G_fichier_action, "commande2");
		})
	}
/*
	else
	if ($("#pageDetails.commande").length==1)
	{
		$('form#emCommande p:eq(1)').hide();
		
		inputFocusBlur($("#nom2, #pre2, #ema2, #tel2, #pays2, #com"));

		$("form#emCommande").bind('submit', function()
		{
			return frmSubmit(this, G_fichier_action, "commande");
		})
	}
*/

/*
	if ($("#pageDetails, #pagePhotos.slide").length==1)
	{
		
		function onAfter(curr, next, opts)
		{
			var index = opts.currSlide;
	
			$('#prev')[index == 0 ? 'hide' : 'show']();
			$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
		}

		var zone= $("#pageDetails").length==1 ? "#imagesDetails" : "#mySlide";
		
    $("ul", zone).cycle({
			fx: 'fade',
			prev:"#imagesDetails a:eq(1), #mySlide a:eq(1)",
			next:"#imagesDetails a:eq(0), #mySlide a:eq(0)",
			after:onAfter,
			timeout:0
		});

	}
*/


	if ($("#pageDetails, #pagePhotos.slide").length==1)
	{
		var zone= $("#pageDetails").length==1 ? "#imagesDetails" : "#mySlide";
		
		var imagePos=0;
		
		var lesImages=	$("li", $(zone));
		var Timages= 		$(lesImages).length;
		
		$("a:eq(1)", $(zone)).click(function()
		{//Previous
			$("li:eq("+imagePos+")", $(zone)).hide();
			
			if (imagePos==0)
				imagePos=Timages-1;
			else
				imagePos--;
			
			$("li:eq("+imagePos+")", $(zone)).show();//fadeIn("slow");
			
			if (zone=="#mySlide")
			{
				var imgStart=$("#infoSlide span").text()-0;
				
				if (imgStart==1)
					num = Timages;
				else
					num =imgStart-1;
					
				$("#infoSlide span").text(num);
			}
			
			return false;
		})
		
		$("a:eq(0)", $(zone)).click(function()
		{//next
			$("li:eq("+imagePos+")", $(zone)).hide();
			
			if (imagePos==Timages-1)
				imagePos=0;
			else
				imagePos++;
			
			$("li:eq("+imagePos+")", $(zone)).show(); //fadeIn("slow");
			
			if (zone=="#mySlide")
			{
				var imgStart=$("#infoSlide span").text()-0;
				
				if (imgStart==Timages)
					num = 1;
				else
					num =imgStart+1;
					
				$("#infoSlide span").text(num);
			}
			
			return false;
		})
	}
	
	if ($("form#search").length==1)
	{//form=3 toutes les formules
		var params= "action=searchGo&form=3&dest=0&them=0&budg=0&mois=0";
		ajax_post(G_fichier_action, params);
		
		var selects =		$("form#search select");
		var newSearch	= $(".results a");
	
		newSearch.hide().click(function(){
			
			selects.val(0).change();
			$(this).hide();
			
			return false;
		})
	
		selects.change(function()
		{
			newSearch.fadeIn();
			
			var form=		$("#formules").val();
			var dest= 	$("#destinations").val();
			var them= 	$("#themes").val();
			var budg= 	$("#budgets").val();
			var mois= 	$("#dates").val();
			
			var params= "action=searchGo&form="+form+"&dest="+dest+"&them="+them+"&budg="+budg+"&mois="+mois;
			
			ajax_post(G_fichier_action, params);
		})
	}

	
	inputFocusBlur($("#email, #nom, #pays, #numero, #communication"));

	$("form#newsletter").bind('submit', function()
	{
		return frmSubmit(this, G_fichier_action, "newsletter");
	})
	
	$('a.target').attr('target', '_blank');
	
	$("a[href=mon-compte]").click(function()
	{
		return false;
	});


/*
	Footer
*/
	var frmFooter=$("form#frmFooter");
	
	$("#okey", frmFooter).hide();

	$(frmFooter).bind('submit', function()
	{
		return frmSubmit(this, G_fichier_action, "contact_footer");
	})
	
	$('#okey a').click(function(){
		
		$('fieldset p', frmFooter).show();
		$('#okey', frmFooter).hide();
		
		return false;	
	});
	
	$("#coordonnees > img:eq(1)").wrap("<a href='mailto:info@emotionplanet.com' />");

/*
	/Footer 
*/
	
})

