// wait until document is fully scriptable
$(document).ready(function() {
	
	//$("#localiser").slideUp();
						   
	$("a.voirdetail").click(function() {
			
			if ($("#singledetail").is(":hidden")) {
				$("#singledetail").slideDown();
				$("a.voirdetail").text("Masquer la fiche");
			} else	{
				$("#singledetail").slideUp();
				$("a.voirdetail").text("Voir la fiche");
			}
	});
	
	$("a#pagessearchbtn").click(function() {
			
			if ($("#pagessearch").is(":hidden")) {
				$("#pagessearch").slideDown();
			} else	{
				$("#pagessearch").slideUp();
			}
	});
	
	$("a#pagessearchbtnhome").click(function() {
			
			if ($("#pagessearchhome").is(":hidden")) {
				$("#pagessearchhome").slideDown();
			} else	{
				$("#pagessearchhome").slideUp();
			}
	});
	
	
	$("a#localbutton").click(function() {
			
			if ($("#localiser").is(":hidden")) {
				$("#localiser").slideDown(),
				initialize();
			} else	{
				$("#localiser").slideUp();
			}
	});
	
	$("img#gravelprix").mouseover(function() {
		$("#alainprix").fadeIn("slow");
	});
	
	$("img#gravelprix").mouseout(function() {
		$("#alainprix").fadeOut("slow");
	});
		
	//Calcul des paiements
	
	$("#mortgageCalc").click(function(){
	var L,P,n,c,dp;
	L = parseInt($("#mcPrice").val());
	n = parseInt($("#mcTerm").val()) * 12;
	c = parseFloat($("#mcRate").val())/1200;
	dp = parseInt($("#mcDown").val());
	L = L - dp;
	P = (L*(c*Math.pow(1+c,n)))/(Math.pow(1+c,n)-1);
	if(!isNaN(P))
	{
	$("#mcPayment").val(P.toFixed(2));
	}
	else
	{
	$("#mcPayment").val('Erreur');
	}
	return false;
	});
	
	/*$("#mortgageCalc").click(function(){
	var L,P,n,c,dp;
	L = parseInt($("#mcPrice").val());
	n = parseInt($("#mcTerm").val()) * 12;
	c = parseFloat($("#mcRate").val())/1200;
	dp = 1 - parseFloat($("#mcDown").val())/100;
	L = L * dp;
	P = (L*(c*Math.pow(1+c,n)))/(Math.pow(1+c,n)-1);
	if(!isNaN(P))
	{
	$("#mcPayment").val(P.toFixed(2));
	}
	else
	{
	$("#mcPayment").val('Erreur');
	}
	return false;
	});
	*/
	
	//Calcul de la taxe de bienvenue
	
	$("#bienCalc").click(function(){
	
	var montant = parseInt($("#bienPrix").val());
	var resultat = 0;
	
	var tranche3 = montant - 250000;
	if(tranche3>0) {
		resultat += (tranche3*1.5/100);
		montant -= tranche3;
		$("#bienTot").val(resultat);
	}
	
	var tranche2 = montant - 50000;
	if(tranche2>0) {
		resultat += (tranche2*1.0/100);
		montant -= tranche2;
		$("#bienTot").val(resultat);
	}
	
	var tranche1 = montant;
	if(tranche1>0) {
		resultat += (tranche1*0.5/100);
		montant -= tranche1;
		$("#bienTot").val(resultat);
	}
	else
	{
	$("#bienTot").val('Erreur');
	}
	return false;
	});
	
					   

	// select #flowplanes and make it scrollable. use circular and navigator plugins
	$("#flowpanes").scrollable({ 
							   
			circular: true, 
			keyboard: false, 
			mousewheel: false 
		
		}).autoscroll({
			
			autoplay:true,
			autopause: false,
			interval: 4000
		
		}).navigator({

			// select #flowtabs to be used as navigator
			navi: "#flowtabs",
	
			// select A tags inside the navigator to work as items (not direct children)
			naviItem: 'a',
	
			// assign "current" class name for the active A tag inside navigator
			activeClass: 'current',
	
			// make browser's back button work
			history: false,

		});
	
	$(".toolbar img[title]").tooltip
									
	({

		// use div.tooltip as our tooltip
		tip: '.tooltip',
		
		// use the fade effect instead of the default
		effect: 'fade',

		// make fadeOutSpeed similar to the browser's default
		fadeOutSpeed: 100,

		// tweak the position
		position: 'top center',
		
		offset:[10,0]
	});
	
	$("#localbtn[title]").tooltip
									
	({

		// use div.tooltip as our tooltip
		tip: '.tooltip',
		
		// use the fade effect instead of the default
		effect: 'fade',

		// make fadeOutSpeed similar to the browser's default
		fadeOutSpeed: 100,

		// tweak the position
		position: 'top center',
		
		offset:[10,0]
	});
	
	/*$("div#galeriesingle img[title]").tooltip
									
	({

		// use div.tooltip as our tooltip
		tip: '.tgallery',
		
		// use the fade effect instead of the default
		effect: 'fade',

		// make fadeOutSpeed similar to the browser's default
		fadeOutSpeed: 50,

		// tweak the position
		position: 'top center',
		
		offset:[40,0]
	});*/
	
	var hiddenSearch = $('div.hidden_search').text();
	
	//alert(hiddenSearch);
	
	$('input#h_searchfield').attr({ value: hiddenSearch }).focus(function(){
		if($(this).val()== hiddenSearch){
		   $(this).val("");
		   $(this).css("color","#FFF");
		}
   }).blur(function(){
		if($(this).val()==""){
		   $(this).val(hiddenSearch);
			$(this).css("color","#CCC");
		}
   });

	
});

