/*
	jquery.dg_columns.js
	Written by Stuart Elmore 29/08/09
	
	Usage:
	$(".selector").dg_columns({
		height: true, // false
		width: false, // true
		animate: false, // true
		animateSpeed: 250 // integer (milsec)
	});

*/ 
(function($){
  $.fn.dg_columns = function() {
	var options = arguments[0] || {};
	options = $.extend($.dg_columns.defaults, options);
    var elem = $(this);
	$.dg_columns.construct(elem, options);
  };
  $.dg_columns = {
	  defaults:{
		  height: true,
		  width: false,
		  animate: false,
		  animateSpeed: 250
	  },
	  construct: function(elem, options){
		  if(options.animate===false){options.animateSpeed=0;}
		  if(options.height===true){
			  $.data($('body').get(0), 'topHeight', 0);
			  $(elem).each(function(){
				if($.data($('body').get(0), 'topHeight')<$(this).height()){
				  $.data($('body').get(0), 'topHeight', $(this).height());
				}
			  });
			  if(options.width===false){
				  $(elem).animate({height:$.data($('body').get(0), 'topHeight')},options.animateSpeed);
			  }
		  }
		  if(options.width===true){
			  $.data($('body').get(0), 'topWidth', 0);
			  $(elem).each(function(){
				if($.data($('body').get(0), 'topWidth')<$(this).width()){
				  $.data($('body').get(0), 'topWidth', $(this).width());
				}
			  });
			  if(options.height===false){
				  $(elem).animate({width:($.data($('body').get(0), 'topWidth'))},options.animateSpeed);
			  }
		  }
		  if(options.height===true && options.width===true){
			  $(elem).animate({height:($.data($('body').get(0), 'topHeight')),width:($.data($('body').get(0), 'topWidth'))},options.animateSpeed);
		  }
	  }
  };
})(jQuery);