var bSearchMapLoaded = new Boolean(false);

$(document).ready(function() {
	/** Begin tabs **/
	$("#tabsearch").click(function(event)
	{
		event.preventDefault();
		if ($("#search").css("display") != "block")
		{
			$("#tabmap").removeClass("item-active").addClass("item-inactive");
			$("#tabsearch").removeClass("item-inactive").addClass("item-active");
			$("#map").stop(true,true).slideUp("slow",function()
			{
				$("#search").delay(100).stop(true,true).slideDown("slow");
			});
		}
		return false;
	});
	$("#tabmap").click(function(event)
	{
		event.preventDefault();
		if ($("#map").css("display") != "block")
		{
			$("#tabsearch").removeClass("item-active").addClass("item-inactive");
			$("#tabmap").removeClass("item-inactive").addClass("item-active");
			$("#search").stop(true,true).slideUp("slow",function()
			{
				$("#map").delay(100).stop(true,true).slideDown("slow",function()
				{
					if (bSearchMapLoaded == false)
					{
						bSearchMapLoaded = true;
						createGoogleSearchMap();
					}
				});
			});
		}
		return false;
	});
	
	/** More info **/
	$(".more, .photo").click(function(event)
	{
		event.preventDefault();
		window.location = "huis.php?id="+ $(this).closest(".house").attr("house");
		return false;
	});
	
	$("#quicktab .tab").click(function(event)
	{
		event.preventDefault();
		window.location = $(this).find(".tabclick").attr("href");
		return false;
	});
	
	/** Dropdowns **/
	$(".field").click(function(event)
	{
		event.preventDefault();
		if ($(this).parent().find(".options").css("display") == "block")
		{
			$(this).parent().find(".options").slideUp("fast");
		}
		else
		{
			var options = $(this).parent().find(".options");
			//var width = options.height();
			/* options.css("margin-top","-"+ height +"px");
			options.css("top",height +"px"); */
			/* options.css("position","absolute");
			options.css("width","absolute"); */
			options.width($(this).closest(".dropdown").width()-2);
			options.slideDown("fast");
		}
		return false;
	});
	$(".option").click(function(event)
	{
		event.preventDefault();
		$(this).closest(".dropdown").find(".hidfield").val($(this).attr("value"));
		$(this).closest(".dropdown").find(".field").html($(this).html());
		$(this).closest(".dropdown").find(".options").slideUp("fast");
		return false;
	});
});
