/*
 * Original FigureHandler script (FigureHandler.js) implemented and described by Aaron Gustafson use prototype.js to work.
 * See http://code.google.com/p/easy-designs/wiki/FigureHandler
 * And this is my version of it called FigureHandlerJQ.js adopted to work on JQuery.
 * I try to preserve all the things of original script, including variables names and even comments.
 * One thing that I changed intentionally: element with ".figure" class must be "div". I think this is reasonably and in addition
 * script will work a little bit faster with this assumption. If you don't like it please erase "div" on 21st line.
 *					Igor Frolov (aka warmrobot) 
 * 					warmrobot@warmrobot.com
 */
$(window).load(function() {
	if( typeof( sizes ) !== 'object' ) {
	var sizes  = { '75-100': 'full-col',
	               '67-75':  'three-quarters-col',
	               '50-67':  'two-thirds-col',
	               '34-50':  'half-col',
	               '25-34':  'third-col',
	               '0-25':   'quarter-col'
			};
		}
	var selector = '.figure';
	if( typeof( id ) == 'string' ) {selector = '#' + id + 'div ' + selector;}
	//private metods
	$(selector).each(function() {
		// get the image width
		var img_width = $("img",this).width();
		// determine the relative sizing
      	var col_width = $(this).parent().width();
		var percent = Math.ceil(img_width/col_width*100);
		var range, col_class;
			for( var size in sizes ){
			range = size.split( '-' );
			if( percent > range[0] &&
			percent <= range[1] ){
				col_class = sizes[size];
				break;
			}
		}
		$(this).addClass(col_class);
		$("p",this).width(img_width);
	});
});