﻿var map;
var icon;
var latitude;
var longitude;

$(document).ready(function() {
    
    InitMap();

    //$("#addressMap").hide();

    $("#hideShowMap").click(function() {
        if ($("#addressMap").is(':visible')) {
            $("#addressMap").hide();
            $("#hideShowMap").html(ResourceManager.GetString("siteDetails_ShowMap"));
        }
        else {
            $("#addressMap").STshow('fast');
            $("#hideShowMap").html(ResourceManager.GetString("siteDetails_HideMap"));
        }
        return false;
    });

    //$("#bannerContent").hide();

    $("#hideShowBanner").click(function() {
        if ($("#bannerContent").is(':visible')) {
            $("#bannerContent").hide();
            $("#hideShowBanner").html(ResourceManager.GetString("siteDetails_ShowBanner"));
        }
        else {
            $("#bannerContent").STshow('fast');
            $("#hideShowBanner").html(ResourceManager.GetString("siteDetails_HideBanner"));
        }
        return false;
    });

    

    $('#popPartner').jqm({ modal: false });
    $('#popDisclaimer').jqm({ modal: false });

    $("#" + linkPartnerImg).click(function(event) {
        var top = event.pageY + 'px'
        $('#popPartner').css('top', top);
        $('#popPartner').jqmShow();
        return false;
    });

    $("#" + linkPartnerText).click(function(event) {
        var top = event.pageY+ 'px'
        $('#popPartner').css('top', top);
        $('#popPartner').jqmShow();
        return false;
    });

    $("#linkDisclaimer").click(function(event) {
        $('#popDisclaimer').jqmShow();
        return false;
    });
    
    

});



function SetIcon(type)
{
    icon=type;
}

function InitMap() {
    
      if (GBrowserIsCompatible()) {
      
        var baseIcon = new GIcon();
        baseIcon.iconSize=new GSize(15,20);          
        baseIcon.iconAnchor=new GPoint(7,10);
        baseIcon.infoWindowAnchor=new GPoint(7,10);
          
        clubIcon = new GIcon(baseIcon, "/images/gfx/icon/pointeur_club.png", null, null);
        eventIcon = new GIcon(baseIcon, "/images/gfx/icon/pointeur_event.png", null, null);
        spotIcon = new GIcon(baseIcon, "/images/gfx/icon/pointeur_spot.png", null, null);

        map = new GMap2(document.getElementById("addressMap"));
        map.setUIToDefault();

               
        var lat = parseFloat(latitude);
        var lng = parseFloat(longitude);         
        map.setCenter(new GLatLng(lat, lng), 13);            
        InitMarkerPosition(new GLatLng(lat, lng));                            
             
        
      }
}


// handy method to fill in the lat and lng fields by clicking on the map.
function InitMarkerPosition(point)
{
  
  map.clearOverlays();
    
  var currentMarker;
    
  if (icon == "club")
    currentMarker = new GMarker(new GLatLng(point.lat(), point.lng()),{icon: clubIcon, draggable: false});
 else if (icon == "event")
    currentMarker = new GMarker(new GLatLng(point.lat(), point.lng()), {icon: eventIcon,draggable: false});
 else if (icon == "spot")
    currentMarker = new GMarker(new GLatLng(point.lat(), point.lng()), {icon: spotIcon,draggable: false});

  map.addOverlay(currentMarker);

}



