var loop_time = 5000;
$(document).ready(function(){		
	$('#all_suburbs').click(function() {
		if($(this).is(':checked')) {
			$('input[name="suburbs[]"]').attr('checked', true);
		}else {
			$('input[name="suburbs[]"]').attr('checked', false);
		}
	});
	$('#select_all').click(function() {
		$('input[name="prop_to_print[]"]').attr('checked', true);
	});
	
	select_options = $('.option');
	$('.option').not('.'+$('.sale_type input:radio:checked').attr('alt')).remove();
	
	$('.sale_type input:radio').change(function() {
		var type = $(this).attr('alt');
		var min_price = select_options.filter('.min-price').filter('.'+type);
		var max_price = select_options.filter('.max-price').filter('.'+type);
		var suburbs = select_options.filter('.suburbs').filter('.'+type);
		var catg = select_options.filter('.catg').filter('.'+type);
		$('.option').remove();
		$('#rs-min-price').append(min_price);
		$('#rs-max-price').append(max_price);
		$('#rs-catg').append(catg);
		$('#rs-suburbs').append(suburbs);
		$('#rs-suburbs input:checkbox').attr('checked', false);
	});

	$('#quick-search input[type="submit"]').click(function() {
		$('#quick-search form').attr('action', SITE_PATH+$('#quick-search input:radio:checked').val());
	});
	
	var selectMax = $('#slideshow-box>ul li').length;
	finishLoading = 0;
	currentSel = 1;
	$('#slide_'+currentSel).hide().css('top', 0).fadeIn('normal');
	
	//$('#slideshow-box ul li').not('.active').children('p').hide();
	$('#slideshow-box ul li').each(function(index) {
		order = parseInt($(this).attr('id').replace("slide_", ""));
		$(this).children('img').attr('src', SITE_PATH+'img/home_bg'+order+'.jpg').removeClass('loading');
		finishLoading++;
	}).live('ON', function(event, current, next) {
		id = parseInt($(this).attr('id').replace("slide_", ""));
		if($(this).hasClass('active')) {
			$('#slideshow-box li').css('z-index', 'auto');
			$('#slide_'+current).css('z-index', 1);
			$('#slide_'+next).hide().css('top', 0).css('z-index', 2).fadeIn('normal');
		}
		currentSel = parseInt($(this).attr('id').replace("slide_", ""));
	});
	
	if(finishLoading == selectMax && selectMax>1) {
		var interval = setInterval(autoSlide, loop_time);
	}
	
	function autoSlide() {
		nextSel = currentSel + 1;
		if(nextSel > selectMax) {nextSel = 1;}
		$('#slide_'+currentSel).removeClass('active');
		$('#slide_'+nextSel).addClass('active').trigger('ON', [currentSel, nextSel]);	
		nextSel++;		
	}

});

