jQuery(document).ready(function() {

	jQuery('#cal a').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		jQuery.get("/immobiliere/calc.php", function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: false,
				overlayId: 'contact-overlay',
				containerId: 'contact-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});


	var noTagA=jQuery('#detail .blocBouton  a');
	jQuery(noTagA[1]).addClass('pictures');
	
	var noA=jQuery('#teaser-annonces-wrp .lastDescription .alignLeft a');
	jQuery(noA[1]).addClass('hide');
	jQuery(noA[3]).addClass('hide');
		
		
	var oneA=jQuery('.derniereBlock .alignLeft a:first').next();
	if (!jQuery(oneA).attr("href") ){oneA=jQuery('.derniereBlock .alignLeft a:first');}
	
	
	var blocB=jQuery('#teaser-annonces .derniereBlock').eq(1);
	var oneB=jQuery(blocB ).children().children().next();
	if (!jQuery(oneB).attr("href") ){oneB =jQuery(blocB).children().children();}

	jQuery(oneA).addClass('wrap-img');
	jQuery(oneB).addClass('wrap-img');
	jQuery('#teaser-annonces-wrp .derniereAnnonce  .lastDescription br').wrap('<span class="breakrow">'+'</span>');

		// preload images
		//var img = ['cancel.png','form_bottom.gif','form_top.gif','form_top_ie.gif','loading.gif','send.png'];
		//$(img).each(function () {
		//	var i = new Image();
		//	i.src = 'img/contact/' + this;
		//});
	
});
var contact = {
	message: null,
	open: function (dialog) {
		
		var title = jQuery('#contact-container .contact-title').html();
		jQuery('#contact-container .contact-title').html('Chargement ...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
					jQuery('#contact-container .contact-content').animate({
						height: 410
					}, function () {
						jQuery('#contact-container form').fadeIn(200, function () {
							jQuery('#contact-container .contact-title').html(title);
						});
					});
				});
			});
		});
	},
	show: function (dialog) {
	},
	close: function (dialog) {
		jQuery('#contact-container .contact-title').html('Au revoir et merci...');
		jQuery('#contact-container .contact-message').fadeOut();
		jQuery('#contact-container form').fadeOut(200);
		jQuery('#contact-container .contact-content').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						jQuery.modal.close();
					});
				});
			});
		});
	}	};
	
	
	function calculate() {
    // Get the user's input from the form. Assume it is all valid.    // Convert interest from a percentage to a decimal, and convert from    // an annual rate to a monthly rate. Convert payment period in years    // to the number of monthly payments.    var principal = document.loandata.principal.value;    var interest = document.loandata.interest.value / 100 / 12;    var payments = document.loandata.years.value * 12;    // Now compute the monthly payment figure, using esoteric math.    var x = Math.pow(1 + interest, payments);    var monthly = (principal*x*interest)/(x-1);    // Get named <span> elements from the form.    var payment = document.getElementById("payment");    var total = document.getElementById("total");    var totalinterest = document.getElementById("totalinterest");     // Check that the result is a finite number. If so, display the    // results by setting the HTML content of each <span> element.    if (isFinite(monthly)) {
         payment.innerHTML = monthly.toFixed(2);        total.innerHTML = (monthly * payments).toFixed(2);        totalinterest.innerHTML = ((monthly*payments)-principal).toFixed(2);    }    // Otherwise, the user's input was probably invalid, so display nothing.    else {        payment.innerHTML = "";        total.innerHTML = ""        totalinterest.innerHTML = "";    }}