var map;
//<![CDATA[
function load() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        var latlngInit = new GLatLng(35.548163, -97.43019);
        map.setCenter(latlngInit, 7);
        map.setUIToDefault();
        
        //Create icon
        var icon = new GIcon();
        icon.image = "http://s3.amazonaws.com/content.newsok.com/newsok/images/ongoing/superfund/icon_active_superfund.gif";
        icon.iconSize = new GSize(21, 25);
        icon.iconAnchor = new GPoint(11, 25);

        // Function to make windows for each marker
        function createMarker(point, number, name, info, location, city, added, cleanup, removed, waste, status, payment, cost, photo, photos, PDF, articleTitle1, articleId1, articleTitle2, articleId2, articleTitle3, articleId3) {
            // Make content Tabs for each marker
            if (photo == "" || photo == null || photo == "N/A") {
                var photoDisplay        = "<img width='100%' src='http://s3.amazonaws.com/content.newsok.com/newsok/images/image_not_avail.gif' />";
            } else {
                var photoDisplay        = "<img width='100%' src='" + photo + "' />";
            }
            if (photos) {
                var galleryPhotos       = new Array();
                galleryPhotos           = photos.split(',');
                var i                   = 0; 
                for (i in galleryPhotos) {
                    photoDisplay += "<a href='javascript:void(0);' onclick='tb_show(\" \", \"http://newsok.com/multimedia/gallery/500842/31/" + galleryPhotos[i] + "?KeepThis=true&custom_click=multimedia_gallery&TB_iframe=true&height=610&width=820\", \"\")'><img width='50' class='thumbs' src='http://photos.newsok.com/2/showimage/" + galleryPhotos[i] + "/sq60/' /></a>";
                }
            }
            var locationDisplay          = "<b>Location:</b> " + location;
            var addressPreviewDisplay       = name;
            var cityDisplay          = "<b>City:</b> " + city;
            var nameDisplay          = "<b>Name:</b> " + name;
            var addedDisplay         = "<b>Added to list:</b> " + added;
            if (cleanup) {
                var cleanupDisplay       = "<b>Cleanup completed:</b> " + cleanup;
            } else {
                var cleanupDisplay      = "";
            }
            var removedDisplay       = "<b>Removed from list:</b> " + removed;
            var infoDisplay          = "<b>Site overview:</b> " + info;
            var wasteDisplay         = "<b>Waste:</b> " + waste;
            if (payment) {
                var paymentDisplay       = "<b>Payment:</b> " + payment;            
            } else {
                var paymentDisplay      = "";
            }
            if (cost) {
                var costDisplay         = "<b>EPA Cost:</b> $" + cost;
            } else {
                var costDisplay         = "";   
            }
            if (articleId1) {
                var articleDisplay1     = "<a target='_blank' href='http://newsok.com/article/" + articleId1 + "'>" + articleTitle1 + "</a>";
            } else {
                var articleDisplay1     = "";
            }
            if (articleId2) {
                var articleDisplay2     = "<a target='_blank' href='http://newsok.com/article/" + articleId2 + "'>" + articleTitle2 + "</a>";
            } else {
                var articleDisplay2     = "";
            }
            if (articleId3) {
                var articleDisplay3     = "<a target='_blank' href='http://newsok.com/article/" + articleId3 + "'>" + articleTitle3 + "</a>";
            } else {
                var articleDisplay3     = "";
            }
			if (status) {
				var statusDisplay = "<b>Status:</b> " + status;
			} else {
				var statusDisplay = "";
			}
            if (PDF) {
                var PDFDisplay          = "<b>PDF Download</b>: <a target='_blank' href='http://s3.amazonaws.com/content.newsok.com/newsok/images/superfund/" + PDF + "'> EPA Cost Summary</a>";
            } else {
                var PDFDisplay = "";
            }
            var marker = new GMarker(point, icon);
            GEvent.addListener(marker, "mouseover", function() {
                marker.setImage("http://s3.amazonaws.com/content.newsok.com/newsok/images/ongoing/superfund/icon_active_over_superfund.gif");
                showBubble(this, addressPreviewDisplay);
            });
            GEvent.addListener(marker, "mouseout", function() {
                marker.setImage("http://s3.amazonaws.com/content.newsok.com/newsok/images/ongoing/superfund/icon_active_superfund.gif");
                hideBubble();
            });
            GEvent.addListener(marker, "click", function() {
                document.getElementById("introText").style.display      = "none";
                document.getElementById("siteInfo").style.display       = "block";
                document.getElementById("whiteBox").style.background    = "#B4CCE6";
                document.getElementById("name").innerHTML               = nameDisplay;
                document.getElementById("location").innerHTML           = locationDisplay;
                document.getElementById("city").innerHTML               = cityDisplay;
                document.getElementById("added").innerHTML              = addedDisplay;
                document.getElementById("cleanup").innerHTML           = cleanupDisplay;
                document.getElementById("removed").innerHTML           = removedDisplay;
                document.getElementById("waste").innerHTML             = wasteDisplay;
                document.getElementById("status").innerHTML            = statusDisplay;
                document.getElementById("payment").innerHTML           = paymentDisplay;
                document.getElementById("PDF").innerHTML               = PDFDisplay;
                document.getElementById("cost").innerHTML               = costDisplay;
                document.getElementById("photo").innerHTML              = photoDisplay;
                document.getElementById("article").innerHTML            = articleDisplay1 + articleDisplay2 + articleDisplay3;
                document.getElementById("photo").innerHTML              = photoDisplay;
                document.getElementById("info").innerHTML               = infoDisplay;
                if (info == "") {
                    document.getElementById("info").style.display = "none";
                } else {
                    document.getElementById("info").style.display = "";
                }                              
                if (articleDisplay1 == "") {
                    document.getElementById("relArticles").style.display = "none";
                } else {
                document.getElementById("relArticles").style.display = "";
                }
                if (PDF == "") {
                    document.getElementById("PDF").style.display = "none";
                } else {
                    document.getElementById("PDF").style.display = "";
                }
            });
            return marker;
        }

        //add XML
        GDownloadUrl("/xml_block/superfund", function(data, responseCode) {
            var xml = GXml.parse(data);
            var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
                var name        = (markers[i].getAttribute("name"));
                var info            = (markers[i].getAttribute("info"));
                var location     = (markers[i].getAttribute("location"));
                var city        = (markers[i].getAttribute("city"));                
                var added       = (markers[i].getAttribute("added"));
                var cleanup     = (markers[i].getAttribute("cleanup"));
                var removed     = (markers[i].getAttribute("removed"));
                var waste       = (markers[i].getAttribute("waste"));
                var status      = (markers[i].getAttribute("status"));
                var payment     = (markers[i].getAttribute("payment"));
                var cost        = (markers[i].getAttribute("cost"));
                var photo       = (markers[i].getAttribute("photo"));
                var photos      = (markers[i].getAttribute("photos"));
                var PDF         = (markers[i].getAttribute("PDF"));
                var articleTitle1   = (markers[i].getAttribute("articleTitle1"));
                var articleId1      = (markers[i].getAttribute("articleId1"));
                var articleTitle2   = (markers[i].getAttribute("articleTitle2"));
                var articleId2      = (markers[i].getAttribute("articleId2"));
                var articleTitle3   = (markers[i].getAttribute("articleTitle3"));
                var articleId3      = (markers[i].getAttribute("articleId3"));
                var point           = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
                map.addOverlay(createMarker(point, markers[i], name, info, location, city, added, cleanup, removed, waste, status, payment, cost, photo, photos, PDF, articleTitle1, articleId1, articleTitle2, articleId2, articleTitle3, articleId3));
            }
        });
    }
    // setup the trackers w/ options
    opt1 = { color: '#FCB03E', weight: 10, length: 15, padding: 15};

    area1 = new GMarker(new GLatLng(35.466682, -97.483234), icon);
    var mt2 = new MarkerTracker(area1, map, opt1);

    area2 = new GMarker(new GLatLng(35.471389,-97.472692), icon);
    var mt3 = new MarkerTracker(area2, map, opt1);

    area3 = new GMarker(new GLatLng(36.132718,-96.075768), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);
    
    area4 = new GMarker(new GLatLng(35.478654,-97.454377), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);
    
    area5 = new GMarker(new GLatLng(36.13898378070337,-96.0702896118164), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);  

    area6 = new GMarker(new GLatLng(34.202772,-97.600187), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);

    area7 = new GMarker(new GLatLng(35.41780352881925,-97.38701820373535), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);

    area8 = new GMarker(new GLatLng(35.504421887918404,-97.41456985473633), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);

    area9 = new GMarker(new GLatLng(35.985054,-96.766844), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);

    area10 = new GMarker(new GLatLng(34.89135204367092,-98.19399833679199), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);

    area11 = new GMarker(new GLatLng(34.89135204367092,-98.19399833679199), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);

    area12 = new GMarker(new GLatLng(36.29299,-95.836166), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);

    area13 = new GMarker(new GLatLng(36.7409475605088,-96.00169029235839), icon);
    var mt1 = new MarkerTracker(area3, map, opt1);  

}
function moveMap(id) {
    if (document.mapToggle.mapView.selectedIndex == "0") {
        map.setCenter(new GLatLng(35.248163, -97.43019), 7);
    }
    if (document.mapToggle.mapView.selectedIndex == "1") {
        map.setCenter(new GLatLng(35.466682, -97.483234), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "2") {
        map.setCenter(new GLatLng(35.471389,-97.472692), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "3") {
        map.setCenter(new GLatLng(36.132718,-96.075768), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "4") {
        map.setCenter(new GLatLng(35.478654,-97.454377), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "5") {
        map.setCenter(new GLatLng(36.13898378070337,-96.0702896118164), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "6") {
        map.setCenter(new GLatLng(34.202772,-97.130425), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "7") {
        map.setCenter(new GLatLng(34.971568,-97.600187), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "8") {
        map.setCenter(new GLatLng(35.41780352881925,-97.38701820373535), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "9") {
        map.setCenter(new GLatLng(35.504421887918404,-97.41456985473633), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "10") {
        map.setCenter(new GLatLng(35.985054,-96.766844), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "11") {
        map.setCenter(new GLatLng(34.89149284677313, -98.19588661193848), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "12") {
        map.setCenter(new GLatLng(36.955927695021366,-94.85733032226562), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "13") {
        map.setCenter(new GLatLng(36.29299,-95.836166), 20);
    }
    if (document.mapToggle.mapView.selectedIndex == "14") {
        map.setCenter(new GLatLng(36.7409475605088,-96.00169029235839), 20);
    }
    
}

var showBubble = function(marker, addressPreviewDisplay) {
    jQuery("#infoWindow").appendTo(map.getPane(G_MAP_FLOAT_SHADOW_PANE));
    //map.panTo(marker.getPoint());
    var markerOffset = map.fromLatLngToDivPixel(marker.getPoint());
    jQuery("#infoWindow").html(addressPreviewDisplay);
    jQuery("#infoWindow").show().css({ top:markerOffset.y - 60, left:markerOffset.x + 11});
};
var hideBubble = function() {
    var bubble = jQuery('#infoWindow');
    jQuery(bubble).hide();
};
//]]>