$(document).ready(function () {

	$('.homefader').cycle({ 
	    fx:      'fade', 
	    pause:		1,
	    delay:    	-5000,
	    timeout:  	8000,
	    speed:		1500,
	    //pager:      '#nav',
	    //prev:		'#prev',
	    //next:		'#next'
	    });

    $('#searchbtn').click(function(){
    	$('#searchform').submit();
    	return false;
    });
    
    $('#clearsrchoptn').click(function(){
    	$('#searchform input').attr('checked', '');
    	$('#van option:first').attr('selected','selected');
    	$('#tot option:first').attr('selected','selected');
    	return false;
    });
    
    $('.doingnothing').click(function(){
    	return false;
    });
    
    $('.gotoFirstPage').click(function(){
    	$('#PageNum').val(1);
    	$('#searchform').submit();
    	return false;
    });
    
    $('.gotoLastPage').click(function(){
    	$('#PageNum').val('last');
    	$('#searchform').submit();
    	return false;
    });
    
    $('.gotoPrevPage').click(function(){
    	var pagenum = parseInt($('#PageNum').val());
    	pagenum -= 1;
    	$('#PageNum').val(pagenum);
    	$('#searchform').submit();
    	return false;
    });
    
    $('.gotoNextPage').click(function(){
    	var pagenum = parseInt($('#PageNum').val());
    	pagenum += 1;
    	$('#PageNum').val(pagenum);
    	$('#searchform').submit();
    	return false;
    });
    
    $('.setPriceAsc').click(function(){
    	$('#OrderBy').val('min_price');
    	$('#SortOrderBy').val('asc');
    	$('#searchform').submit();
    	return false;
    });
    
    $('.setPriceDesc').click(function(){
    	$('#OrderBy').val('min_price');
    	$('#SortOrderBy').val('desc');
    	$('#searchform').submit();
    	return false;
    });
    
    $('.setHousemodelAsc').click(function(){
    	$('#OrderBy').val('housemodel');
    	$('#SortOrderBy').val('asc');
    	$('#searchform').submit();
    	return false;
    });
    
    $('.setHousemodelDesc').click(function(){
    	$('#OrderBy').val('housemodel');
    	$('#SortOrderBy').val('desc');
    	$('#searchform').submit();
    	return false;
    });
    
    $('.setDistrictAsc').click(function(){
    	$('#OrderBy').val('district');
    	$('#SortOrderBy').val('asc');
    	$('#searchform').submit();
    	return false;
    });
    
    $('.setDistrictDesc').click(function(){
    	$('#OrderBy').val('district');
    	$('#SortOrderBy').val('desc');
    	$('#searchform').submit();
    	return false;
    });
    
    $('#qbtn').click(function(){
    	var total_size = $('#questionsform input.obligatory').size();
    	var checked_size = $('#questionsform input.obligatory:checked').size();
    	var additional_chk_size = $('#questionsform input.obligatory_add:checked').size();
    	
    	if (parseInt(additional_chk_size) > 0)
    		checked_size = parseInt(additional_chk_size) + parseInt(checked_size); 
    	
    	if (checked_size < (total_size / 2) )
    	{
    		alert('U moet alle vragen beantwoorden');
    	}
    	else
    	{
    		$('#questionsform').submit();
    	}
	});
	
	$('#keuze_tekst').click(function()
	{
		$('#form_tekst').slideDown();
		$('#form_foto').slideUp();
	});
	
	$('#keuze_foto').click(function()
	{
		$('#form_foto').slideDown();
		$('#form_tekst').slideUp();
	});
	
	$("input#keuze_foto:checked")
	{
		$('#form_foto').show();
		$('#form_tekst').hide();
	}
	
	$('#gallery .thumb a').lightBox({
		imageLoading:			'/wp-content/themes/koophuis/images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
		imageBtnPrev:			'/wp-content/themes/koophuis/images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
		imageBtnNext:			'/wp-content/themes/koophuis/images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
		imageBtnClose:			'/wp-content/themes/koophuis/images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
		imageBlank:				'/wp-content/themes/koophuis/images/lightbox-blank.gif'
	});
    
    $('#upprev_page').click(function(){
    	var page_num = parseInt($('#uppage_num').val());
    	page_num -= 1;
    	$('#uppage_num').val(page_num);
    	$('#upform').submit();
    	return false;
    });
    
    $('#upnext_page').click(function(){
    	var page_num = parseInt($('#uppage_num').val());
    	page_num += 1;
    	$('#uppage_num').val(page_num);
    	$('#upform').submit();
    	return false;
    });
    
    $('#uptotext').click(function(){
    	$('#upitem_type').val('text');
    	$('#uppage_num').val(0);
    	$('#upform').submit();
    });
    
    $('#uptophoto').click(function(){
    	$('#upitem_type').val('image');
    	$('#uppage_num').val(0);
    	$('#upform').submit();
    });
    
    $('#printthispage').click(function(){
    	if (window.print)
    	{
    		window.print();
    	}
    });
    
});

function SearchComponent(){
	 	this.name = null;
	 	this.link = '';
		this.image_link = '';
		this.district = null;
		this.housemodel = null;
		this.min_price = null;
		this.max_price = null
		this.min_rooms = null;
		this.max_rooms = null;
		this.min_surface = null;
		this.max_surface = null;
		this.lat = null;
		this.lng = null;
		this.rank = null;
}
