/*
 *
 * Copyright (c) 2006 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

/*
 * Converts image and link elements to thumbnails
 *
 * @name     jThumb
 * @author   Joan Piedra (httbp://www.joanpiedra.com)
 * @example  $("a.thumb, img.thumb").thumbs();
 *
 */
jQuery.fn.thumbs = function(height_val, width_val, padding_val, margin_val)
{	
   var style_txt = 'width:' + width_val + 'px; height:' + height_val + 'px; padding:' + padding_val + 'px; margin: ' + margin_val + 'px;'
	return this.wrap('<div class="thumb-img" style="' + style_txt + '"><div class="thumb-inner">' + '</div></div>');
}

/*
 * Absolute positions the image in the middle of the thumbnail frame
 *
 * @name     jThumbImg
 * @author   Joan Piedra (http://www.joanpiedra.com)
 * @example  $("a.thumb img, img.thumb").thumbsImg();
 *
 */
jQuery.fn.thumbsImg = function(height_val, width_val)
{
	return this.each(
		function()
		{
		   if ($(this).height() < $(this).width())
		   {
		      $(this).height(height_val);
		   }
		   else if ($(this).height() > $(this).width())
		   {
		      $(this).width(width_val);
		   }
		   else
		   {
		      $(this).height(height_val);
		      $(this).width(width_val);
		   }
			jQuery(this).css('position','absolute');
			jQuery(this).css('left', '-' + ( parseInt( $(this).width() ) / 2 ) + 'px' );
			jQuery(this).css('top', '-' + ( parseInt( $(this).height() ) / 2 ) + 'px' );
			jQuery(this).css('margin-left', '50%' );
			jQuery(this).css('margin-top', '50%' );
		}
	)
}

