function bbg_table(table) {
		var bbg_classtable;

		bbg_classtable = $('#'+table).dataTable( {
			"fnDrawCallback": on_draw,
			"fnHeaderCallback": before_draw,
			"sDom": '<"tablecontrol"f>t<"bottom">lipr',
			"bFilter": true,
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": true,
			"bSort": false,
			"bInfo": false,
			"aaSorting": [[3,'asc']],
			"aoColumns": [
							{ "sType": 'html' },
							{ "sType": 'html' },
							{ "sType": 'html' },
							{ "sType": 'numeric' }
						]
		});
		//Add the dropdown here, because the dataTable plugin 
		//is injecting the search box, so need to wait till 
		//it's injected then add to the same div.
/*
<option value ="">All</option>
<option value ="Garden Design">Garden Design</option>
<option value ="Gardening for Wildlife">Gardening for Wildlife</option>
<option value ="Gardening Techniques">Gardening Techniques</option>
<option value ="Great Plants">Great Plants</option>
<option value ="Kitchen Gardening">Kitchen Gardening</option>
<option value ="Children's Gardening">Children's Gardening</option>
*/
		//HACK: extra floatleft-div for ie :-/
		$('#'+table+'_filter').parent().prepend('<!--[if IE]><div style="float: left; margin-top:0px;"><![endif]--><div style="float: left; margin-right: 10px;"><span style="float: left; margin-top: 2px;">View: </span><select id="'+table+'_selectsort" style="margin-left: 3px;"><option value ="">All</option><option value ="Garden Design">Garden Design</option><option value ="Gardening for Wildlife">Gardening for Wildlife</option><option value ="Gardening Techniques">Gardening Techniques</option><option value ="Great Plants">Great Plants</option><option value ="Kitchen Gardening">Kitchen Gardening</option><option value ="Children\'s Gardening">Children\'s Gardening</option></select></div><!--[if IE]></div><![endif]-->');

		//Event Handlers
		$('#'+table+'_selectsort').change( function() {
			bbg_classtable.fnFilter($(this).val(), 2);
	  });

	  //Remove this event, since we are sorting from the drop down.
	  $(".classtable thead th").unbind('click');
	  
	  if(window.location.hash) {
	  	//Check if the url has a hash.
	  	
	  	//If yes find the link with this name, 
	  	//then trigger the click event to the row that contains it.

	  	//remove the hash char.
	  	var hash_name = window.location.hash.toString().replace(/#/, "");
	  	
	  	$('a[name="'+hash_name+'"]').parent().parent().trigger('click');

	  	//Go to this hash, in case the table was sorted and the scroll location is inaccurate.
	  	window.location = window.location.hash;
	  } else if (window.location.search) {
	  	//Check if the url has a catagory to filter by.
	  	//Remove dashes.
	  	var cat_name = window.location.search.toString().replace(/\?type=/, "").replace(/[-]/g," ");

			//Filter table.
	  	bbg_classtable.fnFilter(cat_name, 2);

	  	//Show selected option.
			$('#'+table+'selectsort option').removeAttr('selected');
			$('#'+table+'selectsort option[value='+cat_name+']').attr('selected', 'true');
	  } /*else {
	  	$('a[name="HealthySoilsforSustainableGardens"]').parent().parent().trigger('click');
	  }*/
}
before_draw = function() {
		//reset active entry:
		$('td.selectedEntry').parent().trigger('click');
		///alert($('td.selectedEntry').parent().html());
}
on_draw = function() {
	set_event();
}

function set_event() {
		$('.classtable tbody tr').unbind('click');
	  $('.classtable tbody tr').click(function(e) {	
	  	var exp = /expand_btn/;
	  	var expc = /collapse_btn/;
	  	
	  	if(e.target.href != undefined) {
	  		//If link is clicked, go to that link and don't exapnd row.
	  		if(! exp.test(e.target.href) && ! expc.test(e.target.href)) {
	  			//IE thinks that the src of the expand btn is a target
	  			//If not the expand btn or collpase btn, just go to that link, and cancel this function.
	  			return;
	  		}
	  	}
	  
	  	var img = $(this).children("td:first").children("img:first");
		  var src = img.attr("src");
		  
		  if(exp.test(src)) { //If need to expand the row:
		  	  	
		  	$(this).css("cursur", "none");
		  	var new_src = img.attr("src").replace(/expand_btn.png/i, "collapse_btn.png");
		  	img.attr("src", new_src);
		  	img.parent().addClass("selectedEntry").siblings().addClass("selectedEntry");
		  	var book_desc = img.parent().siblings('td:first').children("div").children("div.bookdescription").html();
		  	var book_img = img.parent().siblings('td:first').children("div").children("div.bookcover").html();
		  	var book_purchase = img.parent().siblings('td:first').children("div").children("div.bookpurchase").html();
		  	book_img = book_img!='' ? '<div class="bookcover">'+book_img+'</div>' : '';
		  	img.parent().parent().after('<tr><td class="selectedEntry desccell"></td><td class="selectedEntry desccell" style="padding-right: 8px;" colspan="3" width="550px">'+book_img+'<div class="bookdescription">'+book_desc+book_purchase+'</div><br /></td></tr>').next().hide().fadeIn(700);
		  } else { //Else, collpase the row:
		  				
		  	$(this).css("cursur", "pointer");
		  	img.parent().parent().next().remove();
		  	var new_src = img.attr("src").replace(/collapse_btn.png/i, "expand_btn.png");
		  	img.attr("src", new_src);
		  	img.parent().removeClass("selectedEntry").siblings().removeClass("selectedEntry");
		  }
		});

		//activate first entry
		$('.classtable tbody tr:first').trigger('click');
}