/*
 * $Revision: 1.3 $
 * $Date: 2008/08/01 08:13:29 $
 */

/******************************************************************************/
function geo_CreateMarker(point, x, y, count, img)
{
    count += ' hits';
    var marker = new GMarker(point, {title: count, icon: img});

    var html = '<small><strong>Country: </strong>' + y + '<br/>';
    html += '<strong>City: </strong>' + x + '<br />' + count + '</small>';

    GEvent.addListener(marker, 'click', function()
    {
        geo.map.openInfoWindowHtml(point, html);
    });

    geo.map.addOverlay(marker);
}

/******************************************************************************/
function geo_InitMap()
{
    var baseicon              = new GIcon();
    baseicon.shadow           = geo.img_src + 'm_shadow.png';
    baseicon.iconAnchor       = new GPoint(6, 20);
    baseicon.iconSize         = new GSize(12, 20);
    baseicon.shadowSize       = new GSize(22, 20);
    baseicon.infoWindowAnchor = new GPoint(5, 1);
 
    geo.icon[0]  = new GIcon(baseicon);
    geo.icon[0].image = geo.img_src + 'm_yellow.png';
    geo.icon[1]  = new GIcon(baseicon);
    geo.icon[1].image = geo.img_src + 'm_orange.png';
    geo.icon[2]  = new GIcon(baseicon);
    geo.icon[2].image = geo.img_src + 'm_red.png';

    geo_SetMapSize();

    geo.map = new GMap2(document.getElementById('map'));
    geo.map.setMapType(G_HYBRID_MAP);
    geo.map.addControl(new GSmallZoomControl());
    geo.map.setCenter(new GLatLng(0, 0), 2);
    geo.map.hideControls();

    GEvent.addListener(geo.map, 'mouseover', geo.map.showControls);
    GEvent.addListener(geo.map, 'mouseout', geo.map.hideControls);

    geo.map.clearOverlays();
}

/******************************************************************************/
function geo_LoadMap()
{
    if (!GBrowserIsCompatible())
    {
        $("#mapgoogle").hide();
        $("#errmsg").show();
    }
    else
    {
        geo_InitMap();

        for (var i = 0; i < geo.points.length - 1; i = i + 5)
        {
            geo_CreateMarker(new GLatLng(geo.points[i],geo.points[i+1]),
                             geo.points[i+2],
                             geo.points[i+3],
                             geo.points[i+4],
                             geo.icon[(geo.points[i+4].length) - 1]);
        }
    }
}

/******************************************************************************/
function geo_SetMapSize()
{
    $('#map').height(parseInt($('#map').width() * 0.67));
}

/******************************************************************************/
$(window).load(geo_LoadMap);
$(window).resize(geo_SetMapSize);
$(window).unload(GUnload);

