$(document).ready(function(){
	$(".check_all").click(function(){
		   $(".checked_item").attr("checked","checked");
		   $(".count_checked").html( countChecked("checked_item") );
	   }
   	);
	$(".uncheck_all").click(function(){
		   $(".checked_item").attr("checked","");
		   $(".count_checked").html( countChecked("checked_item") );
	   }
   	);
	$(".checked_item").click(function(){
			$(".count_checked").html( countChecked("checked_item") );							 
	 	}
	 );
	
	function countChecked(identifier){
		return parseInt(0 + ($("." + identifier + ":checked").length) ).toString();	
	}
	
	$(".counter").each(function(){
		$("#" + $(this).attr('id') + "_counter").html($(this).attr("value").length);
	});
	
	$(".counter").keyup(function(){
		$("#" + $(this).attr('id') + "_counter").html($(this).attr("value").length);								
	});
	
	// Change price drop-downs based on proprty type chosen.
	$("#property_types_id").change(function(){
		var property_type = $(this).val();
		//
		$.ajax({
			type: "POST",
			url: "includes/reload_price_ranges.sstg",
			data: "property_type=" + property_type,
			success: function(html){
				// The two sets of select options are separated by "||".
				var options = html.split("||",2);
				$("#min_price").html(options[0]);
				$("#max_price").html(options[1]);
			}
		});
	});
	
});
function playSlideShow(identifier,duration){
	start_slide = $(identifier).data("config").start;
	current_slide = $(identifier).data("config").current;
	end_slide = $(identifier).data("config").end;
	//
	//setInterval("nextSlide('" + identifier + "'," + current_slide + "," + end_slide + ")",duration);
	setInterval("nextSlide('" + identifier + "')",duration);
}
	
function nextSlide(identifier){
	current_slide = parseInt(current_slide) + 1;
	current_slide = current_slide.toString();	
	
	if(parseInt(current_slide) > parseInt(end_slide)){
		current_slide = start_slide;	
	}

	$(identifier + " img").attr("src",$(identifier).data(current_slide).image);
	$(identifier + " a").attr("href",$(identifier).data(current_slide).url);
}