// wait until document is fully scriptable
$(document).ready(function() {
	
	/*$(".houseitemlink").mouseenter(function() {
		$("#" + $(this)[0].id + "price").animate({
		    bottom: '+=30',
		  }, 0500, function() {
  		});
  		$("#" + $(this)[0].id + "title").animate({
		    top: '+=30',
		  	}, 0500, function() {
  			});
	});
	
	$(".houseitemlink").mouseout(function() {
			$("#" + $(this)[0].id + "price").animate({
		    bottom: '-=30',
		  }, 0500, function() {
  		});
  		$("#" + $(this)[0].id + "title").animate({
		    top: '-=30',
		  	}, 0500, function() {
  			});
	}); */
        $('.searchform-input-wrapper select option[value="page d\'accueil"]').css('display','none')
	   
	$(".bigButton a#details").click(function() {
			if ($("#singledetail").is(":hidden")) {
                                doHide($("#sendToFriendForm"));
                                doHide($("#moreInfosForm"));
                                doShow($("#singledetail"))
	
			} else	{
				doHide($("#singledetail"));
			}
                        return false;
	});
        $(".bigButton a#sendToFriend").click(function() {
			if ($("#sendToFriendForm").is(":hidden")) {
                                doHide($("#singledetail"));
                                doHide($("#moreInfosForm"));
                                
                                doShow($("#sendToFriendForm"))
	
			} else	{
				doHide($("#sendToFriendForm"));
			}
                        return false;
	});
        $(".bigButton a#moreInfos").click(function() {
			if ($("#moreInfosForm").is(":hidden")) {
                                doHide($("#sendToFriendForm"));
                                doHide($("#singledetail"));
                                doShow($("#moreInfosForm"))
	
			} else	{
				doHide($("#moreInfosForm"));
			}
                        return false;
	});
        
        
	
	$("a.calculbtn").click(function() {
		
		$.scrollTo( '#singlecalculate', 800 );
		
	});
	
	$("a#m_search").click(function() {
			
			if ($("#pagessearch").is(":hidden")) {
				$("#pagessearch").slideDown();
			} else	{
				$("#pagessearch").slideUp();
			}
	});
	
	$("a.localbutton").click(function() {
			
			if ($("#localiser").is(":hidden")) {
				$("#localiser").slideDown(),
				$.scrollTo( '#localiser', 800 );
				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(){
            doCalc();
	});
	
					   

	// 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]
	});*/
        doCalc();
        
	$("#mortgageCalc").trigger('click');
});
function doShow(div){
    if (div.is(":hidden")) {
        div.queue(function () {
            $(this).slideDown();
            $(this).dequeue();
        });
    }
}
function doHide(div){
    if (div.is(":hidden")){}else{
        div.slideUp();
    }
}
function doCalc(){
            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;
}

