(function($){
	$.fn.imagePreview = function(config){
		var defaults = {
				display : 'show',
				showDelay : 0,
				fadeInDelay : 300, 
				bgiframe : false,
				topDiff : 13,
				leftDiff : 13
		};
		var options = $.extend(defaults, config);
		$('a.imagePreview').hover(function(e){	
			var img = $('img', this);
			var imgTop = img.position().top;
			var imgLeft = img.position().left;
			
			this.t = this.title;
			this.title = '';
			var caption = (this.t != '') ? '<br />' + this.t : '';
			
			//摜ǂ
			//$('<img>').attr('src', this.href);
			
			$('body').append('<p id="imagePreview"><img src="' + this.href + '" alt="' + img.attr('alt') + '" />' + caption + "</p>");
			//hide once
			$('#imagePreview').hide();
			//detect IE6
			if (typeof document.documentElement.style.maxHeight == 'undefined'){
				//hide <select /> for IE6
				if(options.bgiframe == true){
					//appply bgiframe
					$('#imagePreview').bgiframe();
				}
			}
			var imagePreview = $('#imagePreview')
				.css('top', (imgTop - $('#imagePreview').height() - options.topDiff) + 'px')
				.css('left', (imgLeft - $('#imagePreview').width() - options.leftDiff) + 'px');
			
			switch(options.display){
				case 'show':
					imagePreview.show(options.showDelay);
					break;
				case 'fadeIn':
					imagePreview.fadeIn(options.fadeInDelay);
					break;
			}
	    },
		function(){
			//$('#imagePreview').hide();
			this.title = this.t;
			$('#imagePreview').remove();
	    });	
    };
})(jQuery);


