(function(a){function E(){c=jQuery("<div>",{id:"preview"}).appendTo("body").hide();a(window).unload(function(){c.remove()});z();var j=null;a(window).bind("scroll resize",function(){j&&clearTimeout(j);j=setTimeout(function(){z()},100)});A=true}function z(){if(jQuery.browser.msie){q=a(window).scrollLeft();h=a(window).scrollTop()}else{q=window.pageXOffset;h=window.pageYOffset}B=a(window).width();C=a(window).height()}var k=0,l=0,m=0,n=0,r=0,u=0,v=0,d=0,f=null,e=null,B=0,C=0,s=null,t=null,w=null,o=null,
p=0,g=0,q=0,h=0,x=true,A=false,c=null;a.fn.preview=function(j){function F(){s=b.content==null?o:a(o).find(b.content);e=null;t=a(s).find("img");if(t.length>0)if(b.useRelAsTargetImg)e=a(s).attr("rel");else{e=a(t).attr("src");if(b.findLinkImgString.length>0)e=e.replace(b.findLinkImgString,b.replaceLinkImgString)}b.maxPreviewWidth!=null?c.css("width",b.maxPreviewWidth):c.css("width","auto");if(e!=null){f=new Image;var i=null;if(b.captionAttr!=null)i=a(t).attr(b.captionAttr);a(f).load(function(){if(f!=
null){l=f.width+10;k=f.height+34;d=Math.round(k/2);r=b.xOffset+l-q;v=d-h;u=d+h;y();a(c).html('<img src="'+e+'" />'+(i==null?"":'<br /><span id="name">'+i+"</span>")).css({padding:2,top:n,left:m}).fadeIn("fast")}}).attr("src",e)}else{f=null;var D=s.html();a(c).html(D);b.header!=null&&a(c).prepend(a(o).children(b.header).clone());l=a(c).width()+20;if(b.maxPreviewWidth!=null)l=b.maxPreviewWidth+20;k=a(c).height()+20;d=Math.round(k/2);r=b.xOffset+l-q;v=d-h;u=d+h;y();D.length>5&&a(c).css({padding:8,top:n,
left:m}).fadeIn("fast")}}function G(){y();a(c).css({top:n,left:m})}function y(){if(b.checkBounds){m=p+r>B?p-r:p+b.xOffset;n=g+v>C?g-k:u>g?g:g-d}else{m=p+b.xOffset;n=g-d}}var b=a.extend({xOffset:40,showDelay:200,content:null,maxPreviewWidth:null,useRelAsTargetImg:false,header:null,findLinkImgString:"",replaceLinkImgString:"",checkBounds:true,captionAttr:"alt"},j);A==false&&E();a(this).hover(function(){o=a(this);x=false;a(o).attr("title","");clearTimeout(w);w=setTimeout(function(){F()},b.showDelay)},
function(){f=null;x=true;clearTimeout(w);a(c).hide()});a(this).bind("mousemove",function(i){p=i.pageX;g=i.pageY;x||G()})}})(jQuery);