/*
function $A (iterable) {
    return Array.prototype.slice.apply(iterable);
}
Function.prototype.bind = function () {
    var method = this;
    var args = $A (arguments);
    var object = args.shift();
    var wrapper = function () {
        return method.apply(object, args);
    };
    return wrapper;
}*/
Function.prototype.bind = function (object) {
    var method = this;
    var wrapper = function () {
        var args = Array.prototype.slice.apply(arguments);
        return method.apply(object, args);
    };
    return wrapper;
}

Function.prototype.bindAsEventListener = function (object) {
    var method = this;
    return function (event) {
        return method.call(object, event || window.event);
    }
}

GoogleMaps = function (gm) {
    this.gm = gm;
    if (GBrowserIsCompatible()) {
        this.addressString = this.buildAddressString(gm.address);
        this.map = new GMap2(this.gm.container);
        this.init();
        return true;
    } else {
        return false;
    }
}

GoogleMaps.prototype.buildAddressString = function (address) {
    this.address = address;
    var addressString = '';
    if (typeof address.searchString == 'undefined' || address.searchString == '' || 1==1) {
        addressString += address.street != '' ? address.street+' ' : '';
        if (address.zip != '') {
            if (address.zip.length < 5) {
                var request = new top.httpRequest;
                request.toggleSync();
                request.init();
                var response = request.load('getAddress.php?type=zip&zip='+address.zip+'&city='+encodeURIComponent(address.city));
                try {
                    var zip = eval('('+response+')');
                    if (typeof zip == 'object') throw true;
                    else throw false;
                } catch (e) {
                    if (e==true) {
                        address.zip = zip.zip;
                    } else {
                        address.zip = '';
                    }
                }
            }
            addressString += address.zip+' '
        }
        addressString += address.city != '' ? address.city : '';
    } else {
        addressString = address.searchString;
    }
    addressString += addressString.indexOf(' Germany')<0 ? ', Germany' : '';

    /*
    var request = new top.httpRequest;
    request.toggleSync();
    request.init();
    var e=encodeURIComponent;
    var p='type=get&'
    p += 'street='+e(address.street);
    p += 'zip='+e(address.zip);
    p += 'city='+e(address.city);
    var response = request.load('getAddress.php?'+p);
    try {
        var zip = eval('('+response+')');
        if (typeof zip == 'object') throw true;
        else throw false;
    } catch (e) {
        if (e==true) {
            address.zip = zip.zip;
        } else {
            address.zip = '';
        }
    }
    */


    /*top.console.log(addressString);*/
    return addressString;
}

GoogleMaps.prototype.reInit = function () {
    if (this.address.searchString != '') {
        this.address.searchString = '';
    } else if (this.address.street != '') {
        this.address.street = '';
    } else if (this.address.city != '') {
        this.address.city = '';
    } else {
        alert("Die Adresse\n"+this.addressString+"\nwurde nicht gefunden");
        this.gm.throbber.style.display = 'none';
        top.stadtplanFrame.frameElement.src = 'karte.html';
        return false;
    }
    this.init(this.buildAddressString(this.address))
    return true;
}

