/*
 *
 * 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()
{
	var	type	= 'img';
	var _self   = this;
	if( arguments[0] != undefined )
	{
		type	= arguments[0];
	}
	return this.wrap('<div class="thumb-img thumb-' + type + '"><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()
{
	
	var marginTop	= '50%';
	
	if( arguments[0] != undefined && arguments[0] == 'detail' )
	{
		marginTop	= '35%';
	}
	
	return this.each(
		function()
		{
			//$(this).css('position','absolute');
			//$(this).css( 'left', '-' + ( parseInt( $(this).width() ) / 2 ) + 'px' );
			//$(this).css( 'top', '-' + ( parseInt( $(this).height() ) / 2 ) + 'px' );
			//$(this).css('margin-left', '50%' );
			//$(this).css('margin-top', marginTop );
			//console.log($(this).width());
			if($(this).width() && $(this).height()){
				var style = '';
				style += 'position: absolute;';
				style += 'left:' + '-' + ( parseInt( $(this).width() ) / 2 ) + 'px;' ;
				style += 'top:' + '-' + ( parseInt( $(this).height() ) / 2 ) + 'px;' ;
				style += 'margin-left: 50%;';
				style += 'margin-top: '+ marginTop + ';';
				$(this).attr('style',style);
			}
			
		}
	)
	
}

