﻿function ChangeMap(loc) {
    m = document.getElementById("regionMap");
    switch (loc) {
        case "california": { m.src = picCalifornia.src; break; }
		case "central": {m.src = picCentral.src; break;}
		case "northwest": {m.src = picNorthwest.src; break;}
		case "northeast": {m.src = picNortheast.src; break;}
		case "southeast": {m.src = picSoutheast.src; break;}
		case "southCentral": {m.src = picSouthCentral.src; break;}
		case "southwest": {m.src = picSouthwest.src; break;}
	}
}

function initialize() {
    if ($("#ContactPage").length) {
        initializeContactPage();
    }
}

function initializeContactPage() {
    preloadImages();
    $(".showMap").click(function() {
        showMap();
    });
}

function MapClick(loc, lat, lng) {
    $(".regionMap").hide();
    $("#" + loc).show();
    if (lat != undefined) {
        showGoogleMap(lat, lng);
    }
}

function preloadImages() {
    if (document.images) {
        picCalifornia = new Image();
        picCentral = new Image();
        picNorthwest = new Image();
        picNortheast = new Image();
        picSoutheast = new Image();
        picSouthCentral = new Image();
        picSouthwest = new Image();

        picCalifornia.src = "images/contacts/california_over.jpg";
        picCentral.src = "images/contacts/central_over.jpg";
        picNorthwest.src = "images/contacts/northwest_over.jpg";
        picNortheast.src = "images/contacts/northeast_over.jpg";
        picSoutheast.src = "images/contacts/southeast_over.jpg";
        picSouthCentral.src = "images/contacts/southCentral_over.jpg";
        picSouthwest.src = "images/contacts/southwest_over.jpg";
    }
}

var googleMap;
function showGoogleMap(lat, lng) {
    var latlng = new google.maps.LatLng(lat, lng);

    if (!googleMap) {
        var myOptions = {
            zoom: 15,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        googleMap = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    } else {
        googleMap.setCenter(latlng);
    }

    var marker = new google.maps.Marker({
        position: latlng,
        map: googleMap,
        title: "Branch Location"
    });

    $("#map_canvas").show();
}

function showMap() {
    $("#map_canvas").hide();
    $(".region").hide();
    $(".regionMap").show();
}

initialize();