GoogleMaps.prototype.init = function (addressString) {
    this.addressString = addressString || this.addressString;
    this.geocoder = new GClientGeocoder();
    this.geocoder.setBaseCountryCode('DE');

    this.geocoder.getLocations(this.addressString, function (locations) {
        if (!locations.Placemark) {
            this.reInit();
            return;
        }
        var point = new GLatLng(locations.Placemark[0].Point.coordinates[1], locations.Placemark[0].Point.coordinates[0]);
        if (!point) {
            this.reInit();
            return;
        } else {
            var zoomLevel = locations.Placemark[0].AddressDetails.Accuracy * 2 < 5 ? 5 : locations.Placemark[0].AddressDetails.Accuracy * 2;
            if (this.gm.throbber) {
                this.gm.throbber.style.display = 'none';
            }
            this.markers.initialize(this.map, this);
            this.map.zoomLevel = zoomLevel;
            var defaultMapType = this.gm.maptype || G_HYBRID_MAP
            this.map.setMapType(defaultMapType);
            this.map.addControl(new GOverviewMapControl());
            this.map.setCenter(point, zoomLevel);
            this.map.searchCenter = this.map.getCenter();
            this.map.enableScrollWheelZoom();

            this.map.myControl = new MyControl();
            this.map.myControl.setHandler(this);
            this.map.addControl(this.map.myControl);
            var mapTypeControl = new GMenuMapTypeControl();
            this.map.addControl(mapTypeControl);
            this.initInfoSlider();
            this.initRouteForm();

            if (typeof this.gm.setMarker != 'undefined') {
                var markerOptions = {
                    id:'search',
                    point:point,
                    color:'red',
                    hoverText:this.map.myControl.createInfoSpan(this.addressString)
                };
                this.map.marker = this.markers.create(markerOptions);
                this.map.addOverlay(this.map.marker);
                this.map.activeMarker = this.map.marker;
            }

            var showMarkerIcon = new GIcon(G_DEFAULT_ICON);
            showMarkerIcon.image = 'images/buttons/showMarker.gif';
            showMarkerIcon.shadow = '';
            showMarkerIcon.printImage = '';
            showMarkerIcon.mozPrintImage = '';
            showMarkerIcon.printShadow = '';
            showMarkerIcon.iconSize = new GSize(36,36);
            showMarkerIcon.imageMap = [0,0,1,1];
            showMarkerIcon.iconAnchor = {x:14,y:44};
            var showMarkerOptions = {icon:showMarkerIcon}
            this.map.showMarkerIcon = new GMarker(point, showMarkerOptions);

            var showMarkerIcon = new GIcon(G_DEFAULT_ICON);
            showMarkerIcon.image = 'images/buttons/showMarker_pulse.gif';
            showMarkerIcon.shadow = '';
            showMarkerIcon.printImage = '';
            showMarkerIcon.mozPrintImage = '';
            showMarkerIcon.printShadow = '';
            showMarkerIcon.iconSize = new GSize(36,36);
            showMarkerIcon.imageMap = [0,0,1,1];
            showMarkerIcon.iconAnchor = {x:14,y:44};
            var showMarkerOptions = {icon:showMarkerIcon}
            this.map.showMarkerIcon_Pulse = new GMarker(point, showMarkerOptions);

            GEvent.addListener(this.map, 'zoomend', function (e) {
                this.map.myOwnSlider.moveTo({x:this.map.getZoom()*10,y:0});
            }.bindAsEventListener(this));

            zoomBoxOptions = {
                offset:{
                    top:38,
                    left:0
                }
            };
            zoomBoxCallbacks = {
                ontoggle : function (e) {
                    this.map.myControl.toggleZoomBoxDiv.style.background = e.on ?
                        'url(images/buttons/toggleZoomBox_dark_on.gif)' :
                        'url(images/buttons/toggleZoomBox_dark.gif)';
                    this.map.myControl.toggleZoomBoxDiv.hoverText = e.on ?
                        this.map.myControl.createInfoSpan('Einschalten: Die Karte mit der Maus verschieben') :
                        this.map.myControl.createInfoSpan('Einschalten: Einen Rahmen um den anzuzeigenden Bereich ziehen und heranzoomen');
                }.bindAsEventListener(this)
            }
            this.map.zoomBox = new ZoomBox(zoomBoxOptions,zoomBoxCallbacks);
            this.map.addControl(this.map.zoomBox);

            var wait = window.setInterval(function () {
                if (document.getElementById('menumtctl_main')) {
                    document.getElementById('menumtctl_main').title = '';
                    GEvent.addDomListener(document.getElementById('menumtctl_main'), "mouseover", function() {
                        this.animateInfoSlider('in', this.map.myControl.createInfoSpan('Kartentyp auswählen'));
                    }.bindAsEventListener(this));
                    GEvent.addDomListener(document.getElementById('menumtctl_main'), "mouseout", function() {
                        this.animateInfoSlider('out');
                    }.bindAsEventListener(this));
                    window.clearInterval(wait);
                }
            }.bind(this), 10);
            if (typeof top.setChoosenAdressWatch != 'undefined') {
                top.setChoosenAdressWatch.stroke('googleMaps');
            }
            if (typeof top.setAdressesWatch != 'undefined') {
                top.setAdressesWatch.stroke('googleMaps');
            }
            if (typeof top.routeWatch != 'undefined') {
                top.routeWatch.stroke('googleMaps');
            }
        }
    }.bindAsEventListener(this));
}

