// JS

window.addEvent('domready', function(){
	
	// Efecto del menu principal
	var mySlide = new Fx.Slide('subMenu');
	mySlide.slideOut();

	$('subMenuToggler').addEvent('click', function(e){
		e = new Event(e);
		mySlide.toggle();
		e.stop();
	});
	
	var mySlide2 = new Fx.Slide('subMenu2');
	mySlide2.slideOut();

	$('subMenuToggler2').addEvent('click', function(e){
		e = new Event(e);
		mySlide2.toggle();
		e.stop();
	});
	
	// Efecto de Hipoteca y de Promociones
	if($('kwicks'))
	{
		var szNormal = 100, szSmall  = 100, szFull   = 165;
		
		var kwicks = $$("#kwicks .kwick");
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 700, transition: Fx.Transitions.Back.easeOut});
		kwicks.each(function(kwick, i) {
			kwick.addEvent("mouseenter", function(event) {
				var o = {};
				o[i] = {height: [kwick.getStyle("height").toInt(), szFull]}
				kwicks.each(function(other, j) {
					if(i != j) {
						var w = other.getStyle("height").toInt();
						if(w != szSmall) o[j] = {height: [w, szSmall]};
					}
				});
				fx.start(o);
			});
		});
		
		$("kwicks").addEvent("mouseleave", function(event) {
			var o = {};
			kwicks.each(function(kwick, i) {
				o[i] = {height: [kwick.getStyle("height").toInt(), szNormal]}
			});
			fx.start(o);
		})
	} //end if wkicks
	
	// Seteamos el acordeon para las promociones
	if($('acordeon'))
	{
		var accordion = new Accordion('h3.toggler', 'div.element', {
			opacity: false,
			alwaysHide: true,
			onActive: function(toggler, element){
				toggler.setStyle('color', '#008EE0');
			},
			
			onBackground: function(toggler, element){
				toggler.setStyle('color', '#222');
			}
		}, $('acordeon'));
	} // end if kwicks
	
	
}); // fin de la dom ready



function calcularHipoteca(mensajeError)
{
	a = parseInt($('tbDuracion').value); // aņos
	c = parseInt($('tbCapital').value); // capital
	i = parseInt($('tbInteres').value)/100; // interes
	
	total = c * i / ( ( 1-Math.pow( (1+i/12) , (-a*12) ) ) *12) ;
	if(isNaN(total))
	{
		$('resultado').innerHTML = mensajeError;
	}
	else
	{
		$('resultado').innerHTML = total.toFixed(2).toString().replace(".",",") + " &euro;";
	}
	
	return false;
}
