﻿var _map;
var _latitudeCenter, _longitudeCenter;
var _saddr = '';

 function initGMap(swLat, swLng, neLat, neLng) {
  if (GBrowserIsCompatible()) {
    _map = new GMap2(document.getElementById("divMap"));
    _map.addControl(new GLargeMapControl ());
    
    var bounds = new GLatLngBounds(new GLatLng(swLat - .06, swLng - .02), new GLatLng(neLat + .06, neLng + .02));
    var zoom = _map.getBoundsZoomLevel(bounds);
    
	var center = new GLatLng((swLat + neLat)/2, (swLng + neLng)/2);
	_map.setCenter(center, zoom);
	
  }
}

function initGMap1(swLat, swLng, neLat, neLng, latCenter, lngCenter) {
  if (GBrowserIsCompatible()) {
    _map = new GMap2(document.getElementById("divMap"));
    _map.addControl(new GLargeMapControl ());
    
    var bounds = new GLatLngBounds(new GLatLng(swLat - .06, swLng - .02), new GLatLng(neLat + .06, neLng + .02));
    var zoom = _map.getBoundsZoomLevel(bounds); 
    
    // when we force the _map to get centered on latCenter/lngCenter, some clinics may move off the viewport, so we decrese zoom --
    zoom = zoom - 1; 
    
	var center = new GLatLng(latCenter, lngCenter);
	_map.setCenter(center, zoom);
	
	_latitudeCenter = latCenter;
	_longitudeCenter = lngCenter;
  }
}

 function initGMap2(lat, lng, zoom) {
  if (GBrowserIsCompatible()) {
    _map = new GMap2(document.getElementById("divMap"));
    _map.addControl(new GLargeMapControl ());
	var center = new GLatLng(lat,lng);
	_map.setCenter(center, zoom);
	bounds = new GLatLngBounds();
  }
}

function centerGmap()
{
    try
    {
        _map.setCenter(new GLatLng(_latitudeCenter, _longitudeCenter));
    }
    catch (e)
    {
    }
}

var _clinicMarkers = new Array();
function addClinicMarker(markerTitle, lat, lng, address, locationType, daddr, key, more_url, isNew, seasonalFluVaccineAvailability, h1n1FluVaccineAvailability)
{
    var clinicIcon = new GIcon();
    
    if (isNew)
    {
        clinicIcon.image = __appBase + '/Images/ClinicPositioning/mcMarker_new.png';
        clinicIcon.printImage = __appBase + '/Images/ClinicPositioning/mcMarker_newIE6PrintFix.gif';
	    clinicIcon.iconSize = new GSize(52, 53);
	    clinicIcon.iconAnchor = new GPoint(21, 53);
	    clinicIcon.imageMap = [5,0, 36,0, 36,37, 5,37];
	    clinicIcon.infoWindowAnchor = new GPoint(19, 1);
    }
    else
    {
	    clinicIcon.image = __appBase + '/Images/ClinicPositioning/mcMarker.gif';
	    clinicIcon.printImage = __appBase + '/Images/ClinicPositioning/mcMarkerIE6PrintFix.gif';
	    clinicIcon.iconSize = new GSize(42, 39);
	    clinicIcon.iconAnchor = new GPoint(11, 39)
    }
    
	clinicIcon.shadow = "";
    clinicIcon.shadowSize = new GSize(0, 0);
    clinicIcon.infoWindowAnchor = new GPoint(10, 1);
    
    var point = new GLatLng(lat, lng);
    var marker = new GMarker(point,{icon:clinicIcon});
    
    _clinicMarkers[_clinicMarkers.length] = marker;
    var html = '<div class="cont"><div style="float:left; width:190px;"><img width=94 height=39 src="' + __appBase + '/images/logo1.gif" alt="MinuteClinic" />' + 
        markerTitle + '<div style="padding:10px 0 5px 0;"><a class="more" href="' + more_url + '">Details</a> <span class="sep">|</span> <a class="external" href="http://maps.google.com/maps?saddr=' + _saddr + '&daddr=' + daddr + '" target ="_blank">Get Directions</a></div></div><div style="margin-left:20px;border-left:solid 1px #DDE; padding:5px 0 5px 20px; width:190px; float:left;margin-bottom:10px;"><strong class="color3">Flu vaccine: ' + seasonalFluVaccineAvailability + '</strong><p style="color: #E52F41;font-size: .95em;">NOTE: Flu vaccine availability information is updated nightly. Flu shots available while supplies last.</p></div></div>';
    marker.html = html;
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(html);
        $('.clinic_list .i .b').removeClass('selected');
        $('.clinic_list .i.n' + key + ' .b').addClass('selected');
    });
    GEvent.addListener(marker, "infowindowclose", function() {
        $('.clinic_list .i .b').removeClass('selected');
    });
    _map.addOverlay(marker);
}

function addClinicMarker1(markerTitle, lat, lng, address, locationType, daddr, isNew)
{
    var clinicIcon = new GIcon();
	
	if (isNew)
    {
        clinicIcon.image = __appBase + '/Images/ClinicPositioning/mcMarker_new.png';
        clinicIcon.printImage = __appBase + '/Images/ClinicPositioning/mcMarker_newIE6PrintFix.gif';
	    clinicIcon.iconSize = new GSize(52, 53);
	    clinicIcon.iconAnchor = new GPoint(21, 53);
	    clinicIcon.imageMap = [5,0, 36,0, 36,37, 5,37];
	    clinicIcon.infoWindowAnchor = new GPoint(19, 1);
    }
    else
    {
	    clinicIcon.image = __appBase + '/Images/ClinicPositioning/mcMarker.png';
	    clinicIcon.printImage = __appBase + '/Images/ClinicPositioning/mcMarkerIE6PrintFix.gif';
	    clinicIcon.iconSize = new GSize(42, 39);
	    clinicIcon.iconAnchor = new GPoint(11, 39)
    }
	
	
	
	clinicIcon.shadow = "";
    clinicIcon.shadowSize = new GSize(0, 0);
    clinicIcon.infoWindowAnchor = new GPoint(10, 1);

    var point = new GLatLng(lat, lng);
    var marker = new GMarker(point,{icon:clinicIcon});
    
    var html = '<div class="cont"><img src="' + __appBase + '/images/logo1.gif" alt="MinuteClinic" /><div class="block4">' + 
        markerTitle + '</div><div style="padding-top:10px;"><a class="external" href="http://maps.google.com/maps?saddr=' + _saddr + '&daddr=' + daddr + '" target ="_blank">Get Directions</a></div>';
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindow(html);
    });
    
    _map.addOverlay(marker);
}

function addClinicMarkerCenter(markerTitle, lat, lng, centerAddress)
{
    _saddr = centerAddress;
    var clinicIcon = new GIcon(G_DEFAULT_ICON);

    var point = new GLatLng(lat, lng);
    var marker = new GMarker(point,{icon:clinicIcon});

    var html = markerTitle;
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindow(html);
    });
    
    _map.addOverlay(marker);
}

$(document).ready(function()
{
    $(".clinic_list .i .b").hover(
      function () {
        $(this).addClass("hover");
      }, 
      function () {
        $(this).removeClass("hover");
      }
    );
    
    $(".clinic_list .i .b").click(
      function () {
        var index = $(this).attr('id').substring(1);
        _clinicMarkers[index].openInfoWindow(_clinicMarkers[index].html);
        $(this).parents(".clinic_list").find(".i .b").removeClass("selected");
        $(this).addClass("selected");
      }
    );
}
)
