$(function() {
	equalHeight($("#app-description").add($("#app-sidebar")));
	var app = $(".app");
	app.each(function() {
		var clickedApp = $(this);
		clickedApp.click(function() {
			// highlight selected app
			app.each(function() {
				if (clickedApp.attr("id") == $(this).attr("id")) {
					$(this).addClass("current");
				} else {
					$(this).removeClass("current");
				}
			});
		
			// grab content for selected app
			var thisAppContentDiv = "#" + $(this).attr("id") + "-content";
			var thisAppDescription = $(thisAppContentDiv + " .description").html();
			var thisAppComments = $(thisAppContentDiv + " .sidebar").html();
			var thisAppBoxName = $(thisAppContentDiv + " .box-name").html();
			var thisAppBoxDev = $(thisAppContentDiv + " .box-dev").html();
			var thisAppBoxCat = $(thisAppContentDiv + " .box-cat").html();
			var thisAppBoxPrice = $(thisAppContentDiv + " .box-price").html();
			var thisAppBoxRating = $(thisAppContentDiv + " .box-rating").html();
						
			// fade out
			$("#app #app-description").fadeOut("fast");
			$("#app #app-info-box table").fadeOut("fast");
			$("#app #app-user-comments").fadeOut("fast", function() {
			
				// update div with content
				$("#app #app-description").html(thisAppDescription);
				$("#app #app-user-comments").html(thisAppComments);
				$("#app #box-name").html(thisAppBoxName);
				$("#app #box-dev").html(thisAppBoxDev);
				$("#app #box-cat").html(thisAppBoxCat);
				$("#app #box-price").html(thisAppBoxPrice);
				$("#app #box-rating").html(thisAppBoxRating);
			
			});
			
			// fade in
			$("#app #app-description").fadeIn("fast");
			$("#app #app-info-box table").fadeIn("fast");
			$("#app #app-user-comments").fadeIn("fast");
		});
	});
});

function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = parseFloat($(this).height());
		if (thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}