var infobox_template = '<b><a href="#" onclick="this.parentNode.parentNode.style.display=\'none\'" class="x">X</a></b>\
<table cellpadding="0" cellspacing="0" border="0">\
<tr><td class="cbt"><img src="/images/infobox/tl.gif"></td><td class="mbt" background="/images/infobox/t.gif"></td><td class="cbt"><img src="/images/infobox/tr.gif"></td></tr>\
<tr><td class="sbt"><img src="/images/infobox/lb.gif"></td><td class="mbt" style="color: white;" background="/images/infobox/mb.gif"><b>__TITLE__</b></td><td class="sbt"><img src="/images/infobox/rb.gif"></td></tr>\
<tr><td class="sbt" background="/images/infobox/l.gif"><img src="/images/infobox/l.gif"></td><td class="mst" style="background:#FFF">__CONTENT__</td><td class="sbt" background="/images/infobox/r.gif"><img src="/images/infobox/r.gif"></td></tr>\
<tr><td class="cbt"><img src="/images/infobox/bl.gif"></td><td class="mbt" background="/images/infobox/b.gif"></td><td class="cbt"><img src="/images/infobox/br.gif"></td></tr>\
</table>';
function GInfoWindow(point, title, content) { this.point = point; this.content = content; this.title = title; this.large = 0; this.hover = 0; }
GInfoWindow.prototype = new GOverlay();
GInfoWindow.prototype.initialize = function(map) {
    var tdiv = document.createElement('div');
    tdiv.style.position = 'absolute';
    tdiv.style.display = 'none';
    tdiv.style.border = '1px solid black';
    tdiv.style.background = '#FFF';
    tdiv.style.padding = '3px';
    tdiv.style.whiteSpace = 'nowrap';
    tdiv.innerHTML = this.title;
    map.getPane(G_MAP_MARKER_PANE).appendChild(tdiv);

    var div = document.createElement('div');
    div.style.position = 'absolute';
    div.style.display = 'none';
    div.innerHTML = infobox_template;
    div.innerHTML = div.innerHTML.replace(/__TITLE__/, this.title);
    div.innerHTML = div.innerHTML.replace(/__CONTENT__/, this.content);
    map.getPane(G_MAP_FLOAT_PANE).appendChild(div);

    this.map_ = map;
    this.tdiv_ = tdiv;
    this.div_ = div;
}
GInfoWindow.prototype.tshow = function() { this.tdiv_.style.display = ''; }
GInfoWindow.prototype.thide = function() { this.tdiv_.style.display = 'none'; }
GInfoWindow.prototype.isHidden = function() { return this.div_.style.display == 'none' ? true : false; }
GInfoWindow.prototype.reset = function() { }
GInfoWindow.prototype.getPoint = function() { return this.point }
GInfoWindow.prototype.show = function() {
    var old = document.getElementById('open_ibox');
    if (old) { old.style.display = 'none'; old.id = ''; }
    var a = this.map_.fromLatLngToDivPixel(this.point);
    var b = this.map_.fromLatLngToDivPixel(this.map_.getCenter());
    var f,g = 0;
    if ((a.x - b.x) <  75) { f = -1; }
    if ((a.y - b.y) < 120) { g = -1; }
    if (f || g) this.map_.panDirection(f, g);
    this.div_.style.display = '';
    this.div_.id = 'open_ibox';
}
GInfoWindow.prototype.hide = function() { this.div_.style.display = 'none'; this.div_.id = ''; }
GInfoWindow.prototype.toggle = function() { this.div_.style.display == 'none' ? this.show() : this.hide(); }
GInfoWindow.prototype.remove = function() { this.map_.getPane(G_MAP_FLOAT_PANE).removeChild(this.div_); }
GInfoWindow.prototype.copy = function() { return new infobox(this.point); }
GInfoWindow.prototype.redraw = function(force) {
    if (!force) return;
    var corner = this.map_.fromLatLngToDivPixel(this.point);

    this.div_.style.left = corner.x + 'px';
    this.div_.style.top = corner.y + 'px';

    this.tdiv_.style.left = (corner.x + 18) + 'px';
    this.tdiv_.style.top = (corner.y - 5) + 'px';
}

