/*
 *
 * Copyright (c) 2010 Luis Escobar Bravo (http://www.nambrena.com)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

/*
 * Clips image automatically
 *
 * @name     jquery.thumbClipper.js
 * @author   Luis Escobar Bravo (http://www.nambrena.com)
 * @example  $("img.thumb").thumbClipper(x,y,width,height);
 *
 */
jQuery.fn.thumbClipper = function()
{
	return this.each(
			function()
			{
				jQuery(this).wrap('<div style="position:relative; width:110px; height:83px;"></div>');
				var height = parseInt( $(this).height());
				var width = parseInt( $(this).width());
				if(height>83){
					var top = parseInt((height - 83) / 2);
				}else{
					var top = 0;
				}
				var top = 0;
				var bottom = top + 83;
				if(width>110){
					var left = parseInt((width - 110) / 2);
				}else{
					var left = 0;
				}
				var right = left + 110;
				jQuery(this).css('position', 'absolute');
				jQuery(this).css('clip', 'rect('+top+'px,'+right+'px,'+bottom+'px,'+left+'px)');
			}
		)
}