function validateSearch()
{
	if(srchObj.state.selectedIndex == 0 && srchObj.county.selectedIndex == 0 && srchObj.property_type.selectedIndex == 0 && srchObj.min_price.selectedIndex == 0 && srchObj.max_price.selectedIndex == 0 && srchObj.acres.selectedIndex == 0)
	{
		alert("Please select at least one value to search.");
		return;
	}
	srchObj.action = 'search_result.html';
	srchObj.submit();
}
$(document).ready(function(){
	$('.pic').mousedown(function(e){

		elem = $(this)[0].id;
		idx = elem.replace('pic-', '');
		activate = $('#'+elem).backgroundImageUrl();
		inActivate = $('#pic-2').backgroundImageUrl();
		if(activate != inActivate)
		{
			pic2_img_id = document.getElementById('hp_image_id2');
			pic2_img_value = pic2_img_id.value;
			curr_pic_img_id = document.getElementById('hp_image_id'+idx);
			curr_pic_img_value = curr_pic_img_id.value;
			$('#pic-2 .pic-tip').fadeOut(400);
			params = 'hp_image_id='+curr_pic_img_value;
			$.ajax({
				type:'POST',
				data: params,
				url: 'change_tip_process.php',
				success: function(retVal){
							$('#pic-2 .pic-tip').html(retVal);
							$('#pic-2 .pic-tip').fadeIn();

					pic2_img_id.value = curr_pic_img_value;
					curr_pic_img_id.value = pic2_img_value;
				}
			});
			$('#pic-2').stop().animate({opacity: 0.7}, function(){
				$(this).backgroundImageUrl(activate).animate({opacity: 1});
				$('#'+elem).backgroundImageUrl(inActivate);

			});
		}
	});

	$interval = '10000';
	var timer = function()
	{
		$('.next').click();
	}
	stopTimer = setTimeout(timer, $interval);

	$('.prev').click(function(){
		clearTimeout(stopTimer);

		$('.slideshow_slides').stop().animate({opacity: 0.7}, function(){

			lastIDVal = document.getElementById('hp_image_id5').value;
			for(i = 5; i >= 2; i--)
			{
				nextID = document.getElementById('hp_image_id' + i);
				prevID = document.getElementById('hp_image_id'+ (i-1));
				prevIDVal = prevID.value;
				nextID.value = prevIDVal;
			}
			document.getElementById('hp_image_id1').value = lastIDVal;

			params = 'hp_image_id='+document.getElementById('hp_image_id2').value;
			$.ajax({
				type:'POST',
				data: params,
				url: 'change_tip_process.php',
				success: function(retVal){
					$('#pic-2 .pic-tip').html(retVal);
				}
			});

			lastBG = $('#pic-5').backgroundImageUrl();
			for(i = 5; i >= 2; i--)
			{
				nextElem = '#pic-' + i;
				prevElem = '#pic-'+ (i-1);
				prevElemBG = $(prevElem).backgroundImageUrl();
				$(nextElem).backgroundImageUrl(prevElemBG).animate({opacity: 1});
			}
			$('#pic-1').backgroundImageUrl(lastBG).animate({opacity: 1});
			$(this).animate({opacity: 1});
		});

		stopTimer = setTimeout(timer, $interval);
	});

	$('.next').click(function(){
		clearTimeout(stopTimer);

			$('.slideshow_slides').stop().animate({opacity: 0.7}, function(){

			firstIDVal = document.getElementById('hp_image_id1').value;
			for(i = 1; i <= 4; i++)
			{
				prevID = document.getElementById('hp_image_id' + i);
				nextID = document.getElementById('hp_image_id'+ (i+1));
				nextIDVal = nextID.value;
				prevID.value = nextIDVal;
			}
			document.getElementById('hp_image_id5').value = firstIDVal;

			params = 'hp_image_id='+document.getElementById('hp_image_id2').value;
			$.ajax({
				type:'POST',
				data: params,
				url: 'change_tip_process.php',
				success: function(retVal){
					$('#pic-2 .pic-tip').html(retVal);
				}
			});

			firstBG = $('#pic-1').backgroundImageUrl();
			for(i = 1; i <= 4; i++)
			{
				prevElem = '#pic-' + i;
				nextElem = '#pic-'+ (i+1);
				nextElemBG = $(nextElem).backgroundImageUrl();
				$(prevElem).backgroundImageUrl(nextElemBG).animate({opacity: 1});
			}
			$('#pic-5').backgroundImageUrl(firstBG).animate({opacity: 1});
			$(this).animate({opacity: 1});
		});

		stopTimer = setTimeout(timer, $interval);
	});

});

(function ($) {
	$.fn.backgroundImageUrl = function(options) {
		if (options){
			return this.each(function(){
				$(this).css('backgroundImage','url('+options+')');
			});
		}else {
			var pattern = /url\(|\)|"|'/g;
			return $(this).css('backgroundImage').replace(pattern,"");
		}
	};
})(jQuery);

