﻿var m_GoogleMapObj = null;
var m_GoogleMap_Lat = -34.397;
var m_GoogleMap_Lng = 150.644;
var m_GoogleMapOverlay = null;
var m_GoogleMapMarkers = new Array();

// Code snippt to get X & Y position of marker from:
// http://snippets.aktagon.com/snippets/377-How-to-find-a-Google-Map-marker-s-exact-position

function ProjectionHelperOverlay(map)
{
    this.setMap(map);
}

ProjectionHelperOverlay.prototype = new google.maps.OverlayView();

ProjectionHelperOverlay.prototype.draw = function ()
{
    if (!this.ready)
    {
        this.ready = true;
        google.maps.event.trigger(this, 'ready');
    }
};

function GoogleMap()
{
    //alert('GoogleMap');

    // Get the lat and lng of the user's location.
    if (typeof (GoogleMapLatLng) == 'function')
    {
        GoogleMapLatLng();
    }

    // Create Google LatLmg object.
    // This is the center of the map.
    var latlng = new google.maps.LatLng(m_GoogleMap_Lat, m_GoogleMap_Lng);
    
    var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    // Make sure we can find the DIV which will show the Google Map.
    var ElementObj = document.getElementById("GoogleMap_Canvas");
    //alert(ElementObj);
    if (ElementObj == null) return;

    // Create the map
    var m_GoogleMapObj = new google.maps.Map(document.getElementById("GoogleMap_Canvas"),
        myOptions);

    // We put the GoogleMapMarkers function only on the Find a Retailer page.
    //
    // Problem: If we call GoogleMapMarkers (w/o checking for existence of the
    // function then a JavaScript error will occur.
    //
    // Solution: Check for existence of the function. If exists then call it.
    // Otherwise, we're not on Find a Retailer page.
    if (typeof (GoogleMapMarkers) == 'function')
    {
        // Add the map pins (Google calls them 'overlays') to the map
        GoogleMapMarkers(m_GoogleMapObj);
    }

    m_GoogleMapOverlay = new ProjectionHelperOverlay(m_GoogleMapObj);
}

function TagsDump()
{
    Tags = document.getElementsByTagName("div");
    alert('Tags.length = ' + Tags.length);
    for (i = 0; i < Tags.length - 1; i++)
    {
        TagObj = Tags[i];
        alert(TagObj.id);
    }
}

function JB_X(Obj)
{
    var x = Obj.offsetLeft;

    while (Obj = Obj.offsetParent)
    {
        x += Obj.offsetLeft;
    }

    return x;
}

function JB_Y(Obj)
{
    var y = Obj.offsetTop;

    y = y - Obj.offsetHeight / 2;

    while (Obj = Obj.offsetParent) {
        y += Obj.offsetTop;
    }

    return y;
}
