$(document).ready( function () {

	//Préchargement des images
	$(window).load(function () {
		$.preloadCssImages();
	});

	//Illustration changement au survol accueil accueil.control.php
	$('a#acheter').hover( function () {
		$('a#acheter').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_acheter_hover.png")');
	}, function (){
		$('a#acheter').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_acheter.png")');
	});
	$('form#form_acheter').hover( function () {
		$('a#acheter').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_acheter_hover.png")');
	}, function (){
		$('a#acheter').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_acheter.png")');
	});
	
	$('a#vendre').hover( function () {
		$('a#vendre').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_vendre_hover.png")');
	}, function (){
		$('a#vendre').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_vendre.png")');
	});
	$('form#form_vendre').hover( function () {
		$('a#vendre').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_vendre_hover.png")');
	}, function (){
		$('a#vendre').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_vendre.png")');
	});
	
	$('a#promotion').hover( function () {
		$('a#promotion').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_promotion_hover.png")');
	}, function (){
		$('a#promotion').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_promotion.png")');
	});
	$('form#form_promotion').hover( function () {
		$('a#promotion').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_promotion_hover.png")');
	}, function (){
		$('a#promotion').css('background-image', 'url("http://www.immobilier-eden-golfe.com/template/img/illustration_promotion.png")');
	});
	
	//Gestion des champ input
	var input = [];
	
	$('input[type=text]').click(function () {
		if (input[$(this).attr('name')] == null) { 
			input[$(this).attr('name')] = $(this).attr('value');
			$(this).attr('value', '');
		}
		else if (input[$(this).attr('name')] == $(this).attr('value')) $(this).attr('value', '');
		$(this).focus();
	});

	$('input[type=text]').blur(function () {
		if ($(this).attr('value') == '') {
			$(this).attr('value', input[$(this).attr('name')]);
		}
	});
	
	$('textarea').click(function () {
		if (input[$(this).attr('name')] == null) { 
			input[$(this).attr('name')] = $(this).attr('value');
			$(this).attr('value', '');
		}
		else if (input[$(this).attr('name')] == $(this).attr('value')) $(this).attr('value', '');
		$(this).focus();
	});

	$('textarea').blur(function () {
		if ($(this).attr('value') == '') {
			$(this).attr('value', input[$(this).attr('name')]);
		}
	});
	
	$('input[type=password]').click(function () {
		if (input[$(this).attr('name')] == null) { 
			input[$(this).attr('name')] = $(this).attr('value');
			$(this).attr('value', '');
		}
		else if (input[$(this).attr('name')] == $(this).attr('value')) $(this).attr('value', '');
	});
	
	$('input[type=password]').blur(function () {
		if ($(this).attr('value') == '') {
			$(this).attr('value', input[$(this).attr('name')]);
		}
	});

	//Sous menu menu.vue.php
	$('#guide_immo ul').hide ();
	
	$('#guide_immo').hover ( function (){
		$('#guide_immo ul').show();
	},function(){
		$('#guide_immo ul').hide();
	});
	 
	//Déroule accueil.control.php
	var etat = null;
	
	//Masque 
	$('p[rel=hide]').css('display', 'none');
	$('div[rel=hide]').css('display', 'none');
	
	
	// Page d'accueil.
	$('.plus_info_recherche').click( function () {
		if (etat != null) {
			var form = $(this).attr('rel');
			$('form#'+form).animate({
				height: '116px'
			}, 500);
			$('form#'+form+' p[rel=hide]').hide();
			$(this).css('background', 'url("template/img/btn_plus.png")');
			etat = null;
		}
		else {
			var form = $(this).attr('rel');
			$('form#'+form).animate({
				height: '200px'
			}, 500, showEltHide($('form#'+form+' p[rel=hide]')));
			$(this).css('background', 'url("template/img/btn_moins.png")');
			etat = form;
		}
	});
	
	//Fonction callback appellée par animate.
	function showEltHide(elt) {
		elt.animate({
			opacity: 'show'
		}, 1000);
	}
	
	//Affichage liste des bien bien.control.php
	$( "#liste_bien #slider_bien" ).accessNews({
		headline : "",
		speed : "slow",
		slideBy : 1
	});
	
	//Affichage liste des bien bienDetail.control.php
	$( "#liste_recherche #slider_bien" ).accessNews({
		headline : "",
		speed : "slow",
		slideBy : 1
	});
	
	//Roll over sur les photos secondaire.
	$('.photos_secondaire img').mouseover ( function () {
		$('.photo_princ img').attr('src', $(this).attr('rel'));
	});
	
	//Affichage formulaire prise de contact detail bien
	$('#pictos a').click ( function () {
		var div = $(this).attr('id');
		if (div == 'contact'){ 
			$("."+div).show();
			$(".description").hide();
			$(".programe").hide();
			$(".diagnostique").hide();
			return false;
		}
		else if (div == 'diagnostique') {
			$("."+div).show();
			$(".contact").hide();
			$(".description").hide();
			$(".diagnostique").show();
			return false;
		}
		else if (div == 'description') {
			$("."+div).show();
			$(".contact").hide();
			$(".programe").show();
			$(".diagnostique").hide();
			return false;
		}
		else if (div == 'programe') {
			$("#photos").hide();
			$(".photos").show();
			$("#programe").show();
			$(".programe").hide();
			$(".contact").hide();
			return false;
		}
		else if (div == 'photo') {
			$("#photos").show();
			$(".photos").hide();
			$("#programe").hide();
			$(".programe").show();
			$(".contact").hide();
			return false;
		}
	});

});
