(function($){

	$.fn.imgboxy=function(options){

		var img=$(this);
		
		img.click(function(){
		
			//getting document width and height
			var de=document.documentElement;
			var dw=(window.innerWidth || (de&&de.clientWidth) || document.body.clientWidth) - 30;
			var dh=(window.innerHeight || (de&&de.clientHeight) || document.body.clientHeight) - 30;
			
			//getting image's original width and height
			var iow=img.width(),ioh=img.height();
			img.removeAttr("width") .removeAttr("height") .css({width:"",height:""});
			
			//getting images free width and height
			iw=img.width();
			ih=img.height();
			img.css({width:iow,height:ioh});

			//calculating the size
			if(iw>dw){
				var width=dw;
				var height=Math.round(ih/(iw/dw));
			}
			if(ih>dh){
				var width=Math.round(iw/(ih/dh));
				var height=dh;
			}
			
			var dialog=new Boxy("<div></div>",{show:false,modal:true,center:true,clickToHide:true});
			dialog.setContent("<div><img src='"+img.attr('src')+"' style='width:"+width+"px;height:"+height+"px;' /></div>");
			dialog.show();
			dialog.center();
		});
		

	}
	
})(jQuery);
