function initialize_map(ratings,map_type){if(GBrowserIsCompatible()){window.map=new GMap2(document.getElementById("map_canvas"));var map=window.map;var topRight=new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(10,10));map.addControl(new GSmallMapControl(),topRight);GoogleElectionMap.setCenter();function createMarker(state_data,map_type){var info_size=(map_type==1)?[350,200]:[200,75];var centroid=state_data[2];var bounds=state_data[4];var name=state_data[3];var state_abbr=state_data[0];var data_type=state_data[5];var marker=new GMarker(new GLatLng(centroid[1],centroid[0]),{"title":name});GEvent.addListener(marker,"infowindowopen",function(){if(map_type<2||map_type>3)
loadDataForBounds(state_abbr,data_type,bounds[0],bounds[1],name);else
loadDataForVoters(state_abbr,data_type,bounds[0],bounds[1],name);});GEvent.addListener(marker,"click",function(){var scroll_text=(info_size[1]>150)?'overflow-y:auto;':'';if(map_type<2||map_type>3)
marker.openInfoWindowHtml("<div id='info_window' style='margin-right:10px;"+scroll_text+"text-align:center;height:"+info_size[1]+"px;width:"+info_size[0]+"px;'><br/><img id='info_box_spinner' src='/images/icons/spinner.gif'/></div>");else
marker.openInfoWindowHtml("<div id='info_window' style='margin-right:10px;"+scroll_text+"text-align:center;height:"+info_size[1]+"px;width:"+info_size[0]+"px;'><br/><img id='info_box_spinner' src='/images/icons/spinner.gif'/></div>");});return marker;}
var mgr=new MarkerManager(map);var new_markers=[];var polygons=[];var use_counties=(map_type==1||map_type==3||map_type==5);if(use_counties)
polygons=getCountyPolygons(ratings);else
polygons=getStatePolygons(ratings);polygons.forEach(function(state_polygon,i){if(state_polygon[6])
new_markers.push(createMarker(state_polygon,map_type));map.addOverlay(state_polygon[1]);});mgr.addMarkers(new_markers,3);mgr.refresh();}}
function getCountyPolygons(ratings){var polygons=[];getStateList().forEach(function(state,i){state["shapes"].forEach(function(shape,j){polygons.push([state["state"],getPolygonFromArray(ratings[state["name"]],shape["points"]),state["centroid"],state["name"],state["bounds"],state["type"],(ratings[state["name"]]>0)]);});});return polygons;}
function getStatePolygons(ratings){var polygons=[];getStateList().forEach(function(state,i){state["shapes"].forEach(function(shape,j){polygons.push([state["state"],getPolygonFromArray(ratings[state["state"]],shape["points"]),state["centroid"],state["name"],state["bounds"],state["type"],(ratings[state["state"]]>0)]);});});return polygons;}
function getPolygonFromArray(rating,array_points){var rating_colors=['#000000','#fc2416','#fc2416','#ff4a1c','#ff6a20','#ff8c11','#ffb200','#ebcc00','#afca00','#74c900','#008300','#000000'];var points=[];array_points.forEach(function(point,i){points.push(new GLatLng(point[1],point[0]));});return new GPolygon(points,"#000000",1,.6,rating_colors[rating],.5);}
function getStateList(){return GoogleElectionMap.getPoints();}
function loadDataForVoters(state_abbr,data_type,bounds_a,bounds_b,county){new Ajax.Request('/welcome/get_data_for_voters?state_abbr='+state_abbr+'&county='+county+'&data_type='+data_type+'&bounds_a='+bounds_a+'&bounds_b='+bounds_b,{asynchronous:true,evalScripts:true});}
function loadDataForBounds(state_abbr,data_type,bounds_a,bounds_b,county){new Ajax.Request('/welcome/get_data_for_bounds?state_abbr='+state_abbr+'&county='+county+'&data_type='+data_type+'&bounds_a='+bounds_a+'&bounds_b='+bounds_b,{asynchronous:true,evalScripts:true});}