$(document).ready(function(){
	var widget = $("#hipotecaWidget .content").load("/hipotecaWidget.html", null , function(){
		$("#hipotecaWidget .btn , #hipotecaWidget .close").click(function(){ 
		widget.slideToggle("normal");
		return false;})
		var content = $(this);
		content.find("#calcular").click( function(){
			var precio = content.find("#precio").val();
			var interes = content.find("#interes").val();
			var plazo = content.find("#plazo").val();
			content.find("#mensualidad").val(calculoHipoteca(interes, precio, plazo));
			//content.find("#mensualidad").val(13);
			return false;
		});
		
		$(".miniFicha a.type02").click(function(){
			if(widget.css("display")=="none"){
				widget.slideDown("normal");
				
			}
			content.find("#precio").val($(this).find(".precio").html());
			content.find("#plazo").val("30");
			content.find("#calcular").click();
			return false;
		});
	});
	
	
})

function calculoHipoteca($interes,$precio_hip, $plazo){
	$pow = Math.pow((1 + ($interes / 1200)), ($plazo * 12)); 
    $pago = ($precio_hip * $pow) * ($interes / 1200) / ($pow - 1);
	return Math.round($pago);
}
