(function($){

/**
 *	BoÃ®tes pour fonctions de partage et favoris
 */
$(function() {
	$( "#dialog-share" ).dialog({
		autoOpen: false,
		draggable: false,
		resizable: false,
		height: 380,
		width:313,
		show: "fade",
		modal: true
	});
	$( "#share-link" ).click(function() {
		$( "#dialog-share" ).dialog( "open" );
		// close the other dialog boxes if needed
		$("#dialog-account").dialog("close");
		$("#dialog-favourite").dialog("close");
		return false;
	});
	
	$( "#dialog-favourite" ).dialog({
		autoOpen: false,
		draggable: false,
		resizable: false,
		height: 250,
		width:290,
		show: "fade",
		modal: false
	});
	$( "#favourite-link" ).click(function(event) {
		$("#dialog-favourite").dialog('option','position',[event.clientX,100]);
		$("#dialog-favourite").dialog("open");
		// close the other dialog boxes if needed
		$("#dialog-share").dialog("close");
		$("#dialog-account").dialog("close");
		return false;
	});
	
	$( "#dialog-account" ).dialog({
		autoOpen: false,
		draggable: false,
		resizable: false,
		height: 210,
		width:215,
		show: "fade",
		modal: false
	});
	$( "#account-link" ).click(function(event) {
		$("#dialog-account").dialog('option','position',[event.clientX,100]);
		$("#dialog-account").dialog("open");
		// close the other dialog boxes if needed
		$("#dialog-share").dialog("close");
		$("#dialog-favourite").dialog("close");
		return false;
	});
});

function openDropDown(target) {
	target.fadeIn(300);
}
function closeDropDown(target) {
	target.fadeOut(300);
}


/*** 
	Ouverture de la Google Map.
	Utilise l'API V3.
	
	#### TEMPORAIRE POUR DEMO : doit utiliser les infos sur l'appart chargÃ©es via Ajax ou autre...
*/
function openApartMap() {	
	// Les coordonnÃ©es GPS de l'appart
	var mapLatlng = new google.maps.LatLng(48.859365,2.356632);
	var mapOptions = {
	  zoom: 16,
	  center: mapLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var apartMap = new google.maps.Map(document.getElementById("map_canvas_99"), mapOptions);

	// Place le marqueur avec le nom de l'appart
	var apartMarker = new google.maps.Marker({
		position: mapLatlng, 
		map: apartMap,
		title:"Appartement DÃ©lices des Tournelles"
	});
	$("#map_canvas_99").show();
}


$(document).ready(function() {
	
	// smooth scroll
	$(".navtabs A").anchorAnimate({speed:1000,easing:'easeInOutQuart'});
	$(".apart-pricing A.dir_down").anchorAnimate({speed:1000,easing:'easeInOutQuart'});
	
		
    $('#nav ul li').has('ul').children('a').addClass('daddy');
				   
	/* Affichage des options supplÃ©mentaires dans le bloc de recherche */
	$("#btn_toggleSearchOptions").click(function(event) {
		toggleSearchOptions();					   
		event.preventDefault();
	});

        if(($("#searchMore select[name=number_of_chambers]").length && $("#searchMore select[name=number_of_chambers]").val() != "") ||
	   ($("#searchMore input[name=with_lift]").length && $("#searchMore input[name=with_lift]").is(":checked")))
        {
	    //show searchMore
	    toggleSearchOptions();
	}
        else
        {
	    //hide searchMore
            $("#searchMore").hide();
	}
	
	/* SÃ©lection de langue */
	$("#lang_selected").click(function(event) {				   
		openDropDown($(".lang_selector"));
		event.preventDefault();
	});
	$(".dropdown .flag").click(function(event) {
		closeDropDown($(".lang_selector"));
		//event.preventDefault();
	});
	
	/* Champs de texte avec tip */
	$(".tipped").bind("blur", function(event) {
		if(this.value === "") {
			$(this).toggleClass("blurred", true);
			this.value = this.title;
		}
	});
	$(".tipped").bind("focus", function(event) {
		if(this.value === this.title) {
			this.value = "";
			$(this).toggleClass("blurred", false);
		}
	});
	$(".tipped").each(function(index){
		$(this).val($(this).attr('title'));
	});
	
	
	/* Tooltips sur pictos Confort */
	$(".picto_c").tooltip({effect: 'slide',
						   tipClass:'tooltip_mini',
						   position:'top right',
						   offset: [15,-30]});
	
	
	/* Tooltips sur les liens "Appartement" */
	$(".apartLink").tinyTips('title');
	
        /*
	$(".favSwitch").click(function(event) {
		if($(this).hasClass('isfav')) {
			$(this).removeClass('isfav');
			$(this).addClass('notfav');
			$(this).html("ajouter Ã  mes favoris");
		} else {
			$(this).addClass('isfav');
			$(this).removeClass('notfav');
			$(this).html("supprimer de mes favoris");
		}
		event.preventDefault();
	});
	*/
	
	/* 
		Ouverture de la Google Map au clic sur un bouton "afficher la carte" dans la liste d'apparts.
		Utilise l'API V3.
	*
	var mapLatlng = new google.maps.LatLng(48.859365,2.356632);
	var mapOptions = {
	  zoom: 16,
	  center: mapLatlng,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var apartMap = new google.maps.Map(document.getElementById("map_canvas_99"), mapOptions);

	// Place le marqueur avec le nom de l'appart
	var apartMarker = new google.maps.Marker({
		position: mapLatlng, 
		map: apartMap,
		title:"Appartement DÃ©lices des Tournelles"
	});
	*/
	
});


})(jQuery);

  var hideCalendarInputButton = function(e) {
	  var $e = jQuery(e);
	  var id = $e.attr('id');
	  jQuery('img[id="trigger_'+id+'"]').css("visibility", "hidden").css("width", "1px");
	  $e.click(function(){
	      jQuery('img#trigger_'+id).click();
	      jQuery(this).focus();
	  });
  };
  jQuery(document).ready(function(){
      jQuery('input.input_date_calendar').each(function(i, e) {
	  hideCalendarInputButton(e);
      });
    });