GoogleMaps.prototype.markers = {
    _markers : {},
    length : 0,
    initialize : function (map, parent) {
        this.parent = parent;
        this.map = map;
    },
    create : function (options) {
        options = options || {color:'default'};
        var pin = new GIcon(G_DEFAULT_ICON);
        pin.image = 'images/buttons/pin_'+options.color+'.png';
        pin.shadow = 'images/buttons/pin_shadow.png';
        pin.printImage = 'images/buttons/pin.png';
        pin.mozPrintImage = 'images/buttons/pin.png';
        pin.printShadow = 'images/buttons/pin_shadow.png';
        pin.shadowSize = new GSize(41,34);
        //pin.transparent = 'images/buttons/pin_transparent.png'; // events don't work with this
        pin.imageMap = [11,1,8,2,6,7,6,12,8,14,10,15,8,33,10,33,14,15,18,13,19,10,19,5,15,1];

        var marker = new GMarker(options.point, {icon:pin});
        marker.data = options.data || false;
        marker.hoverText = options.hoverText;
        this.add(marker, options.id);
        return marker;
    },
    add : function (marker, index) {
        this._markers[index] = marker;
        this.addEvents(marker);
        this.length++;
    },
    get : function (index) {
        return typeof this._markers[index] != undefined ? this._markers[index] : false;
    },
    getAll : function () {
        return this._markers;
    },
    remove : function (index) {
        this.parent.removeMarker(this._markers[index]);
        this._markers[index] = undefined;
        this.length--;
    },
    removeAll:function () {
        for (var index in this._markers) {
            this.remove(index);
        }
        this.length = 0;
        this._markers = {};
    },
    addEvents : function (marker) {
        if (typeof top.eintraegeFrame != 'undefined') {
            GEvent.addDomListener(marker, "mouseover", function() {
                if (window.animateInfoSliderTimeout) {
                    window.clearTimeout(window.animateInfoSliderTimeout);
                }
                if (top.eintraegeFrame.document.getElementById(marker.data.id) && this != this.map.activeMarker) {
                    var element = top.eintraegeFrame.document.getElementById(marker.data.id)
                    element.style.top = element.offsetTop-2+'px';
                    element.style.left = element.offsetLeft-2+'px';
                    element.style.border = '3px solid #FC9925';
                }
                this.parent.animateInfoSlider('in', marker.hoverText);
            }.bindAsEventListener(this));
            GEvent.addDomListener(marker, "mouseout", function() {
                if (top.eintraegeFrame.document.getElementById(marker.data.id)) {
                    var element = top.eintraegeFrame.document.getElementById(marker.data.id)
                    element.style.top = element.offsetTop+2+'px';
                    element.style.left = element.offsetLeft+2+'px';
                    element.style.border = '1px solid #2F465D';
                }
                if (window.animateInfoSliderTimeout) {
                    window.clearTimeout(window.animateInfoSliderTimeout);
                }
                window.animateInfoSliderTimeout = window.setTimeout(function () {
                    this.parent.animateInfoSlider('out');
                }.bind(this), 2000);
            }.bindAsEventListener(this));
            GEvent.addDomListener(marker, 'click', function () {
                this.map.setCenter(marker.getLatLng(), this.map.getZoom());
                this.map.searchCenter = this.map.getCenter(marker.getLatLng());
                this.map.activeMarker = marker;
            }.bindAsEventListener(this));
        }
    }
};
GoogleMaps.prototype.setAddress = function (address) {
    addressString = decodeURIComponent(address.street)+', '+decodeURIComponent(address.zip)+' '+decodeURIComponent(address.city);
    this.geocoder.getLocations(addressString, function (locations) {
        if (typeof locations.Placemark != 'undefined') {
            var point = new GLatLng(locations.Placemark[0].Point.coordinates[1], locations.Placemark[0].Point.coordinates[0]);
            var zoomLevel = locations.Placemark[0].AddressDetails.Accuracy * 2 < 5 ? 5 : locations.Placemark[0].AddressDetails.Accuracy * 2;
            if (point) {
                var markerOptions = {
                    id:address.id,
                    point:point,
                    color:'red',
                    data:address,
                    hoverText:this.map.myControl.createInfoSpan(decodeURIComponent(address.name)+', '+addressString)
                };
                var marker = this.markers.create(markerOptions);
                this.map.addOverlay(marker);
                this.map.setCenter(point, zoomLevel);
                this.map.searchCenter = this.map.getCenter(point);
            } else {
                alert('Adresse nicht gefunden.');
            }
        } else {
            alert('Adresse nicht gefunden.');
        }
    }.bindAsEventListener(this));
}
GoogleMaps.prototype.setMarker = function (address, color) {
    var addressString = address.street+', '+address.zip+' '+address.city;

    this.geocoder.getLocations(addressString, function (locations) {
        var point=false, zoomLevel = false;
        if (typeof locations.Placemark != 'undefined') {
            point = new GLatLng(locations.Placemark[0].Point.coordinates[1], locations.Placemark[0].Point.coordinates[0]);
            zoomLevel = locations.Placemark[0].AddressDetails.Accuracy * 2 < 5 ? 5 : locations.Placemark[0].AddressDetails.Accuracy * 2;
        }
        if (point) {
            var markerOptions = {
                id:address.id,
                point:point,
                color:'default',
                data:address,
                hoverText:this.map.myControl.createInfoSpan(address.name+', '+addressString)
            };
            var marker = this.markers.create(markerOptions);
            this.map.addOverlay(marker);
        } else {
            this.geocoder.getLocations(addressString, function (response) {
                //top.console.log(address, response);
            });
        }
    }.bindAsEventListener(this));
}
GoogleMaps.prototype.removeMarker = function (marker) {
    this.map.removeOverlay(marker);
}
GoogleMaps.prototype.highLiteMarker = function (id) {
    if (this.markers.get(id)) {
        var icon = this.map.getCurrentMapType().getName() == 'Karte' ? 'showMarkerIcon_Pulse' : 'showMarkerIcon';
        this.map.addOverlay(this.map[icon]);
        this.map[icon].setLatLng(this.markers.get(id).getLatLng());
    }
}
GoogleMaps.prototype.removeHighLite = function () {
    if (typeof this.map != 'undefined'){
        var icon = this.map.getCurrentMapType().getName() == 'Karte' ? 'showMarkerIcon_Pulse' : 'showMarkerIcon';
        this.map.removeOverlay(this.map[icon]);
    }
}
GoogleMaps.prototype.initInfoSlider = function () {
    this.map.infoSliderParent = document.createElement('div');
    this.map.controlContainerBorder = document.createElement('div');
    this.map.infoSliderParent.id = 'infoSliderParent';
    this.map.controlContainerBorder.id = 'controlContainerBorder';
    this.map.getContainer().appendChild(this.map.controlContainerBorder);
    var style = this.map.infoSliderParent.style;
    style.top = this.map.controlContainer.offsetHeight + 'px';
    style.height = '0px';

    this.map.getContainer().appendChild(this.map.infoSliderParent);
    this.map.infoSlider = document.createElement('div');
    this.map.infoSlider.id = "infoSlider";
    this.map.infoSlider.clear = function () {
        while (this.hasChildNodes()) {
            this.removeChild(this.firstChild);
        }
    }
}
GoogleMaps.prototype.animateInfoSlider = function (dir, text) {
    if (this.map.infoSlider.interval) {
        window.clearInterval(this.map.infoSlider.interval);
    }
    if (dir == 'in') {
        this.map.infoSlider.clear();
        this.map.infoSlider.text = this.map.infoSlider.appendChild(text);
        this.map.infoSliderParent.appendChild(this.map.infoSlider);

        var borderWidth = this.map.getContainer().offsetWidth-this.map.infoSlider.offsetWidth;
        this.map.controlContainerBorder.style.width = (borderWidth>0?borderWidth:0)+'px';
        this.map.infoSliderParent.style.width = this.map.infoSlider.offsetWidth+'px';

        this.map.infoSlider.interval = window.setInterval(function () {
            this.map.infoSliderParent.style.height = parseInt(this.map.infoSliderParent.style.height)+5+'px';
            if (parseInt(this.map.infoSliderParent.style.height) >= this.map.infoSlider.offsetHeight) {
                window.clearInterval(this.map.infoSlider.interval);
                this.map.infoSliderParent.style.height = this.map.infoSlider.offsetHeight+'px';
            }
        }.bind(this), 40);
    } else {
        this.map.infoSlider.interval = window.setInterval(function () {
       		var newHeight = (parseInt(this.map.infoSliderParent.style.height)-5) > 0 ? (parseInt(this.map.infoSliderParent.style.height)-5) : parseInt(this.map.infoSliderParent.style.height);
            this.map.infoSliderParent.style.height = newHeight+'px';

            if (parseInt(this.map.infoSliderParent.style.height) <= 5) {
                window.clearInterval(this.map.infoSlider.interval);
                this.map.infoSliderParent.style.height = '0px';
                this.map.infoSlider.clear();
                this.map.controlContainerBorder.style.width = '100%';
                this.map.infoSliderParent.style.width = '100%';
            }
        }.bind(this), 40);
    }
}

