(function(n){var a,t,f,r,e,o,s,h,c,y,l,u,v;if(t=!!document.createElement("canvas").getContext,a=function(){var t=document.createElement("div"),n;return t.innerHTML='<v:shape id="vml_flag1" adj="1" />',n=t.firstChild,n.style.behavior="url(#default#VML)",n?typeof n.adj=="object":!0}(),!(t||a)){n.fn.maphilight=function(){return this};return}t?(h=function(n){return Math.max(0,Math.min(parseInt(n,16),255))},c=function(n,t){return"rgba("+h(n.substr(0,2))+","+h(n.substr(2,2))+","+h(n.substr(4,2))+","+t+")"},f=function(t){var i=n('<canvas style="width:'+t.width+"px;height:"+t.height+'px;"><\/canvas>').get(0);return i.getContext("2d").clearRect(0,0,i.width,i.height),i},u=function(n,t,r,u,f){if(u=u||0,f=f||0,n.beginPath(),t=="rect")n.rect(r[0]+u,r[1]+f,r[2]-r[0],r[3]-r[1]);else if(t=="poly")for(n.moveTo(r[0]+u,r[1]+f),i=2;i<r.length;i+=2)n.lineTo(r[i]+u,r[i+1]+f);else t=="circ"&&n.arc(r[0]+u,r[1]+f,r[2],0,Math.PI*2,!1);n.closePath()},r=function(t,i,r,f){var e=t.getContext("2d"),s,h,o;f.shadow&&(e.save(),f.shadowPosition=="inside"&&(u(e,i,r),e.clip()),s=t.width*100,h=t.height*100,u(e,i,r,s,h),e.shadowOffsetX=f.shadowX-s,e.shadowOffsetY=f.shadowY-h,e.shadowBlur=f.shadowRadius,e.shadowColor=c(f.shadowColor,f.shadowOpacity),o=f.shadowFrom,o||(o=f.shadowPosition=="outside"?"fill":"stroke"),o=="stroke"?(e.strokeStyle="rgba(0,0,0,1)",e.stroke()):o=="fill"&&(e.fillStyle="rgba(0,0,0,1)",e.fill()),e.restore(),f.shadowPosition=="outside"&&(e.save(),u(e,i,r),e.globalCompositeOperation="destination-out",e.fillStyle="rgba(0,0,0,1);",e.fill(),e.restore()));e.save();u(e,i,r);f.fill&&(e.fillStyle=c(f.fillColor,f.fillOpacity),e.fill());f.stroke&&(e.strokeStyle=c(f.strokeColor,f.strokeOpacity),e.lineWidth=f.strokeWidth,e.stroke());e.restore();f.fade&&n(t).css("opacity",0).animate({opacity:1},100)},e=function(n){n.getContext("2d").clearRect(0,0,n.width,n.height)}):(f=function(t){return n('<var style="zoom:1;overflow:hidden;display:block;width:'+t.width+"px;height:"+t.height+'px;"><\/var>').get(0)},r=function(t,i,r,u,f){var s,o,h,e;for(var c in r)r[c]=parseInt(r[c],10);s='<v:fill color="#'+u.fillColor+'" opacity="'+(u.fill?u.fillOpacity:0)+'" />';o=u.stroke?'strokeweight="'+u.strokeWidth+'" stroked="t" strokecolor="#'+u.strokeColor+'"':'stroked="f"';h='<v:stroke opacity="'+u.strokeOpacity+'"/>';i=="rect"?e=n('<v:rect name="'+f+'" filled="t" '+o+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+r[0]+"px;top:"+r[1]+"px;width:"+(r[2]-r[0])+"px;height:"+(r[3]-r[1])+'px;"><\/v:rect>'):i=="poly"?e=n('<v:shape name="'+f+'" filled="t" '+o+' coordorigin="0,0" coordsize="'+t.width+","+t.height+'" path="m '+r[0]+","+r[1]+" l "+r.join(",")+' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:'+t.width+"px;height:"+t.height+'px;"><\/v:shape>'):i=="circ"&&(e=n('<v:oval name="'+f+'" filled="t" '+o+' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:'+(r[0]-r[2])+"px;top:"+(r[1]-r[2])+"px;width:"+r[2]*2+"px;height:"+r[2]*2+'px;"><\/v:oval>'));e.get(0).innerHTML=s+h;n(t).append(e)},e=function(t){var i=n("<div>"+t.innerHTML+"<\/div>");i.children("[name=highlighted]").remove();t.innerHTML=i.html()});o=function(n){for(var i=n.getAttribute("coords").split(","),t=0;t<i.length;t++)i[t]=parseFloat(i[t]);return[n.getAttribute("shape").toLowerCase().substr(0,4),i]};l=function(t,i){var r=n(t);return n.extend({},i,n.metadata?r.metadata():!1,r.data("maphilight"))};y=function(n){return n.complete?typeof n.naturalWidth!="undefined"&&n.naturalWidth===0?!1:!0:!1};s={position:"absolute",left:0,top:0,padding:0,border:0};v=!1;n.fn.maphilight=function(i){return i=n.extend({},n.fn.maphilight.defaults,i),t||v||(n(window).ready(function(){document.namespaces.add("v","urn:schemas-microsoft-com:vml");var t=document.createStyleSheet();n.each(["shape","rect","oval","circ","fill","stroke","imagedata","group","textbox"],function(){t.addRule("v\\:"+this,"behavior: url(#default#VML); antialias:true")})}),v=!0),this.each(function(){var u,w,p,v,h,c,d,b,k;if(u=n(this),!y(this))return window.setTimeout(function(){u.maphilight(i)},200);(p=n.extend({},i,n.metadata?u.metadata():!1,u.data("maphilight")),b=u.get(0).getAttribute("usemap"),b)&&(v=n('map[name="'+b.substr(1)+'"]'),u.is('img,input[type="image"]')&&b&&v.size()>0)&&(u.hasClass("maphilighted")&&(k=u.parent(),u.insertBefore(k),k.remove(),n(v).unbind(".maphilight").find("area[coords]").unbind(".maphilight")),w=n("<div><\/div>").css({display:"block",background:'url("'+this.src+'")',position:"relative",padding:0,width:this.width,height:this.height}),p.wrapClass&&(p.wrapClass===!0?w.addClass(n(this).attr("class")):w.addClass(p.wrapClass)),u.before(w).css("opacity",0).css(s).remove(),a&&u.css("filter","Alpha(opacity=0)"),w.append(u),h=f(this),n(h).css(s),h.height=this.height,h.width=this.width,d=function(){var u,i,f,e;i=l(this,p);i.neverOn||i.alwaysOn||(u=o(this),r(h,u[0],u[1],i,"highlighted"),i.groupBy&&(f=/^[a-zA-Z][\-a-zA-Z]+$/.test(i.groupBy)?v.find("area["+i.groupBy+'="'+n(this).attr(i.groupBy)+'"]'):v.find(i.groupBy),e=this,f.each(function(){var n,t;this!=e&&(n=l(this,p),n.neverOn||n.alwaysOn||(t=o(this),r(h,t[0],t[1],n,"highlighted")))})),t||n(h).append("<v:rect><\/v:rect>"))},n(v).bind("alwaysOn.maphilight",function(){c&&e(c);t||n(h).empty();n(v).find("area[coords]").each(function(){var e,i;i=l(this,p);i.alwaysOn&&(!c&&t&&(c=f(u[0]),n(c).css(s),c.width=u[0].width,c.height=u[0].height,u.before(c)),i.fade=i.alwaysOnFade,e=o(this),t?r(c,e[0],e[1],i,""):r(h,e[0],e[1],i,""))})}),n(v).trigger("alwaysOn.maphilight").find("area[coords]").bind("mouseover.maphilight",d).bind("mouseout.maphilight",function(){e(h)}),u.before(h),u.addClass("maphilighted"))})};n.fn.maphilight.defaults={fill:!0,fillColor:"000000",fillOpacity:.2,stroke:!0,strokeColor:"ff0000",strokeOpacity:1,strokeWidth:1,fade:!0,alwaysOn:!1,neverOn:!1,groupBy:!1,wrapClass:!0,shadow:!1,shadowX:0,shadowY:0,shadowRadius:6,shadowColor:"000000",shadowOpacity:.8,shadowPosition:"outside",shadowFrom:!1}})(jQuery)