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