GoogleMaps.prototype.initRouteForm = function () {
    var container = this.map.getContainer();
    this.map.routeFormOverlay = document.createElement('div');
    this.map.routeFormOverlay.id = 'routeFormOverlay';
    var style = this.map.routeFormOverlay.style;
    style.top = this.map.controlContainer.offsetHeight + 'px';
    style.height = container.offsetHeight - this.map.controlContainer.offsetHeight + 'px';
    this.map.routeFormOverlay.opacity = 0;
    top.cssHandler.setOpacity(this.map.routeFormOverlay, this.map.routeFormOverlay.opacity);

    this.map.routeForm = this.buildRouteForm();
    this.map.routeForm.id = 'routeForm';
    style = this.map.routeForm.style;
    this.map.routeForm.maxPadding = '50';
    this.map.routeForm.maxWidth = container.offsetWidth - 2*this.map.routeForm.maxPadding;
    for (var i=0;i<this.map.routeForm.getElementsByTagName('FIELDSET').length;i++) {
        this.map.routeForm.getElementsByTagName('FIELDSET')[i].style.width = this.map.routeForm.maxWidth-20+'px';
    }
    style.top = this.map.controlContainer.offsetHeight + 'px';

    this.map.routeForm.state = false;
    this.map.routeForm.toggle = function (address, startaddress, info) {
        if (typeof this.map.routeFormOverlay.fadeInterval != 'undefined') {
            window.clearInterval(this.map.routeFormOverlay.fadeInterval);
        }
        if (typeof this.map.routeForm.effectInterval != 'undefined') {
            window.clearInterval(this.map.routeForm.effectInterval);
        }
        if (this.map.routeForm.state == false) {
            style.left = Math.floor(container.offsetWidth/2)+'px';
            style.width = '0px';
            container.appendChild(this.map.routeFormOverlay);
            this.map.routeFormOverlay.fade('in');
        } else {
            this.map.routeFormOverlay.fade('out');
            if (this.map.routeForm.parentNode) {
                this.map.routeForm.parentNode.removeChild(this.map.routeForm);
            }
        }
        this.map.routeForm.state = !this.map.routeForm.state;
        if (typeof address == 'object') {
            this.map.routeForm.toStreet.value = decodeURIComponent(address.street);
            this.map.routeForm.toZip.value = decodeURIComponent(address.zip);
            this.map.routeForm.toCity.value = decodeURIComponent(address.city);
        }
        if (typeof startaddress == 'object') {
            this.map.routeForm.street.value = decodeURIComponent(startaddress.street);
            this.map.routeForm.zip.value = decodeURIComponent(startaddress.zip);
            this.map.routeForm.city.value = decodeURIComponent(startaddress.city);
        }
    }.bind(this);
    this.map.routeFormOverlay.fade = function (a) {
        if (typeof this.fadeInterval != 'undefined') {
            window.clearInterval(this.fadeInterval);
            top.cssHandler.setOpacity(this.map.routeFormOverlay, a == 'in' ? 0 : .5);
        }
        this.map.routeFormOverlay.fadeInterval = window.setInterval(function () {
            if (a=='in') {
                this.map.routeFormOverlay.opacity += .1;
                top.cssHandler.setOpacity(this.map.routeFormOverlay, this.map.routeFormOverlay.opacity);
            } else {
                this.map.routeFormOverlay.opacity -= .1;
                top.cssHandler.setOpacity(this.map.routeFormOverlay, this.map.routeFormOverlay.opacity);
            }
            if (this.map.routeFormOverlay.opacity >= .5 || this.map.routeFormOverlay.opacity <= 0) {
                top.cssHandler.setOpacity(this.map.routeFormOverlay, this.map.routeFormOverlay.opacity <= 0 ? 0 : .5);
                window.clearInterval(this.map.routeFormOverlay.fadeInterval);
                this.map.routeFormOverlay.onfadeReady(a);
            }
        }.bind(this), 40)
    }.bindAsEventListener(this);
    this.map.routeFormOverlay.onfadeReady = function (a) {
        if (a=='in') {
            container.appendChild(this.map.routeForm);
            this.map.routeForm.showEffect(a);
        } else {
            if (this.map.routeFormOverlay.parentNode) {
                this.map.routeFormOverlay.parentNode.removeChild(this.map.routeFormOverlay);
            }
        }
    }.bindAsEventListener(this);
    this.map.routeForm.showEffect = function (a) {
        this.map.routeForm.effectInterval = window.setInterval(function () {
            if (a=='in') {
                this.map.routeForm.style.width = parseInt(this.map.routeForm.style.width) + 80 + 'px';
                this.map.routeForm.style.left = parseInt(this.map.routeForm.style.left) - 40 + 'px';
            } else {

            }
            if (parseInt(this.map.routeForm.style.width) >= this.map.routeForm.maxWidth) {
                window.clearInterval(this.map.routeForm.effectInterval);
                this.map.routeForm.style.width=this.map.routeForm.maxWidth+'px';
                this.map.routeForm.style.left=parseInt((container.offsetWidth - this.map.routeForm.maxWidth)/2)+'px';
            }
        }.bind(this),40);
    }.bindAsEventListener(this);
}
GoogleMaps.prototype.buildRouteForm = function () {
    var form = document.createElement('form');
    var fieldsetStart = form.appendChild(document.createElement('fieldset'));
    form.infoBox = document.createElement('div');
    form.infoBox.id = 'routeInfoBox';
    form.infoBox.set = function (string) {
        this.appendChild(document.createTextNode(string));
        form.insertBefore(this, fieldsetStart);
    }
    var legend = fieldsetStart.appendChild(document.createElement('legend'));
    legend.appendChild(document.createTextNode('Startadresse'));
    form.street = fieldsetStart.appendChild(this.createLabeledInputField('Straße:', {name:'street'})).getElementsByTagName('INPUT')[0];
    form.zip = fieldsetStart.appendChild(this.createLabeledInputField('Plz:', {name:'zip'})).getElementsByTagName('INPUT')[0];
    form.city = fieldsetStart.appendChild(this.createLabeledInputField('Ort:', {name:'city'})).getElementsByTagName('INPUT')[0];

    var fieldsetEnd = form.appendChild(document.createElement('fieldset'));
    legend = fieldsetEnd.appendChild(document.createElement('legend'));
    legend.appendChild(document.createTextNode('Zieladresse'));
    form.toStreet = fieldsetEnd.appendChild(this.createLabeledInputField('Straße:', {name:'toStreet'})).getElementsByTagName('INPUT')[0];
    form.toZip = fieldsetEnd.appendChild(this.createLabeledInputField('Plz:', {name:'toZip'})).getElementsByTagName('INPUT')[0];
    form.toCity = fieldsetEnd.appendChild(this.createLabeledInputField('Ort:', {name:'toCity'})).getElementsByTagName('INPUT')[0];

    fieldsetButton = form.appendChild(document.createElement('fieldset'));
    fieldsetButton.style.border = 'none';

    var button = document.createElement('INPUT');
    button.type='submit';
    button.value='Route berechnen';
    button.setAttribute('id','routeFormButton');

    fieldsetButton.appendChild(button);
    var that = this;
    form.onsubmit=function () {
        top.route(this);
        that.map.routeForm.toggle();
        return false;
    };
    return form;
}
GoogleMaps.prototype.createLabeledInputField = function (label, attributes) {
    var l = document.createElement('label');
    l.appendChild(document.createTextNode(label));
    GEvent.addDomListener(l, 'mouseover', function () {
        this.style.backgroundColor = '#b1b1b1';
    })
    GEvent.addDomListener(l, 'mouseout', function () {
        this.style.backgroundColor = '';
    })
    var f = document.createElement('input');
    for (var i in attributes) {
        f[i] = attributes[i];
    }
    f.value = '';
    f.onfocus = function () { this.select(); }

    l.appendChild(f);
    return l;
}



