var statedata = new Array(); var hazdata = false; var statecolor = new Array(); var statepalette = new Array("#EACF98","#839417","#F06A27","#788979"); var overbox = false; var oversomething = false; var statetimeout = new Array(); $(document).ready(function (){ $.ajax({ url: 'states.json', dataType: 'json', success: function (data) { for(var it in data){ statedata[data[it].geo.cached_slug] = data[it].geo; if(data[it].geo.coroner_system == "none" && data[it].geo.medical_examiner_system == "state"){ statecolor[data[it].geo.cached_slug] = 0; } if(data[it].geo.coroner_system == "county" && data[it].geo.medical_examiner_system == "none"){ statecolor[data[it].geo.cached_slug] = 1; } if(data[it].geo.coroner_system == "district" && data[it].geo.medical_examiner_system == "none"){ statecolor[data[it].geo.cached_slug] = 1; } if(data[it].geo.coroner_system == "none" && data[it].geo.medical_examiner_system == "county"){ statecolor[data[it].geo.cached_slug] = 2; } if(data[it].geo.coroner_system == "county" && data[it].geo.medical_examiner_system == "state"){ statecolor[data[it].geo.cached_slug] = 3; } if(data[it].geo.coroner_system == "sometimes" && data[it].geo.medical_examiner_system == "sometimes"){ statecolor[data[it].geo.cached_slug] = 3; } if(data[it].geo.coroner_system == "county" && data[it].geo.medical_examiner_system == "county_state"){ statecolor[data[it].geo.cached_slug] = 3; } if(data[it].geo.coroner_system == "sometimes_justices" && data[it].geo.medical_examiner_system == "sometimes"){ statecolor[data[it].geo.cached_slug] = 2; } if(data[it].geo.coroner_system == "none" && data[it].geo.medical_examiner_system == "county_state"){ statecolor[data[it].geo.cached_slug] = 2; } if(data[it].geo.coroner_system == "none" && data[it].geo.medical_examiner_system == "county_state"){ statecolor[data[it].geo.cached_slug] = 2; } if(data[it].geo.coroner_system == "none" && data[it].geo.medical_examiner_system == "district"){ statecolor[data[it].geo.cached_slug] = 2; } } hazdata = true; drawmap('initial'); }, error: function (req, something, whatever) { $("#container").html(something); } }); }); function drawmap (caller) { $("#mapcontainer").html(''); var mywidth = $("#mapcontainer").width(); var myheight = 710; var ratio = 1; if(mywidth != 980){ ratio = mywidth / 980; myheight = Math.floor(mywidth * .8); $("#mapcontainer").css({ 'height': myheight + 'px' }); } var R = Raphael("mapcontainer", mywidth, myheight), attr = { "fill": "#d3d3d3", "stroke": "#fff", "stroke-opacity": ".5", "stroke-linejoin": "round", "stroke-miterlimit": "4", "stroke-width": "0.75", "stroke-dasharray": "none" }, usRaphael = {}; for (var state in usmap) { usRaphael[state] = R.path(usmap[state]).attr(attr); if(ratio != 1){ usRaphael[state].scale(ratio,ratio,0,0); } usRaphael[state].attr({fill: statepalette[statecolor[state]]}); } for (var state in usRaphael) { (function (st, state) { st[0].style.cursor = "pointer"; $(st[0]).mouseover(function (e) { st.animate({fill: '#ED1B24'}, 300); // st.toFront(); boxon(e.pageX,e.pageY,state) R.safari(); oversomething = true; clearTimeout(statetimeout[state]); }); $(st[0]).mouseout(function () { oversomething = false; statetimeout[state] = setTimeout(function () { st.animate({fill: statepalette[statecolor[state]]}, 300); if(!oversomething) { boxoff(); } // st.toFront(); R.safari(); }, 200); }); })(usRaphael[state], state); } } function boxon (x,y,statecode){ var txt = '

' + usmap_longnames[statecode] + '

'; var dat = statedata[statecode]; if(dat){ txt += ''; } $("#mapover").html(txt); boxdetermine(x,y); $("#mapover").show(); overbox = true; } function unobfuscate (txtin){ txtin = txtin.replace(/_/g,' '); var txtout = txtin.charAt(0).toUpperCase() + txtin.slice(1); if(txtout == 'County state'){ txtout = "County & state"; } return txtout; } function boxdetermine (x,y){ var defx = x - 245; var defy = y - 285; var img = 'mapcommentlr.png'; var paddingstr = '20px 30px 18px 30px'; if(defy < 350){ defy = y + 10; img = 'mapcommentur.png'; paddingstr = '45px 30px 18px 30px'; if(defx < 10){ img = 'mapcommentul.png'; defx += 190; } } else { if(defx < 200){ img = 'mapcommentll.png'; defx += 190; } } $("#mapover").css({ 'top': defy + 'px', 'left': defx + 'px', 'background-image':'url(../art/'+img+')', 'background-repeat':'no-repeat', 'padding': paddingstr }); } function numfmt (nStr) { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } function boxoff() { $("#mapover").hide(); $("#mapover").unbind('mouseenter'); $("#mapover").unbind('mouseleave'); overbox = false; } $(document).mousemove(function(e){ if(overbox){ boxdetermine(e.pageX,e.pageY); } });