// Search Behaviour

jQuery.checkFilter = function(el) {
	var onClass = "on";
	
	if ($(el).is(":checked"))
		$(el).parent().addClass(onClass);
	else
		$(el).parent().removeClass(onClass);
}


$(function(){
	
	$("#searchFilters label").each(function(){
		$(this).replaceWith('<span id="for_'+ $(this).attr("for") +'">' + $(this).text() + "</span>");
	});

	$("#searchFilters input").each(function(){
		$.checkFilter($(this));
	});

/*	$("#searchFilters input").change(function(){
		$.checkFilter($(this));
	});*/

	$("#searchFilters span").click(function(e){
		var checkID = $(this).attr("id");
		checkID = "#" + checkID.substr(checkID.indexOf("_")+1);
		if ($(checkID).attr("checked")) {
			$(checkID).removeAttr("checked");
		} else {
			$(checkID).attr("checked", "checked");
		}
		$.checkFilter($(checkID));
	});

});
