$(document).ready(function() {
	
	var _hiddenHeight = 40;
	var _hiddenWidth = 40;
	
	var _hiddenTextHeight = 54;
	
	var firstRun = 1;
	
	$("img.expand").each(function() {
		
		var _expandedTextHeight = parseInt($(this).next("div").css("height"));
		var _expandedWidth = parseInt($(this).css("width"));
		var _expandedHeight = parseInt($(this).css("height"));		
		
		$(this).wrap("<div class=\"hideIMG\">")
		.parents("div.hideIMG")
		.click(
			function() {
				
				if (firstRun == 0) {
					$("div.expanded").not($(this)).animate({
					height:_hiddenHeight, 
					width:_hiddenWidth
					})
					.removeClass("expanded")

					.siblings("div.expandedText").not($(this)).animate({
						height:_hiddenTextHeight,
					})
					.removeClass("expandedText");
				}
			
				firstRun = 0;
				
				$(this).animate({
					height:_expandedHeight, 
					width:_expandedWidth
				}, 700)
				.addClass("expanded")
				
				.next("div").animate({
					height:_expandedTextHeight
				}, 700)
				.addClass("expandedText");
			}
		)
		.next("div").addClass("hideText").css("height", _hiddenTextHeight)
	});
});