GMarker.prototype.openInfoWindow = function() { this.ibox.show(); }
GMarker.prototype.toggleinfobox = function() { this.ibox.toggle(); }
GMarker.prototype.infobox = function(title, content) { this.ibox = new GInfoWindow(this.getPoint(), title, content); }
//----------------------------------------------------
function ctext() {}
ctext.prototype = new GControl();
ctext.prototype.initialize = function(map) {
    var container = document.createElement('div');
    container.id = 'gmap_ctext';
    container.style.width = '420px';
    container.style.padding = '0px';
    container.style.textAlign = 'right';
    container.style.fontWeight = 'bold';
    map.getContainer().appendChild(container);
    this.container = container;
    map.ctext = 1;
    return container;
}
ctext.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 30)); }
GMap2.prototype.set_ctext = function(html) { document.getElementById('gmap_ctext').innerHTML = html; }
GMap2.prototype.clear_ctext = function() { document.getElementById('gmap_ctext').innerHTML = ''; }
GMap2.ctext = 0;
//----------------------------------------------------
function map_max() {}
map_max.prototype = new GControl();
map_max.prototype.initialize = function(map) {
    var container = document.createElement('div');
    container.id = 'map_max';
    container.style.width = '19px';
    container.style.height = '19px';
    container.style.padding = '0px';
    container.style.backgroundImage = 'url(/images/gmapbutton.png)';
    container.style.textAlign = 'center';
    container.innerHTML = '<a href="#" class="mapmax" onclick="map.map_max.big();"><img src="/images/max.gif"></a>';
    map.getContainer().appendChild(container);
    map.map_max = this;
    this.container = container;
    this.mapc = map.getContainer();
    return container;
}
map_max.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7)); }
map_max.prototype.big = function() {
    var cent = map.getCenter();
    this.container.innerHTML = '<a href="#" class="mapmax" onclick="map.map_max.small();"><img src="/images/min.gif"></a>';
    this.mapc.style.position = 'absolute';
    this.mapc.style.width = '100%';
    this.mapc.style.height = '100%';
    this.mapc.style.border = '0px';
    map.checkResize();
    if (markers[0]) lowzoom();
    else map.setCenter(cent);
}
map_max.prototype.small = function() {
    var cent = map.getCenter();
    this.container.innerHTML = '<a href="#" class="mapmax" onclick="map.map_max.big();"><img src="/images/max.gif"></a>';
    this.mapc.style.position = 'relative';
    this.mapc.style.width = '510px';
    this.mapc.style.height = '400px';
    this.mapc.style.border = '1px solid black';
    map.checkResize();
    if (markers[0]) lowzoom();
    else map.setCenter(cent);
}
//----------------------------------------------------
function printvc() {}
printvc.prototype = new GControl();
printvc.prototype.initialize = function(map) {
    var container = document.createElement('div');
    container.id = 'gmap_printvc';
    container.style.width = '19px';
    container.style.height = '19px';
    container.style.textAlign = 'center';
    container.style.verticalAlign = 'middle';
    container.style.backgroundImage = 'url(/images/gmapbutton.png)';
    container.innerHTML = '<a href="#" onclick="map.printvc.on()"><img src="/images/printer.gif"></a>';
    map.getContainer().appendChild(container);
    this.container = container;
    map.printvc = this;
    this.mapc = map.getContainer();
    return container;
}
printvc.prototype.on = function() { this.container.innerHTML = '<a href="#" onclick="map.printvc.off()"><img src="/images/printer.gif"></a>'; print_view(0); }
printvc.prototype.off = function() { this.container.innerHTML = '<a href="#" onclick="map.printvc.on()"><img src="/images/printer.gif"></a>'; print_view(1); }
printvc.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(47, 7)); }
//----------------------------------------------------
function linkicon() {}
linkicon.prototype = new GControl();
linkicon.prototype.initialize = function(map) {
    var container = document.createElement('div');
    container.id = 'gmap_linkicon';
    container.style.display = "none";
    container.style.width = '19px';
    container.style.height = '19px';
    container.style.textAlign = 'center';
    container.style.verticalAlign = 'middle';
    container.style.backgroundImage = 'url(/images/gmapbutton.png)';
    container.innerHTML = '<a href="" id="gmap_linkicon_href"><img src="/images/icon_link.gif"></a>';
    map.getContainer().appendChild(container);
    this.container = container;
    map.linkicon = this;
    this.mapc = map.getContainer();
    return container;
}
linkicon.prototype.set = function(one, two, three) {
    var link, txt;
    if (!three) { link = one; txt = one; }
    else { link = 'http://moremap.com/index.pl?svc=directions&loc='+one.uri()+'&loc2='+two.uri()+'/';
           txt  = 'http://moremap.com/index.pl?svc=directions&loc='+one+'&loc2='+two+'/' }
    gE('gmap_linkicon_href').href = link;
    gE('linkbox_href').href=link;
    gE('linkbox_href').innerHTML=txt;
    display('gmap_linkicon',1);
    display('linkbox',1);
}
linkicon.prototype.clear = function() { gE('gmap_linkicon_href').href = ''; gE('linkbox_href').href=''; gE('linkbox_href').innerHTML=''; display('gmap_linkicon',0); display('linkbox',0); }
linkicon.prototype.getDefaultPosition = function() { return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 47)); }
