var G_fichier_action = "actions.php";

$(function()
{
	var browser = 		jQuery.browser;
	var browserVer =	jQuery.browser.version;
	var browserOk=		true;
	
	if (browserVer.indexOf(".")>-1)
	{
		browserVer = browserVer.split(".");
		browserVer = browserVer[0];
	}

	if (browser.webkit && browserVer<530)
		browserOk = false;
	else
	if (browser.opera && browserVer<11)
		browserOk = false;
	else
	if (browser.msie && browserVer<9)
		browserOk = false;
	else
	if (browser.mozilla && browserVer<5)
		browserOk = false;
	
	if (!browserOk)
	{
		var p = "Votre navigateur est ancien, pensez à le mettre à jour.<br />";
		p+=			"lecarre.com est compatible avec les nouveaux browsers (<em>Firefox</em> 5.0, <em>Chrome</em> 12, <em>Opera</em> 11 et <em>IE</em> 9).";
		
		$("body").prepend("<div id='browser'>"+p+"</div>").delay(5500).queue(function(){$("#browser").slideUp()});
	}
	
	$("nav li")
	.mouseover(function()
	{
			var index =  $("nav li").index(this);
			
			if (index==0)
				color="#2E2E3E";
			else
			if (index==1)
				color="#E43381";
			else
			if (index==2)
				color="#C1D600";
			else
			if (index==3)
				color="#F46B0B";
			else
			if (index==4)
				color="#069EA1";
			else
				color="#666670";

		$("span", $(this)).css("background-color", color);
		
		$("a", $(this)).css("background-color", color);
	})
	.mouseout(function()
	{
		if (!$("span", $(this)).hasClass("actif"))
		{
			$("span", $(this)).css("background-color", "#666670");
			
			var index =  $("nav li").index(this);
			
			if (index==1)
				color="#E43381";
			else
			if (index==2)
				color="#C1D600";
			else
			if (index==3)
				color="#F46B0B";
			else
			if (index==4)
				color="#069EA1";
			else
				color="#666670";
				
			$("a", $(this)).css("background-color", color);
		}
	})

	$(".zPaves div a")
	.mouseover(function()
	{
		$("img:first", $(this).parent()).css("opacity", 0.4);
		
		$("img.play", $(this).parent()).css({
																					"width":"50px", "left":"110px",
																					"height":"50px", "top":"112px"
																				});
	})
	.mouseout(function()
	{
		$("img:first", $(this).parent()).css("opacity", 1);
		
		$("img.play", $(this).parent()).css({
																					"width":"76px", "left":"97px",
																					"height":"76px", "top":"100px"
																				});
	})

	if ($("#pgIndex").length==1)
	{
		$("a.lt").fancybox();

/*
	splashScreen
*/		
		var splash = 	"splash1";
		var nbVue =		1;
		var jours =		1;

		var cookieVar = splash;
		var cookieVal = $.cookie(cookieVar)-0;
		
		if (cookieVal<nbVue && $("#"+splash).length>0)
		{
			cookieVal++;
			
			$.cookie(cookieVar, cookieVal, {expires: jours});
			
			window.setTimeout(function()
			{
				$.fancybox({"href":"#"+splash})
			}, 500);
		}
	}
	else
	if ($("#pg-agenda").length==1)
	{
		$("a.lt").fancybox();
	}
	else
	if ($("#pg-lecarre").length==1)
	{
		function initialize()
		{
			var myLatLng = new google.maps.LatLng(50.641337, 5.569049);
			var myOptions =
			{
				zoom: 18,
				center: myLatLng,
				mapTypeId: google.maps.MapTypeId.HYBRID
			};
			
			var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
			var image = new google.maps.MarkerImage('_images/biere.png');

			var Etablissements = [
					['L\'A-fond liégeois', 0, 0], 
					['La Fiesta', 0, 0],
					['L\'Orange Givrée', 50.641385, 5.569469],
					['L\'Embuscade', 0, 0],
					['Le Pourquoi Pas', 50.641443, 5.569547],
					['L\'Escalier', 50.641637, 5.569245],
					['La Cour Saint-Jean', 50.641629, 5.569360],
					['L\'Aller Simple', 50.641575, 5.569307],
					['Le Déluge', 50.641359, 5.569028],
					['L\'Aquarelle', 50.641230, 5.569009],
					['L\'Aventure', 50.641264, 5.568805],
					['Chez Bouldou', 0, 0],
					['Plaza Catedral de Bouldou', 0, 0],
					['Le Soleil', 0, 0],
					['La Guimbarde', 50.641091, 5.569138],
					['Le Yellow Submarine', 50.640715, 5.569398],
					['Le Géographic Café', 50.641391, 5.569319],
					['L\'Imprévu', 50.640768, 5.569446],
					['Le Bara\'rhum', 50.641393, 5.569603],
					['L\'Aéropostale', 50.641679, 5.569186],
					['Le Mad Murphy', 50.641700, 5.569309],
					['Le Smile', 50.641416, 5.568625],
					['Les Trois Rivières', 50.641543, 5.569604],
					['Le Cuba\'r', 0, 0],
					['Le Saloon', 0, 0],
					['Le Tam-Tam', 0, 0],
					['Le Point de Vue', 50.641179, 5.568896],
					['Le Far-West', 0, 0],
					['L\'Exxit', 50.640647, 5.569441],
					['Le Bora-Bora', 0, 0],
					['Le Duplex', 0, 0],
					['La Mamma Roma', 50.641511, 5.568529],
					['Le Spartacus', 0, 0],
					['Pita Elmas', 50.641302, 5.568904],
					['Pita Calimero', 0, 0],
					['Le mystérix', 50.641046, 5.569183]				
			];
	
			for (i in Etablissements)
			{
				var marker = new google.maps.Marker({
						position: new google.maps.LatLng(Etablissements[i][1], Etablissements[i][2]),
						map: map,
						icon:image,
						title:Etablissements[i][0]
				});  
			}
			
			var flightPlanCoordinates = [
					new google.maps.LatLng(50.641690, 5.567071),
					new google.maps.LatLng(50.640233, 5.569034),
					new google.maps.LatLng(50.640902, 5.570790),
					new google.maps.LatLng(50.642498, 5.568919),
					new google.maps.LatLng(50.641690, 5.567071)
			];
			
			var flightPath = new google.maps.Polyline({
					path: flightPlanCoordinates,
					strokeColor: "#FF0000",
					strokeOpacity: 1.0,
					strokeWeight: 6
			});
 
			flightPath.setMap(map);
		}
		
		initialize();
	}
	else
	if ($("#pg-galeries-albums").length==1)
	{
		$("#pagination a").click(function()
		{
			$(".zPaves:hidden:eq(0), .zPaves:hidden:eq(1)").fadeIn("fast", function()
			{
				$("div", $(this)).slideDown("normal");
				
				if ($(".zPaves:hidden").length==0)
					$("#pagination").hide();
				
			});
			return false;
		})
		
		if ($(".zPaves:hidden").length==0)
			$("#pagination").hide();
	}
	else
	if ($("#pg-galeries-details").length==1)
	{
		$('a.lt').each(function()
		{
			$(this).attr('rel', 'litebox');
		}); 
																
		$(".lt").fancybox();

//retour avec l'image ds le lien
		var adr = 		window.location.href;
		var imgPos =	adr.indexOf("#");
		
		if (imgPos>-1)
		{
			var img = adr.substr(imgPos+1);
/*			
			window.setTimeout(function(){
				$("a[href$='"+img+"']").trigger("click");
			}, 500);
*/		}
	}
	else	
	if ($("#pg-annoncer").length==1)
	{
		$("form#frmPro").bind('submit', function()
		{
			return frmSubmit(this, G_fichier_action, "pro");
		})
		
		$("form#frmFree").bind('submit', function()
		{
			return frmSubmit(this, G_fichier_action, "free");
		})
		
		$("#wrapper p a").click(function(){
			
			$(this).parent().parent().next().fadeToggle("slow");
		
			return false;
		})
		
		$('#date2').datepicker({showButtonPanel: true});
		
		$("#lieu2").change(function(){
			
			if ($(this).val()==-1)
			{
				var lieu = prompt("Entrez un nouveau lieu ! ", "");
				
				if (lieu!=null)
				{
					$("#lieu2_autre").val(lieu);
				}
			}
		
			
			})
		
		emails();
		
		$(".target").attr("target", "_blank");
	}
	else
	if ($("#pg-contact").length==1)
	{
		emails();
	}
	
})
