// Application Blocks
// @author Schoolwires Development Team (Gina B, Brenton K, Paul N, Joseph K)
// Last updated on 07/21/11 by Joseph K.
//When each app has styling you can use this to extend the last app down to the bottom of the column. Add to your resize function also.

(function($) {
		  
	$.fn.appBlocks = function(settings){
		//SETTINGS
		var config = {
			'additionalSpacing' : 0
		};
		//if there are outside setting passed in extend them into the plug-in
		if (settings){$.extend(true, config, settings);
			
		
		}
			
			return this.each(function() {
				//Varible Declaration
				var element = this;
				
				var totalAppHeaderHeight = 0;
				var totalAppDetailHeight = 0;
				var totalAppFooterHeight = 0;
				var totalAppMoreLinkHeight = 0;
				var columnHeight = 0;
				var lastAppDetailHeight = 0;
				var addLastAppDetailHeight = 0;
	            buildBlocks();
				
				function buildBlocks() {
					//Grabbing All App Elements Height w/Addition Spacing
					$("div.ui-widget.app", element).each(function () {
						totalAppHeaderHeight += $(this).find("div.ui-widget-header").height();
						totalAppDetailHeight += $(this).find("div.ui-widget-detail").height();
						totalAppFooterHeight += $(this).find("div.ui-widget-footer").height();
						totalAppMoreLinkHeight += $(this).parent().find("a.more-link").height() + config.additionalSpacing ;
						
						
						
					});
					
					//Grab Column Height
					columnHeight = $(element).height();
					
					//Finding Last App Detail Height
					lastAppDetailHeight = $("div.ui-widget.app div.ui-widget-detail:last", element).height();

					
					//Calculating Last Detail Height
					addLastAppDetailHeight = columnHeight - totalAppHeaderHeight - totalAppDetailHeight - totalAppFooterHeight  - totalAppMoreLinkHeight + lastAppDetailHeight;
					
					//Setting the Last App Detail Height
					$("div.ui-widget.app div.ui-widget-detail:last", element).height(addLastAppDetailHeight);
					
				};
			});
	};
})(jQuery);
		
