/*
 *
 * 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 (http://www.joanpiedra.com)
 * @example  $("a.thumb, img.thumb").thumbs();
 *
 */
jQuery.fn.thumbs = function()
{
	return this.wrap('<div class="thumb-img"><div class="thumb-inner">' + '</div><div class="thumb-strip"></div><div class="thumb-zoom"></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(width,height)
{
	i=0;
	return this.each(
		function()
		{
			//$(this).css('position','relative');
			//alert(this.width+'x'+this.height);
			//if ($(this).width() >= 150 || $(this).height() >= 150)
			
			//if (this.width > 100 || this.height > 100)
			if (this.height < height)
			{
				$('.thumb-img').css('height', height+'px' );
				$('.thumb-img').css('width', width+'px' );
			}
			/*
			else if (this.width > width)
			{
				$(this).css('width', width+'px' );
			}
			else
			{
			//$(this).css('width', '100px' );
			}
			*/
			
			//var cx = (this.width<=100) ? Math.floor( (100-this.width) / 2 ) : 0;
			//var cy = (this.height<=100) ? Math.floor( (100-this.height) / 2 ) : 0;

			var cx=0;
			var cy=0;
			//cx = (this.width<=width) ? Math.floor( (width-this.width) / 2 ) : 0;
			//cy = (this.height<=height) ? Math.floor( (height-this.height) / 2 ) : 0;
			//}

			cx = Math.floor( (width-this.width) / 2 );
			cy = Math.floor( (height-this.height) / 2 );

			//var cx = (1) ? Math.floor( (100-this.width) / 2 ) : 0;
			//var cy = (1) ? Math.floor( (100-this.height) / 2 ) : 0;


/*
			if (i<10)
			{
			alert("size: " + this.width + 'x' + this.height);
			alert("pos: " + cx + 'x' + cy);
			i++;
			}
*/


			//alert(Math.floor( (this.width) / 2 ) + 'x' + Math.floor( (this.height) / 2 ));

			$(this).css('left', cx + 'px' );
			$(this).css('top', cy + 'px' );
		}
	)
}
