(function($) {
	$.fn.imgpreview = function(options){
		// default settings
		var settings = {
			marginLeft : 10,
			identifier : 'imgpreview',
			height : 200,
			width : 200,
			titleSource : 'title',
			imgSource : 'href',
			bgColor : '#333',	// background color for title
			color : '#fff',		// font color for title
			borderColor : '#333',	// border color
			size : '0.8em'			// font size for title
		};
		//extending options
		options = options || {};
	   	$.extend(settings, options);

		this.each(function(i){
			var title = $(this).attr(settings.titleSource);
			var imgBig = $(this).attr(settings.imgSource);
			var titleAttribute = $(this).attr("title");

			$(this).mouseenter(function(e){
				// removing zoom container if exists to avoid duplicates
				$('#'+settings.identifier).remove();
				// removing title to prevent default tooltip
				$(this).attr("title","");

				var x = e.pageX + 30;
				var y = e.pageY - (settings.height / 2);

				$('body').append('<div id="'+settings.identifier+'" style="z-index: 9999;border:1px solid '+settings.borderColor+'; position:absolute; top:'+y+'px;left:'+x+'px;width:'+settings.width+'px;"><div style="background-color:'+settings.bgColor+';color:'+settings.color+';font-size:'+settings.size+';line-height:1.2;padding: 5px;">'+title+'</div><div style="width:'+settings.width+'px;height:'+settings.height+'px;overflow:hidden;position:relative;"><img id="'+settings.identifier+'_img" src="'+imgBig+'" style="position:relative;"></div></div>');
			}).mouseleave(function(){
				// removing zoom container
				$('#'+settings.identifier).remove();
				// setting title back
				$(this).attr("title",titleAttribute);
			});
		});

		return this;
	};
})(jQuery);
