/*
 * CrosshairControlSide Library
 * Author: Nao Iizuka <s03048ni@sfc.keio.ac.jp>
 * Feel free to use this script.
 *
 * This work is derived from http://www.step1.cn/googleapi/map/total.html#K_CrossControl
 */
/**
 * CrosshairControlSide class
 */
function CrosshairControlSide (length, image) {
    this.length = length || 10;
    this.image = image || 'http://ecogis.sfc.keio.ac.jp/developers/gmaps/images/crosshair.gif';
}
CrosshairControlSide.prototype = new GControl();
CrosshairControlSide.prototype.initialize = function (map) {
    this.Map = map; //GMap2 object
    this.div = document.createElement('div');
    var img = document.createElement('img');
    img.src = this.image;
    img.width = this.length * 2;
    img.height = 1;
    this.div.appendChild(img);
    this.div.style.width = this.length * 2 + 'px';
    this.div.style.height = '1px';
    this.div.style.zIndex = 4;
    map.getContainer().appendChild(this.div);
    this.defaultPosition = new CrosshairControlPosition();
    this.setDefaultPosition();
    GEvent.bind(map, 'resize', this, this.setDefaultPosition);
    return this.div;
}
CrosshairControlSide.prototype.setDefaultPosition = function() {
    var container = this.Map.getContainer();
    this.defaultPosition.setPosition(container.offsetWidth / 2 - this.length,
				     container.offsetHeight / 2 - 1);
    this.defaultPosition.apply(this.div);
}
CrosshairControlSide.prototype.getDefaultPosition = function() {
    return this.defaultPosition;
}
/**
 * CrosshairControlPosition class
 */
function CrosshairControlPosition() {
}
CrosshairControlPosition.prototype.setPosition = function (cx,cy) {
    this.x = cx || 0;
    this.y = cy || 0;
}
CrosshairControlPosition.prototype.apply = function (div) {
    div.style.position = 'absolute';
    div.style.left = this.x + 'px';
    div.style.top = this.y + 'px';
}
