﻿function body_onload()
{
    refreshData();
    
    CreateMap();

    //hook timer for data refresh
    //this.window.setInterval(refreshData, 5000);
}

function refreshData()
{
    PageMethods.DisplayPopularPlaces(OnDisplayPopularPlacesSucess, OnDisplayPopularPlacesError);
    PageMethods.DisplayTopHunters(OnDisplayTopHuntersSucess, OnDisplayTopHuntersError);
    PageMethods.DisplayStats(OnDisplayStatsSucess, OnDisplayStatsError);
}

function viewPlace(place)
{
    document.location = "Hoosphere.aspx?p=" + escape(place);
}

function OnDisplayPopularPlacesSucess(result) {

    var placeholder = $get('PopularPlacesPlaceHolder');

    if (placeholder != null) {
        placeholder.innerHTML = result;
    }
}

function OnDisplayPopularPlacesError(result)
{ }

function OnDisplayTopHuntersSucess(result) 
{
    var placeholder = $get('HooLeaguePlaceHolder');

    if (placeholder != null) {
        placeholder.innerHTML = result;
    }
}

function OnDisplayTopHuntersError(result)
{ }


function OnDisplayStatsSucess(result)
{

    if (result != null)
    {

        var p1 = $get('TotalValue');
        if (p1 != null)
        {
            p1.innerHTML = result.totalHoosFound ? result.totalHoosFound : "-";
        }
    }
}

function OnDisplayStatsError(result)
{ }



// Map Stuff
var map = null;

function CreateMap() {
    map = new VEMap('VEMap');
    map.onLoadMap = EventMapLoad;
    map.AttachEvent("onclick", map_onclick);
    map.LoadMap();
}

function EventMapLoad() {
    var shapeLayer = new VEShapeLayer();
    var shapeSpec = new VEShapeSourceSpecification(VEDataType.ImportXML, mapUrl, shapeLayer);
    map.ImportShapeLayerData(shapeSpec);
}

function map_onclick(event)
{
    if (event.elementID)
    {
        var hoo = map.GetShapeByID(event.elementID);
        document.location = "Hoosphere.aspx?p=" + escape(hoo.GetTitle());
    }
    
}

