(function($) {

	MAX_THUMB_WIDTH = 76;
	MAX_THUMB_HEIGHT = 76;
	$.fn.thumbcar = function() {

		// build main options before element iteration
		var opts = $.extend({}, $.fn.thumbcar.defaults);		
		
		function bind() {
			displayThumbnailsPhoto();
		};

		function _isIE()
		{
			return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;
		}


		function displayThumbnailsPhoto()
		{
			var __isIE = _isIE();

			if (__isIE == -1 || __isIE != 6)
			{

				$(opts.divParent).find('img').attr('src');

			$(opts.divParent).hide();

				var thumbPhotoSrc = $(opts.divParent).find('img').attr('src');

				newThumbPhotoWidth = MAX_THUMB_WIDTH;
				newThumbPhotoHeight = MAX_THUMB_HEIGHT;

				$dt = $(opts.divParent);
				$dt.find("img").replaceWith('');
				

				var img = new Image();

				var $img = $(img)

					.load(function () {						

						thumbPhotoWidth = this.width;
						thumbPhotoHeight = this.height;

						$(this).hide();

						$(this).addClass('jcarousel-item_img');

						

						if (thumbPhotoWidth == thumbPhotoHeight)
						{							
							newThumbPhotoWidth = MAX_THUMB_WIDTH;
							newThumbPhotoHeight = MAX_THUMB_HEIGHT;

							newThumbMarginTop = 10;
							newThumbMarginLeft = 10;
						}

						if (thumbPhotoWidth < thumbPhotoHeight)
						{
							ratio = thumbPhotoWidth / thumbPhotoHeight;

							newThumbPhotoHeight = MAX_THUMB_HEIGHT;
							newThumbPhotoWidth = newThumbPhotoHeight * ratio;

							newThumbMarginLeft = (MAX_THUMB_WIDTH - Math.round(newThumbPhotoWidth)) /2 + 10;
							newThumbMarginTop = 10;
						}

						if (thumbPhotoHeight < thumbPhotoWidth)
						{
							ratio = thumbPhotoHeight / thumbPhotoWidth;

							newThumbPhotoWidth = MAX_THUMB_WIDTH;
							newThumbPhotoHeight = newThumbPhotoWidth * ratio;

							newThumbMarginTop = (MAX_THUMB_HEIGHT - Math.round(newThumbPhotoHeight)) /2 +10;
							newThumbMarginLeft = 10;
						}						

						$(this).css({
							width: Math.round(newThumbPhotoWidth) + 'px',
							height: Math.round(newThumbPhotoHeight) + 'px',
							marginLeft: Math.round(newThumbMarginLeft) + 'px',
							marginTop: Math.round(newThumbMarginTop) + 'px'
						})
						.width( Math.round(newThumbPhotoWidth) )
						.height( Math.round(newThumbPhotoHeight) )
						.fadeIn();
					})
					.attr({
						src: thumbPhotoSrc,
						oncontextmenu: 'return false'
					});

					$(opts.divParent).prepend($img);

				$(opts.divParent).fadeIn();
			}
		}

		
		
		// iterate each matched element
		return this.each(function() {
			bind();
		});
	};
	//
	// plugin defaults
	//
	$.fn.thumbcar.defaults = {

		divParent   : '#clonetmp'
	};

})(jQuery);