/*

Simple jquery grid plugin developed for Unit Editions
October 2010
Chris Barrow / chris-barrow.com

*/


(function($) {
	
	var opts, // defaults
		items, // from selector
		parent; // instance
	
	$.fn.grid = function(selector, options)
	{
		parent = this;
		items = $(parent).find(selector);
		opts = $.extend(this.grid.defaults, options);
		
		// make the grid
		make();	
	};
	
	// Makes the grid
	make = function()
	{
		var leftPos = 0;
		var topPos = 0;
		$(items).each(function()
		{
			// position this element
			$(this).css({
				position:'absolute',
				top:topPos + 'px',
				left:leftPos + 'px'
			});
			// calculate next position
			var c = $(this).width() + opts.gutter;
			leftPos += c;
			if(leftPos >= $(parent).width())
			{
				// we've gone too far to the right, start next row
				leftPos = 0;
				topPos += opts.col_height + opts.gutter;
			}
		});
		$(parent).css('height',topPos + 20);
	}
	
})(jQuery);

// defaults
jQuery.fn.grid.defaults = {
	gutter: 10,			// space between each item 
	col_width: 200, 	// the width of each grid block
	col_height: 200		// the height of each grid block
};

