

	$('#searchForm').live('submit', function () {
		var type = $(this).find('select[name="search_type"]').val();
		if ($(this).find('select[name="search_city[]"]').val() == '') {
			alert('Please select a city.');
			return false;
		}
		if (!(type in { 'Rental' : true })) {
			if ($(this).find('select[name="minimum_price"]').val() == '') {
				alert('Please select a minimum price.');
				return false;
			}
		}
		if (!(type in { 'Rental' : true })) {
			if ($(this).find('select[name="maximum_price"]').val() == '') {
				alert('Please select a maximum price.');
				return false;
			}
		}
		if (!(type in { 'Commercial' : true, 'Land' : true, 'Lot' : true })) {
			if ($(this).find('select[name="minimum_bedrooms"]').val() == '') {
				alert('Please select minimum bedrooms.');
				return false;
			}
		}
		if (!(type in { 'Commercial' : true, 'Land' : true, 'Lot' : true, 'Rental' : true })) {
			if ($(this).find('select[name="minimum_bathrooms"]').val() == '') {
				alert('Please select minimum bathrooms.');
				return false;
			}
		}
		return true;
	});	



    
    $('#main_slideshow .slideset').each(function(){

        var slides = $(this).find('.slide');
        var width  = $(this).width(), height = $(this).height();

        slides.css({
            'width'  : width,
            'height' : height
        });

        slides.each(function() {
            $(this).find('img').each(function () {
                var $this = $(this);
                $this.attr('src', '/thumbs/' + width + 'x' + height + '/' + $this.attr('delayedsrc'));
                $this.closest('.slide').not('.active').css('opacity', 0);
            });
        });

        if (slides.length > 1) {

            setInterval(function () {

                var slides = $('#main_slideshow').find('.slide');

                var active = slides.filter('.active');

                if (active.length == 0) active = slides.filter(':first');

                var next = active.next().length ? active.next() : slides.filter(':first');

                active.removeClass('active').animate({opacity: 0.0}, 500, function() {
                    next.show().addClass('active').animate({opacity: 1.0}, 500);
                });

            }, 5000);

        }

    });


