(function($){  
 $.fn.boxify = function(options) {  

	var defaults = {  
		slack : ".slack",
		slackParent : "[class^='grid_']"
	}; 

	var o = $.extend(defaults, options);  

	return this.each(function() {  
		iter = 0;

		function findSlackNodes(node){
			var slackNodes = new Array;
		}

		function resizeChildSlack(aNode, setHeight){
			var difference = setHeight - $(aNode).height();
			var cSlack = $(aNode).children(o.slack).children('.curvy');
			$(cSlack).each(function(){
				var currentHeight = $(this).height();
				$(this).css({'min-height' : currentHeight + (difference / cSlack.length)});

				// $(this).height(currentHeight + (difference / cSlack.length));

				//console.log(this);
				//console.log('^^^ resized to ' + currentHeight + ' + ' + difference);
			});
		}


		//@return Boolean	Does this node have any children slack? 
		function hasChildSlack(aNode){
			var v = $(aNode).children(o.slack);
			if(v.length > 0){
				return true;
			}else{
				return false;
			}
		}

		function hasDecSlack(aNode){
			var v = $(aNode).find(o.slack);
			if(v.length > 0){
				return true;
			}else{
				return false;
			}
		}


		function equalBox (node) {
			iter++;

			if(hasDecSlack(node))
			{
				//console.log('equalBox #' + iter + $(node).attr('id'));
				var cNodes = $(node).children(o.slackParent); //children grid nodes of Node
				//console.log(cNodes);

				var cNodeTallest = 0;

				$(cNodes).each(function(){
					if($(this).height() > cNodeTallest) { 
						cNodeTallest = $(this).height(); //Here we find the height of the tallest child node
					}
				});

				//here we resize the children slack to match hight of tallest child element
				$(cNodes).each(function(){
					resizeChildSlack(this, cNodeTallest);

					//once children are resized; it's time to move on - start recursion
					equalBox(this);
				});

				//at this point the children are equal and we continue to recursively
				//resize all slack children

			}else{
				//if this node has no slack anywhere then we must end our journey			
				//console.log('end of equalBox #' + iter);
				return true;
			}

			//console.log('cNodeTallest '+ cNodeTallest);

		}

	equalBox(this);
		
    });  
 };  
})(jQuery);
