﻿//   This Javascript is provided by Mike Williams
//   Community Church Javascript Team
//   http://www.bisphamchurch.org.uk/   
//   http://econym.org.uk/gmap/
//
//   This work is licenced under a Creative Commons Licence
//   http://creativecommons.org/licenses/by/2.0/uk/


//  Modified slightly by INET-DESIGN ApS to use DOM manipulation functions provided by jQuery


/*****************/
/**** EWindow ****/

function EStyle(stemImage, stemSize, boxClass, boxOffset) {
    this.stemImage = stemImage;
    this.stemSize = stemSize;
    this.boxClass = boxClass;
    this.boxOffset = boxOffset;

    var agent = navigator.userAgent.toLowerCase();

    var fudge = 0;
    this.fudge = fudge;
}

function EWindow(map, estyle) {
    // parameters
    this.map = map;
    this.estyle = estyle;
    // internal variables
    this.visible = false;
    // browser - specific variables
    this.ie = false;
    var agent = navigator.userAgent.toLowerCase();
    if ((agent.indexOf("msie") > -1) && (agent.indexOf("opera") < 1)) { this.ie = true } else { this.ie = false }
}

EWindow.prototype = new GOverlay();

EWindow.prototype.initialize = function(map) {
    var div1 = document.createElement("div");
    $(div1).css("position", "absolute");

    map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div1);

    var div2 = document.createElement("div");
    $(div2).css({
        "position": "absolute",
        "width": this.estyle.stemSize.width + "px"
    });
    map.getPane(G_MAP_FLOAT_SHADOW_PANE).appendChild(div2);
    this.div1 = div1;
    this.div2 = div2;
}

EWindow.prototype.openOnMap = function(point, content, offset) {
    this.offset = offset || new GPoint(0, 0);
    this.point = point;

    var objDiv = document.createElement("div");
    $(objDiv).addClass(this.estyle.boxClass);
    $(objDiv).append(content);

    $(this.div1).empty().append(objDiv);

    if (this.ie && this.estyle.stemImage.toLowerCase().indexOf(".png") > -1) {
        var loader = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.estyle.stemImage + "', sizingMethod='scale');";
        this.div2.innerHTML = '<div style="height:' + this.estyle.stemSize.height + 'px; width:' + this.estyle.stemSize.width + 'px; ' + loader + '" ></div>';
    } else {
        this.div2.innerHTML = '<img src="' + this.estyle.stemImage + '" width="' + this.estyle.stemSize.width + '" height="' + this.estyle.stemSize.height + '">';
    }

    var z = GOverlay.getZIndex(this.point.lat());

    $(this.div1).css("zIndex", z);
    $(this.div2).css("zIndex", z + 1);

    this.visible = true;
    this.show();
    this.redraw(true);
}

EWindow.prototype.openOnMarker = function(marker, content) {
    var vx = marker.getIcon().iconAnchor.x - marker.getIcon().infoWindowAnchor.x;
    var vy = marker.getIcon().iconAnchor.y - marker.getIcon().infoWindowAnchor.y;
    this.openOnMap(marker.getLatLng(), content, new GPoint(vx, vy));
}


EWindow.prototype.redraw = function(force) {
    if (!this.visible) { return; }
    var p = this.map.fromLatLngToDivPixel(this.point);
    this.div2.style.left = (p.x + this.offset.x) + "px";
    this.div2.style.bottom = (-p.y + this.offset.y - this.estyle.fudge) + "px";
    this.div1.style.left = (p.x + this.offset.x + this.estyle.boxOffset.x) + "px";
    this.div1.style.bottom = (-p.y + this.offset.y + this.estyle.boxOffset.y) + "px";
}

EWindow.prototype.remove = function() {
    this.div1.parentNode.removeChild(this.div1);
    this.div2.parentNode.removeChild(this.div2);
    this.visible = false;
}

EWindow.prototype.copy = function() {
    return new EWindow(this.map, this.estyle);
}

EWindow.prototype.show = function() {
    this.div1.style.display = "";
    this.div2.style.display = "";
    this.visible = true;
}

EWindow.prototype.hide = function() {
    this.div1.style.display = "none";
    this.div2.style.display = "none";
    this.visible = false;
}

