﻿// Script data for map of breach notification laws
var centerLatitude = 39.810492;
var centerLongitude = -96.556061;
var startZoom = 4;

var map;

function addMarker(latitude, longitude, name, law, status, encrypt) {
    var marker = new GMarker(new GLatLng(latitude, longitude));
    GEvent.addListener(marker, 'click',
        function() {
            marker.openInfoWindowHtml("<h2>" + name + "</h2><div><span><strong>Breach Notification Law: </strong></span><span>" + law + "</span></div><div><span><strong>Status: </strong></span><span>" + status + "</span></div><div><span><strong>Safe harbor for encrypted data: </strong></span><span>" + encrypt + "</span></div>");
        }
    );
    map.addOverlay(marker);
}

function init() {
    if (GBrowserIsCompatible()) {	
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);

        for(id in markers) {
            addMarker(markers[id].latitude, markers[id].longitude, markers[id].name, markers[id].law, markers[id].status, markers[id].encrypt);
        }
    }
}
function findState(which) {
	if (which != 0) {
   		map.clearOverlays();
    	map.setCenter(new GLatLng(markers[which-1].latitude, markers[which-1].longitude), 6);
    	var marker = new GMarker(new GLatLng(markers[which-1].latitude, markers[which-1].longitude));
    	GEvent.addListener(marker, 'click',
        	function() {
            	marker.openInfoWindowHtml("<h2>" + markers[which-1].name + "</h2><div><span><strong>Breach Notification Law: </strong></span><span>" + markers[which-1].law + "</span></div><div><span><strong>Status: </strong></span><span>" + markers[which-1].status + "</span></div><div><span><strong>Safe harbor for encrypted data: </strong></span><span>" + markers[which-1].encrypt + "</span></div>");
        	}
    	);
    	map.addOverlay(marker);
    	marker.openInfoWindowHtml("<h2>" + markers[which-1].name + "</h2><div><span><strong>Breach Notification Law: </strong></span><span>" + markers[which-1].law + "</span></div><div><span><strong>Status: </strong></span><span>" + markers[which-1].status + "</span></div><div><span><strong>Safe harbor for encrypted data: </strong></span><span>" + markers[which-1].encrypt + "</span></div>");
    }
}

function resetMapToCenter() {
	map.clearOverlays();
	map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
	for(id in markers) {
    	addMarker(markers[id].latitude, markers[id].longitude, markers[id].name, markers[id].law, markers[id].encrypt);
    }
}

window.onload = init;
//window.onunload = GUnload(); Suppossed to prevent memory leaks