$(document).ready(function() {

	console.log("RESIZER CALLED.");

	maxH = 450;
	maxW = 760;
	
	$('td[id^="td_post"] img').each(function() {
		
		var thisH = $(this).attr("height");
		var thisW = $(this).attr("width");
				
		if(thisW > maxW) {
			var ratio = maxW / thisW;		
			$(this).css("width", maxW);
			$(this).css("height", Math.round(thisH * ratio));
			$(this).css("cursor", "pointer");
			$(this).addClass("image-resize");
		}
		
		if(thisH > maxH) {
			var ratio = maxH / thisH;
			$(this).css("height", maxH);
			$(this).css("width", Math.round(thisW * ratio));
			$(this).css("cursor", "pointer");
			$(this).addClass("image-resize");
		}
		
		$(this).attr("rel", thisH);
		$(this).attr("rev", thisW);
	});
	
	$(".image-resize").click(function() {
		
		var newH = $(this).attr("rel");
		var newW = $(this).attr("rev");
		var oldH = $(this).attr("height");
		var oldW = $(this).attr("width");
		
		$(this).attr("rel", oldH);
		$(this).attr("rev", oldW);
		$(this).css("height", newH);
		$(this).css("width", newW);
		
	});
		
});