EWindow.prototype.isHidden = function() {
    return !this.visible;
}

EWindow.prototype.supportsHide = function() {
    return true;
}

EWindow.prototype.zindex = function(zin) {
    var z = GOverlay.getZIndex(this.point.lat());
    this.div1.style.zIndex = z + zin;
    this.div2.style.zIndex = z + 1 + zin;
}


EWindow.prototype.getSize = function() {
    if (!this.visible) {
        return null;
    }
    else {
        return new GSize(this.div1.offsetWidth, this.div1.offsetHeight + this.div2.offsetHeight);
    }
}


/**** EWindow ****/
/*****************/



var ICON_HOUSE = null;
var ICON_HOUSE_DISCOUNT = null;
var ICON_HOUSE_MEMO = null;
var ICON_HOUSE_DISCOUNT_MEMO = null;
var ICON_MULTIPLE_HOUSES = null;

var TYPE_HOUSE = 0;
var TYPE_MULTIPLE_HOUSES = 1;
var TYPE_HOUSE_MEMO = 2;
var TYPE_HOUSE_DISCOUNT = 3;
var TYPE_HOUSE_DISCOUNT_MEMO = 4;

var E_STYLE_HOUSE;

/*
var ew = null;
var ewm = null;
*/

if (GBrowserIsCompatible()) {
    ICON_HOUSE = new GIcon();
    ICON_HOUSE.image = "/Site/Images/Icons/icon-house.png";
    ICON_HOUSE.iconSize = new GSize(30, 22);
    ICON_HOUSE.iconAnchor = new GPoint(15, 22);
    ICON_HOUSE.infoWindowAnchor = new GPoint(15, 11);

    ICON_HOUSE_MEMO = new GIcon();
    ICON_HOUSE_MEMO.image = "/Site/Images/Icons/icon-house-memo.png";
    ICON_HOUSE_MEMO.iconSize = new GSize(30, 22);
    ICON_HOUSE_MEMO.iconAnchor = new GPoint(15, 22);
    ICON_HOUSE_MEMO.infoWindowAnchor = new GPoint(15, 11);

    ICON_HOUSE_DISCOUNT = new GIcon();
    ICON_HOUSE_DISCOUNT.image = "/Site/Images/Icons/icon-house-discount.png";
    ICON_HOUSE_DISCOUNT.iconSize = new GSize(30, 22);
    ICON_HOUSE_DISCOUNT.iconAnchor = new GPoint(15, 22);
    ICON_HOUSE_DISCOUNT.infoWindowAnchor = new GPoint(15, 11)

    ICON_HOUSE_DISCOUNT_MEMO = new GIcon();
    ICON_HOUSE_DISCOUNT_MEMO.image = "/Site/Images/Icons/icon-house-discount-memo.png";
    ICON_HOUSE_DISCOUNT_MEMO.iconSize = new GSize(30, 22);
    ICON_HOUSE_DISCOUNT_MEMO.iconAnchor = new GPoint(15, 22);
    ICON_HOUSE_DISCOUNT_MEMO.infoWindowAnchor = new GPoint(15, 11)

    ICON_MULTIPLE_HOUSES = new GIcon();
    ICON_MULTIPLE_HOUSES.image = "/Site/Images/Icons/icon-house-multiple.png";
    ICON_MULTIPLE_HOUSES.iconSize = new GSize(30, 22);
    ICON_MULTIPLE_HOUSES.iconAnchor = new GPoint(15, 22);
    ICON_MULTIPLE_HOUSES.infoWindowAnchor = new GPoint(15, 11);

    E_STYLE_HOUSE = new EStyle("/Site/Images/Icons/stem.png", new GSize(24, 24), "e_style_house", new GPoint(-10, 23));
    E_STYLE_HOUSE_DISCOUNT = new EStyle("/Site/Images/Icons/stem.png", new GSize(24, 24), "e_style_house_discount", new GPoint(-10, 23));
    E_STYLE_MULTIPLE_HOUSES = new EStyle("/Site/Images/Icons/stem-multiple.png", new GSize(24, 24), "e_style_multiple_houses", new GPoint(-10, 23));

    GMarker.prototype.type = -1;
}



