var loop_time = 5000;
$(document).ready(function(){	
	var fsearch_str = $('#fsearch').val();	
	$('#fsearch').focus(function(){if($(this).val() == fsearch_str) $(this).val(''); }).blur(function(){ if($(this).val() == '') $(this).val(fsearch_str); });
	options = { serviceUrl: SITE_PATH+'system/fsbsearch.php',
			minChars:3,
			delimiter: /(,|;)\s*/, // regex or character
			maxHeight:200,
			width:205,
			zIndex: 100000,
			deferRequestBy: 0, //miliseconds
			noCache: true, //default is false, set to true to disable caching
			// callback function:
			onSelect: function(value, data){ $('#suburb_id').val(data); }
	};
	$('#fsearch').autocomplete(options);
	
	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').css('height','382px').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++;		
	}
	$('#fast-search form').submit(function() {
		$('#fast-search form').attr('action', SITE_PATH+$('#fast-search input:radio:checked').val());
		return true;
	});
	$('#appraisal, #testimonials, #property-alert,#radio').click(function() {
		var a_link = $(this).find('a');
		if(a_link.attr('target') == '_blank') {
			window.open(a_link.attr('href'));
		}else {
			location.href = a_link.attr('href');
		}
		return false;
	});
	
});
