function toggleFeedback(elem, id) {
	if ($(elem).hasClass("open")) {
		$(elem).removeClass("open");
		$("#feedback"+id).slideUp(300);
	}
	else {
		$(elem).addClass("open");
		$("#feedback"+id).slideDown(300);		
	}
	
	return false;
}


Drupal.behaviors.publishedFeedback = function() {
	var page = 0;
	var categoryId = 0;
	var cache = {}; //Used to cache the responses to requests
	
	//Cache what's on the page when it loads (the first page of feedbacks of category 'all')
	cache[0] = {};
	cache[0][0] = $("#publishedFeedback").html();
	
	var getFeedback = function() {
		if (cache[categoryId] && cache[categoryId][page]) {
			$("#publishedFeedback").html(cache[categoryId][page]);
			$("#publishedFeedback .pager a").click(paginationClick);
			return;
		}
		
		var url = drupalUrl+'get_feedback/'+categoryId;
		if (page) {
			url += ('?page='+page);
		}
		
		$.get(url, function(data) {
			$("#publishedFeedback").html(data);
			$("#publishedFeedback .pager a").click(paginationClick);
			if (!cache[categoryId]) {
				cache[categoryId] = {};
			}
			cache[categoryId][page] = data;
		});
	};
	
	var paginationClick = function() {
		var idx = -1;
		//Find the page number
		if ((idx = $(this).attr("href").indexOf("page=")) > -1) {
			idx += "page=".length;
			var tmp = '';
			for (var i = idx; i < $(this).attr("href").length; i++) {
				var c = $(this).attr("href").charAt(i);
				if (c < "0" || c > "9") {
					break;
				}
				tmp += c;
			}
			if (!tmp) {
				page = 0;
			}
			else {
				page = tmp;
			}	
		}
		else {
			page = 0;
		}
		
		getFeedback();
		return false;
	}
	
	
	$("#feedbackCategorySelect").change(function() {
		categoryId = $(this).val();
		page = 0;
		getFeedback();
		return false;
	});
	
	$("#publishedFeedback .pager a").click(paginationClick);
		
}