$(function() {
  var cardID, summary, tabArea, tabType;
	$(".readmore").each(function (i) {
 	cardID = $(this).attr("id");
	summary = $.ajax({type: "POST", async: false, url : "/listings.post.php", data : "docid=" + cardID + "&what=summary"}).responseText;
	tabArea = $("#readmore" + cardID + " .tab-area");
	$(tabArea).html(summary);

	// Code
	$("#readmore" + cardID + " .tab-menu ul li.tab-title a").click(function(event) {
		event.preventDefault();
		
		tabType = $(this).attr("class");
		cardID = $(this).parents("li").parents("ul").attr("id");
		tabArea = $("#readmore" + cardID + " .tab-area");
		if(tabType == "map") {
			var data = $.ajax({type: "POST", async: false, url : "/listings.post.php", data : "docid=" + cardID + "&what=map"}).responseText;
			data = data.split("|");
			$(tabArea).googleMap(data[0], data[1], 13, {controls: ["GSmallMapControl", "GMapTypeControl"]});
		}else{
			$.post("/listings.post.php", "docid=" + cardID + "&what=" + tabType, function(returnData) {
				$(tabArea).css({backgroundColor: "#FFF", border: "solid 1px #DDD"});
				$(tabArea).html(returnData);			
			});
		}
		return false; // Stops the actual link travelling
	});
	});
});

