// JavaScript Document

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var youIcon = new GIcon(G_DEFAULT_ICON);
youIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
youIcon.iconSize = new GSize(34, 34);
youIcon.shadowSize = new GSize(37, 34);
youIcon.iconAnchor = new GPoint(9, 34);
youIcon.infoWindowAnchor = new GPoint(9, 2);

// Create our "home" marker icon
var homeIcon = new GIcon(G_DEFAULT_ICON);
homeIcon.image = "http://www.xanadoo.com/images/store_icon_shadowed.png";
homeIcon.shadow = "http://www.xanadoo.com/images/spcr.png";
homeIcon.iconSize = new GSize(55, 29);
homeIcon.shadowSize = new GSize(49, 17);
homeIcon.iconAnchor = new GPoint(9, 34);
homeIcon.infoWindowAnchor = new GPoint(9, 2);

function getIcon(number, letter) {
    var objLetteredIcon;
    if (number==9999) {
        objLetteredIcon = new GIcon(homeIcon);
    }else if (number==-1) {
	    objLetteredIcon = new GIcon(youIcon);
	    objLetteredIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";  
    }else{
	    objLetteredIcon = new GIcon(baseIcon);
	    objLetteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";  
    }  
    return objLetteredIcon;
}

function createMarker(point, number) {
  // Create a lettered icon for this point using our icon class
  var letter = String.fromCharCode("A".charCodeAt(0) + number);  
  var letteredIcon = getIcon(number, letter);
  
  // Set up our GMarkerOptions object  
  markerOptions = { icon:letteredIcon };
  
  var marker = new GMarker(point, markerOptions);
  marker.value = number;
  if (number>-1) {
    GEvent.addListener(marker, "click", function() {
        var myHtml = "<strong>" + storename[number] + "</strong>" + "<br />" + address[number];
        map.openInfoWindowHtml(point, myHtml);
    });
  }else{
    GEvent.addListener(marker, "click", function() {
        var myHtml = "<strong>You are here!</strong>";
        map.openInfoWindowHtml(point, myHtml);
    });  }

  return marker;
}

function addYou(lat, long) {
    if (lat>0) {
        var point = new Array();
	    point[0] = new GLatLng(lat,long);
	    map.addOverlay(createMarker(point[0],-1));
	}
}