var HistoryGMap = Class.create();
HistoryGMap.prototype = {
    // コンストラクタ
    initialize: function( scale, latitude, longitude, article_id, icon, noscale ) {
        this.marker = {};
        this.noscale = noscale;
        this.current_scale;
        if (GBrowserIsCompatible()) {
            this.map = this.createMap('map', scale, latitude, longitude);
        }
        this.prot(article_id, latitude, longitude, icon);
    },
    
    // メソッド
    createMap : function (id, scale, latitude, longitude) {
        var map = new GMap2($( id ));
        map.addControl(new GScaleControl());
        if( this.noscale != '1') {
            map.addControl(new TextualZoomControl());
        }
        else {
            map.disableDragging();
        }
        map.setCenter(new GLatLng(latitude, longitude), scale);
        this.current_scale = map.getZoom();
        return map;
    },

    // Creates a marker whose info window displays the letter corresponding
    // to the given index.
    createMarker : function (point, url) {
        var image_url;
        if( url ) {
            image_url = url;
        }
        else {
            image_url = "/img/icon_map01.gif";
        }
        // Create a lettered icon for this point using our icon class
        var icon = new GIcon(baseIcon);
        icon.image = image_url;
        var marker = new GMarker(point, icon);
        return marker;
    },

    prot : function (article_id, latitude, longitude, icon) {
        article_id = 'H' + article_id;
        var point = new GLatLng(latitude, longitude);
        if(!(this.marker[article_id])) {
            this.marker[article_id]= this.createMarker(point, icon);
            this.map.addOverlay(this.marker[article_id]);
        }
    }
}

// A TextualZoomControl is a GControl that displays textual "Zoom In"
// and "Zoom Out" buttons (as opposed to the iconic buttons used in
// Google Maps).
function TextualZoomControl() {
}
TextualZoomControl.prototype = new GControl();

// Creates a one DIV for each of the buttons and places them in a container
// DIV which is returned as our control element. We add the control to
// to the map container and return the element for the map class to
// position properly.
TextualZoomControl.prototype.initialize = function(map) {
    var container = document.createElement("div");
    var _zButton_in  = 1;
    var _zButton_out = 1;
    
    var zoomInDiv = document.createElement("div");
    this.setButtonStyle_(zoomInDiv);
    container.appendChild(zoomInDiv);
    zoomInDiv.appendChild(document.createTextNode("拡大"));
    // map.getZoom() は数値が小さい方が広域
    GEvent.addDomListener(zoomInDiv, "click", function() { // 拡大をクリック(map.getZoom()は大きくなる)
        map.zoomIn();
        if(_zButton_out == 0 && map.getZoom() > 13) {
            zoomOutDiv.style.visibility = "visible";
            _zButton_out = 1;
        }
        if(_zButton_in == 1 && map.getZoom() == 19 ) {
            zoomInDiv.style.visibility = "hidden";
            _zButton_in = 0;
        }
        current_scale = map.getZoom();
    });

    var zoomOutDiv = document.createElement("div");
    this.setButtonStyle_(zoomOutDiv);
    container.appendChild(zoomOutDiv);
    zoomOutDiv.appendChild(document.createTextNode("縮小"));
    GEvent.addDomListener(zoomOutDiv, "click", function() { // 縮小をクリック(map.getZoom()は小さくなる)
        if(_zButton_in == 0 && map.getZoom() < 20) {
            zoomInDiv.style.visibility = "visible";
            _zButton_in = 1;
        }
        if(map.getZoom() > 13 ) {
            map.zoomOut();
        }
        if(_zButton_out == 1 && map.getZoom() <= 13) { // scale は13 までしか許可しない
            zoomOutDiv.style.visibility = "hidden";
            _zButton_out = 0;
        }
        current_scale = map.getZoom();
    });

    map.getContainer().appendChild(container);
    return container;
}

// By default, the control will appear in the top left corner of the
// map with 7 pixels of padding.
TextualZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}

// Sets the proper CSS for the given button element.
TextualZoomControl.prototype.setButtonStyle_ = function(button) {
    button.style.textDecoration = "underline";
    button.style.color = "#0000cc";
    button.style.backgroundColor = "white";
    button.style.font = "small Arial";
    button.style.border = "1px solid black";
    button.style.padding = "1px";
    button.style.marginBottom = "2px";
    button.style.textAlign = "center";
    button.style.width = "2.5em";
    button.style.cursor = "pointer";
}

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon();
//baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(21, 24);
//baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
//baseIcon.infoWindowAnchor = new GPoint(9, 2);
//baseIcon.infoShadowAnchor = new GPoint(18, 25);

