$.fn.imageResize = function(options) {  
	var defaults = {  
		maxWidth:300,
		lightBox:true,
		delay:0
	};  
	var options = $.extend(defaults, options);   
	return this.each(function() {  		
		if ($(this).is("img")){
			var run = $(this);
		}else{
			var run = $(this).find("img");
		}	
		setTimeout(function () {  
			run.each(function(){
				var image = $(this);
				var maxWidth = options.maxWidth;
				var width = image.width();
				var height = image.height();
				if(width > maxWidth){
					var ratio = height/width;
					var newWidth = maxWidth;
					var newHeight = newWidth*ratio;
					image.attr("width",newWidth);
					image.attr("height",newHeight);
				}else{
					var newWidth = image.width();
					var newHeight = image.height();
				}
				if(options.lightBox == true){
					var src = image.attr("src");				
					image.wrap("<a class='imageHolder lightBox' href="+ src +"></a>");
					var holderCss = {
						"width": newWidth,
						"height": newHeight,
						"position":"relative",
						"display":"block"
					}
					image.parents(".imageHolder").css(holderCss);
					image.before("<div class ='mag'></div>");
					var magCss = {
						"position":"absolute",
						"top":"0px",
						"right":"0px"
					}				
					$(".mag").css(magCss);	
					$("body a.lightBox").lightBox();				
				}
			});	
		}, options.delay);
	});  
};