var initMap = function (venueId) {
    if (!GBrowserIsCompatible()) {
        return;
    }
    $j.getJSON("/index.php?c=venues&a=get-venue&id=" + venueId, addMarker);
    $j(document.body).unload(GUnload());
};
var addMarker = function (venue) {
    if (!venue) {
        return;
    }
    var venuePoint = new GLatLng(venue.latitude, venue.longitude);
    var map = new GMap2(document.getElementById("mapWrapper"));
    map.setCenter(venuePoint, 15);
    map.addControl(new GLargeMapControl3D());
    map.addControl(new GOverviewMapControl());
    map.addControl(new GMapTypeControl());
    var tempMark = createMarker(venue, venuePoint);
    map.addOverlay(tempMark);
    tempMark.openInfoWindowTabsHtml(infoTabs);
};
var createMarker = function (venue, point) {
    var customIcon = new GIcon();
    customIcon.image = "http://www.etcvenues.co.uk/images/pink-map-locator.png";
    customIcon.iconSize = new GSize(24, 24);
    customIcon.iconAnchor = new GPoint(12, 12);
    customIcon.infoWindowAnchor = new GPoint(12, 1);
    var marker = new GMarker(point, {
        icon: customIcon
    });
    infoTabs = [new GInfoWindowTab("Info", '<div class="gMapBubble"><p><img src="/images/get/' + venue.mapImageId + '" width="265" height="75" /></p><p><strong>' + venue.name + "</strong><br />" + venue.address1 + ", " + venue.town + ", " + venue.postcode + "</p><p><strong>Sales: </strong>" + venue.telephone_sales + '<br /><strong>Switchboard: </strong>' + venue.telephone_switchboard + '<br /><strong>Email: </strong><a href="mailto:' + venue.email + '" title="Email ' + venue.name + '">' + venue.email + "</a></p></div>"), new GInfoWindowTab("Directions", '<div class="gMapBubble">' + venue.directions + "</div>"), new GInfoWindowTab("Plan Route", '<div class="gMapBubble"><h4>walking directions...</h4><p>Enter your starting point (e.g. postcode or tube station) to get walking directions to ' + venue.name + '.</p><form action="http://www.walkit.com/walkit_pipe.php" target="_blank" method="post" id="walkit_form"><input type="hidden" name="walkit_to" value="' + venue.latitude + ',' + venue.longitude + '" id="walkit_to" /><input type="hidden" name="walkit_city" value="' + venue.walkitCity + '" id="walkit_city" /><input type="hidden" name="walkit_to_id" value="' + venue.walkitId + '" id="walkit_to_id" /><input type="hidden" name="referid" value="6geo07o1as08kwg48sg00wgc0" id="referid" /><input type="hidden" name="refproprid" value="0" id="refproprid" /><input name="walkit_from" type="text" class="inputField" id="walkit_from" /><input name="walkit_go" value="Go" type="submit" id="Button1" /></form><h4>driving directions...</h4><p>Get driving directions to the ' + venue.name + ' simply by entering your postcode below</p><form action="/" id="directionsForm" name=directionsForm" method="post"><input class="inputField" type="text" id="postcode"  onKeyPress="return disableEnterKey(event)"><input type="hidden" id="destination" name="destinaton" value="' + venue.latitude + ',' + venue.longitude + '" /><input type="button" onclick="getDirections();" value="Go"></form></div>')];
    GEvent.addListener(marker, "click", function () {
        marker.openInfoWindowTabsHtml(infoTabs);
    });
    return marker;
};