function MyControl() {
}

MyControl.prototype = new GControl();

MyControl.prototype.setHandler = function (handler) {
    this.mapHandler = handler;
}
MyControl.prototype.initialize = function(map) {
    var container = document.createElement("div");

    var routeDiv = document.createElement("div");
    routeDiv.className = 'button';
    routeDiv.style.background = 'url(images/buttons/route_dark.gif)';
    routeDiv.hoverText = this.createInfoSpan('Route suchen');
    container.appendChild(routeDiv);
    GEvent.addDomListener(routeDiv, "click", function() {
        map.routeForm.toggle();
    });

    var setCenterDiv = document.createElement("div");
    setCenterDiv.className = 'button';
    setCenterDiv.style.background = 'url(images/buttons/setCenter_dark.gif)';
    setCenterDiv.hoverText = this.createInfoSpan('Aktuelle Adresse zentrieren');
    container.appendChild(setCenterDiv);
    GEvent.addDomListener(setCenterDiv, "click", function() {
        map.setCenter(map.searchCenter);
    });

    var panLeftDiv = document.createElement("div");
    panLeftDiv.className = 'button';
    panLeftDiv.style.background = 'url(images/buttons/panLeft_dark.gif)';
    panLeftDiv.hoverText = this.createInfoSpan('Ansicht nach links Verschieben');
    container.appendChild(panLeftDiv);
    GEvent.addDomListener(panLeftDiv, "click", function() {
        map.panDirection(1,0);
    });

    var panRightDiv = document.createElement("div");
    panRightDiv.className = 'button';
    panRightDiv.style.background = 'url(images/buttons/panRight_dark.gif)';
    panRightDiv.hoverText = this.createInfoSpan('Ansicht nach rechts Verschieben');
    container.appendChild(panRightDiv);
    GEvent.addDomListener(panRightDiv, "click", function() {
        map.panDirection(-1,0);
    });

    var panUpDiv = document.createElement("div");
    panUpDiv.className = 'button';
    panUpDiv.style.background = 'url(images/buttons/panUp_dark.gif)';
    panUpDiv.hoverText = this.createInfoSpan('Ansicht nach oben Verschieben');
    container.appendChild(panUpDiv);
    GEvent.addDomListener(panUpDiv, "click", function() {
        map.panDirection(0,1);
    });

    var panDownDiv = document.createElement("div");
    panDownDiv.className = 'button';
    panDownDiv.style.background = 'url(images/buttons/panDown_dark.gif)';
    panDownDiv.hoverText = this.createInfoSpan('Ansicht nach unten Verschieben');
    container.appendChild(panDownDiv);
    GEvent.addDomListener(panDownDiv, "click", function() {
        map.panDirection(0,-1);
    });

    this.toggleZoomBoxDiv = document.createElement("div");
    this.toggleZoomBoxDiv.className = 'button';
    this.toggleZoomBoxDiv.style.background = 'url(images/buttons/toggleZoomBox_dark.gif)';
    this.toggleZoomBoxDiv.hoverText = this.createInfoSpan('Einschalten: Einen Rahmen um den anzuzeigenden Bereich ziehen und heranzoomen');
    container.appendChild(this.toggleZoomBoxDiv);
    GEvent.addDomListener(this.toggleZoomBoxDiv, "click", function() {
        map.zoomBox.toggle();
    });

    var zoomOutDiv = document.createElement("div");
    zoomOutDiv.className = 'button zoomButton';
    zoomOutDiv.style.background = 'url(images/buttons/zoomOut_dark.gif) no-repeat 0px 4px';
    zoomOutDiv.hoverText = this.createInfoSpan('Herauszoomen');
    container.appendChild(zoomOutDiv);
    GEvent.addDomListener(zoomOutDiv, "click", function() {
        map.zoomOut();
    });

    var sliderBGDiv = document.createElement('DIV');
    sliderBGDiv.hoverText = this.createInfoSpan('Zoomlevel einstellen');
    sliderBGDiv.id = 'sliderBg';
    var sliderBoundary = document.createElement('div');
    sliderBoundary.id='sliderBoundary';
    sliderBGDiv.appendChild(sliderBoundary);

    var sliderDiv = document.createElement('DIV');
    myOwnSliderOptions = {
        container:sliderBoundary,
        left:map.getZoom()*10,
        top:'3'
    };

    map.myOwnSlider = new GDraggableObject(sliderDiv, myOwnSliderOptions);
    GEvent.addListener(map.myOwnSlider, 'dragend', function () {
        var newZoomLevel = Math.round(parseFloat(map.myOwnSlider.left/10));
        map.setZoom(newZoomLevel);
        map.myOwnSlider.moveTo({x:newZoomLevel*10,y:0});
    })
    sliderDiv.id = 'slider';
    sliderBoundary.appendChild(sliderDiv);

    container.appendChild(sliderBGDiv);

    var zoomInDiv = document.createElement("div");
    zoomInDiv.className = 'button zoomButton';
    zoomInDiv.style.background = 'url(images/buttons/zoomIn_dark.gif) no-repeat 0px 4px';
    zoomInDiv.hoverText = this.createInfoSpan('Heranzoomen');
    container.appendChild(zoomInDiv);
    GEvent.addDomListener(zoomInDiv, "click", function() {
        map.zoomIn();
    });

    controlsUnderlay = map.controlContainer = document.createElement('DIV');

    controlsUnderlay.id='controlsUnderlay';
    map.getContainer().appendChild(controlsUnderlay);
    map.getContainer().appendChild(container);

    var that = this;
    for (var i=0;i<container.childNodes.length;i++) {
        GEvent.addDomListener(container.childNodes[i], "mouseover", function() {
            that.mapHandler.animateInfoSlider('in', this.hoverText);
        });
        GEvent.addDomListener(container.childNodes[i], "mouseout", function() {
            if (this.initAnimation)
                window.clearTimeout(this.initAnimation);
            that.mapHandler.animateInfoSlider('out');
        });
    }

    return container;
}
MyControl.prototype.createInfoSpan = function (strings, split, splitBy) {
    if (typeof strings == undefined || strings == '') return false;
    var infoSpan = document.createElement('span');
    splitBy = splitBy ? splitBy : ', ';
    split = typeof split != 'undefined' ? split : true;
    if (typeof strings == 'string' && split == true) {
        strings = strings.split(splitBy);
    }
    if (split == true){
        for (var i=0;i<strings.length;i++) {
            if (strings[i]=='' || strings[i].match(/^\s*$/)) continue;
            infoSpan.appendChild(document.createTextNode(strings[i]));
            infoSpan.appendChild(document.createElement('br'));
        }
    } else {
        infoSpan.appendChild(document.createTextNode(strings));
    }
    return infoSpan;
}

MyControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}

/*
MyBla = function () {
    console.log('Ich werde Instanziiert');
};

MyBla.prototype = new GControl();

MyBla.prototype.container = document.createElement('div');

MyBla.prototype.initialize = function (map) {
    this.container.style.border = '1px solid red';
    this.container.style.position = 'absolute';
    this.container.style.top = '100px';
    this.container.style.left = '100px';
    this.container.style.width = '100px';
    this.container.style.height = '100px';
    this.container.style.background = 'black';

    map.getContainer().appendChild(this.container);

    return this.container;
}


            that.map.addControl(new MyBla());
*/

