if (document.location.pathname == '/waldweihnacht/anfahrt/index.html' || document.location.pathname == '/waldweihnacht/anfahrt/') {
    document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAy-MfgKvKUTrUdcDeLLAi0RSQDxhtvFpF4EkYjAXfMyNuEExAVRQap5zchVEM0CPQLr8Y5TiwfRW5jQ" type="text/javascript"></script>');
}
runOnLoad(function(){
	Ext.ux.Lightbox.register('a.lightbox', true);
    var t = Ext.get('inter');
    if (t) {
        var imgs = t.select('img');
        imgs.each(function(im){
            if (im.dom.src.match(/\/thm\//)) {
                im.on('mouseover', function(ev, el){
                    if (!el) return;
                    Ext.MessageBox.show({
                        title: '',
                        msg: '<center><img onload="resizeBox(this);" src="' + el.src.replace(/\/thm\//, '/media/') + '" width="320" alt="" /></center>',
                        modal: false,
                        width: 400,
                        height: 400,
                        closable: false
                    });
                    var pos = getPos(ev);
                    Ext.MessageBox.getDialog().moveTo(pos.x, pos.y);
                }, im);
                im.on('mouseout', function(ev, el){
                    if (!el) return;
                    Ext.MessageBox.hide();
                }, im);
                im.on('mousemove', function(ev, el){
                    if (!el) return;
                    var pos = getPos(ev);
                    Ext.MessageBox.getDialog().moveTo(pos.x, pos.y);
                }, im);
            }
            if (im.dom.src.match(/\/media\/med_/)) {
            	im.on('mouseover', function(ev, el){
            		if (!el) return;
            		Ext.MessageBox.show({
            			title: '',
            			msg: '<center><img onload="resizeBox(this);" src="' + el.src.replace(/\/media\/med_/, '/org/med_') + '" width="320" alt="" /></center>',
            			modal: false,
            			width: 400,
            			height: 400,
            			closable: false
            		});
            		var pos = getPos(ev);
            		Ext.MessageBox.getDialog().moveTo(pos.x, pos.y);
            	}, im);
            	im.on('mouseout', function(ev, el){
            		if (!el) return;
            		Ext.MessageBox.hide();
            	}, im);
            	im.on('mousemove', function(ev, el){
            		if (!el) return;
            		var pos = getPos(ev);
            		Ext.MessageBox.getDialog().moveTo(pos.x, pos.y);
            	}, im);
            }
        });
    }
    var g = Ext.get('gmaps');
    if (g) {
        initialize();
    }
});
var resizeBox = function(img) {
	var d = Ext.MessageBox.getDialog();
	d.resizeTo(d.width, img.height+50);
};
var getPos = function(ev){
    var pos = {
        x: 0,
        y: 0
    };
    pos.x = ev.xy[0] + 50;
    var box = Ext.MessageBox.getDialog().el.getBox();
    pos.y = ev.xy[1] - box.height;
    if(pos.y < 0) {
        pos.y = 100;
    }
    return(pos);
};

var verkehrsfuehrung = function() {
    Ext.MessageBox.show({
        title: '',
        msg: '<center><img src="/images/ww/verkehrsfuehrung.gif" width="640" height="483" alt=""/></center>',
        modal: true,
        width: 660,
        height: 503,
        closable: true
    });
}

var gdir;
var marker;
function initialize(){
    if (GBrowserIsCompatible()) {
        var point = new GPoint(9.526834, 50.105752);
        var map = new GMap2(document.getElementById("gmaps"));
        map.addControl(new GMenuMapTypeControl());
        map.addControl(new GLargeMapControl());
        map.addControl(new GOverviewMapControl());
        map.enableScrollWheelZoom();
        map.setCenter(new GLatLng(point.y, point.x), 11);
        var icon = new GIcon();
        icon.iconSize = new GSize(52, 33);
        icon.iconAnchor = new GPoint(0, 16);
        icon.infoWindowAnchor = new GPoint(0, 0);
        icon.image = 'http://www.bayrische-schanz.de/images/ww/glogo.gif';
        marker = new GMarker(point, icon);
        var txt = ['<strong>SPESSART WaldWeihnacht</strong>', '', 'Waldschänke Bayrische Schanz', 'Schanzstraße 85', '97816 Lohr-Ruppertshütten', 'Tel 0 93 55 - 6 18', 'Fax 0 93 55 - 97 69 36', '<a href="mailto:info@spessart-waldweihnacht.de">info@spessart-waldweihnacht.de</a>', '<a href="http://www.spessart-waldweihnacht.de">www.spessart-waldweihnacht.de</a>'/*, '<br><a href="#" onclick="verkehrsfuehrung(); return(false);"><img src="/images/ww/parken.gif" width="16" height="16" alt="" border="0" style="vertical-align:middle;">&nbsp;Verkehrsf&uuml;hrung</a>'*/];
        txt = '<div style="color:#000000">' + txt.join('<br />') + '</div>';
        GEvent.addListener(marker, "click", function(){
            marker.openInfoWindowHtml(txt);
        });
        map.addOverlay(marker);
        marker.openInfoWindowHtml(txt);
        gdir = new GDirections(map, document.getElementById("directions"));
        GEvent.addListener(gdir, "error", handleErrors);
    }
}

function setDirections(fromAddress){
    gdir.load("from: " + fromAddress + " to: Bayrische Schanz, Fellen", {
        "locale": "de"
    });
    marker.closeInfoWindow();
}

function handleErrors(){
    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS) 
        alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR) 
        alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY) 
        alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
    else if (gdir.getStatus().code == G_GEO_BAD_KEY) 
        alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST) 
        alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
    else 
        alert("An unknown error occurred.");
}

