$(document).ready(function(){
	$(".hidden").css('display', 'none');

	$(".slider").click(function(){
		 $(this).parent().find('.slide-body').slideToggle("slow");
	});

	$(".more_photos").click(function(){
		$('.photos-body').slideDown("slow");
		$.scrollTo('.photos-body', 600);
	});

	$(".react").click(function(){
		$.scrollTo('#contact', 600);
		 //$('#contact').scroll();

	})

	$("a.gallery").fancybox({
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade',
		'speedIn'		:	600,
		'speedOut'		:	200,
		'overlayShow'	:	false,
		'titleShow'		:	true,
		'titlePosition'	:	'over'
	});

	$(".activity-img").hover(function(){
		$(this).find('.activity-text').slideToggle("");
	});

	$(".overview-img").hover(function(){
		$(this).find('.activity-text').slideToggle("");
	});


	$(".overview-obj").hover(
		function(){
			$(this).find(".more-info").css('font-size', '13px');
			$(this).find(".more-info").a('font-size', '13px');
		},
		function(){
			$(this).find(".more-info").css('font-size', '12px');
		}
	);

	//zoekblokken voorzien van goede waarden.
	var h_kind		= $("#hidden_kind").val();
	var h_min_price = $("#hidden_min_price").val();
	var h_max_price = $("#hidden_max_price").val();

	if(h_kind=='huur')
	{
		$("#min_price_huur option").each(function(){
			if($(this).val()==h_min_price)
				$(this).attr('selected','selected');
		});

		$("#max_price_huur option").each(function(){
			if($(this).val()==h_max_price)
				$(this).attr('selected','selected');
		});

		$("#min_price_koop").hide();
		$("#min_price_huur").show();
		$("#max_price_koop").hide();
		$("#max_price_huur").show();
	}
	else if(h_kind=='koop' || h_kind == '')
	{
		$("#min_price_koop option").each(function(){
			if($(this).val()==h_min_price)
				$(this).attr('selected','selected');
		});

		$("#max_price_koop option").each(function(){
			if($(this).val()==h_max_price)
				$(this).attr('selected','selected');
		});

		$("#min_price_huur").hide();
		$("#min_price_koop").show();
		$("#max_price_huur").hide();
		$("#max_price_koop").show();
	}

	$("#select_type").change(function(){
		var type_val = $(this).val();
		
		if(type_val==1 || type_val =='')
		{
			$("#min_price_huur").hide();
			$("#min_price_koop").show();
			$("#max_price_huur").hide();
			$("#max_price_koop").show();
		}
		else if(type_val==2)
		{
			$("#min_price_koop").hide();
			$("#min_price_huur").show();
			$("#max_price_koop").hide();
			$("#max_price_huur").show();
		}
	});

	/*
	 * Formulieren
	 */
	var options = {
		success:       showResponse,
		url:		   '/ajax/send_home_form.php'
	};
	$('#home_form').ajaxForm(options);
	
	$("table").tablesorter();

});

function showResponse(responseText, statusText, xhr, $form)  {
	var response = responseText.split('|');

	if(response[0]=='ERROR')
	{
		$('.error_message').hide();
		if(response.length>1)
			$('.error_message').slideDown();

		$(".form_field").css('border','1px solid #ccc');

		for(var i = 1; i <= (response.length-1); i++)
			$("#"+response[i]).css('border', '2px solid red');
	}
	else
	{
		$("#home_form").hide();
		$('.error_message').hide();
		$("#succes_message").slideDown();
	}
}

function popUp(URL, w, h)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+",left = 560,top = 88');");
}
