/**
 *  Amenities Map as Dialog [jQuery UI]
 *  Instantiates the jQuery UI "dialog" class on the amenities map.
 *  Last modified: 2010-05-10 {pf}
 */
function amenitiesMapDialog() {
    
    $('#amenitiesMap').dialog( {
        'autoOpen': false,
        'draggable': false,
        'modal': true,
        'resizable': false,
        'width': 1000,
        'height': 'auto'
    });
    
    //    Bind mailto links with overlay actions
    $('.amenitiesMap').click( function() {
        $('#amenitiesMap').dialog( 'open' );
        return false;
    });
    
    autoOpenModal();
    
}


/**
 *  Amenities Map
 *  Adds the markup necessary for the amenities map to the base of the
 *  current document.
 *  Last modified: 2010-05-10 {pf}
 */
function amenitiesMap() {
    
    if ( isIE7 == false ) {
		amenitiesInitialize();
		amenitiesMapDialog();
    }
    
}


/**
 *  Amenities Map Initialization [sic]
 *  Instantiates the Google Maps API on the amenities map after it's
 *  been added to the document.
 *  Last modified: 2010-05-10 {pf}
 */
function amenitiesInitialize() {
    
    if (GBrowserIsCompatible()) {
        
        var dimensions = new GSize(520,713);
        var mapOptions = {size:dimensions};
        var map = new GMap2(document.getElementById("amenitiesMapTarget"), mapOptions);
            map.setCenter(new GLatLng(52.451821, -1.72891), 15);
            map.setUIToDefault();
        
        // Add airport marker
        map.addOverlay(new GMarker(new GLatLng(52.45307, -1.73877)));
        
        // Area 1
        var polygon = new GPolygon([
            new GLatLng(52.456764, -1.71745),
            new GLatLng(52.456987, -1.71769),
            new GLatLng(52.457274, -1.71700),
            new GLatLng(52.457928, -1.71788),
            new GLatLng(52.457810, -1.71818),
            new GLatLng(52.457915, -1.71836),
            new GLatLng(52.456882, -1.72052),
            new GLatLng(52.456725, -1.72042),
            new GLatLng(52.456581, -1.72076),
            new GLatLng(52.456359, -1.72042),
            new GLatLng(52.455914, -1.72142),
            new GLatLng(52.455666, -1.72127),
            new GLatLng(52.455574, -1.72140),
            new GLatLng(52.454973, -1.72069),
            new GLatLng(52.454842, -1.72087),
            new GLatLng(52.453469, -1.71896),
            new GLatLng(52.453260, -1.71954),
            new GLatLng(52.453731, -1.72014),
            new GLatLng(52.452985, -1.72183),
            new GLatLng(52.453626, -1.72248),
            new GLatLng(52.452358, -1.72520),
            new GLatLng(52.451730, -1.72436),
            new GLatLng(52.451508, -1.72479),
            new GLatLng(52.449664, -1.72271),
            new GLatLng(52.450344, -1.72114),
            new GLatLng(52.450854, -1.72168),
            new GLatLng(52.451259, -1.72063),
            new GLatLng(52.450788, -1.71996),
            new GLatLng(52.451978, -1.71760),
            new GLatLng(52.452985, -1.71874),
            new GLatLng(52.453299, -1.71816),
            new GLatLng(52.452462, -1.71700),
            new GLatLng(52.453351, -1.71531),
            new GLatLng(52.453731, -1.71589),
            new GLatLng(52.453927, -1.71550),
            new GLatLng(52.453495, -1.71492),
            new GLatLng(52.453835, -1.71421),
            new GLatLng(52.454031, -1.71449),
            new GLatLng(52.454594, -1.71346),
            new GLatLng(52.455378, -1.71456),
            new GLatLng(52.454868, -1.71565),
            new GLatLng(52.454672, -1.71537),
            new GLatLng(52.454306, -1.71612),
            new GLatLng(52.454319, -1.71733),
            new GLatLng(52.455875, -1.71906)
        ], "#142589", 0, 0, "#142589", 0.8);
        map.addOverlay(polygon); // DRAW POLYGON
        
        // Area 2
        var polygon = new GPolygon([
            new GLatLng(52.449868, -1.722152),
            new GLatLng(52.449698, -1.722463),
            new GLatLng(52.448887, -1.721519),
            new GLatLng(52.449212, -1.720697),
            new GLatLng(52.449771, -1.721421),
            new GLatLng(52.449600, -1.721755)
        ], "#142589", 0, 0, "#142589", 0.8);
        map.addOverlay(polygon); // DRAW POLYGON
        
        // Area 3
        var polygon = new GPolygon([
            new GLatLng(52.449123, -1.72042),
            new GLatLng(52.448560, -1.72157),
            new GLatLng(52.447776, -1.72052),
            new GLatLng(52.448325, -1.71934)
        ], "#142589", 0, 0, "#142589", 0.8);
        map.addOverlay(polygon); // DRAW POLYGON
        
        // Station
        var polygon = new GPolygon([
            new GLatLng(52.451209, -1.72531),
            new GLatLng(52.450901, -1.72615),
            new GLatLng(52.450110, -1.72497),
            new GLatLng(52.450319, -1.72425)
        ], "#000000", 0, 0, "#000000", 0.8);
        map.addOverlay(polygon); // DRAW POLYGON
        
        // Track
        var polygon = new GPolygon([
            new GLatLng(52.450670, -1.725938),
            new GLatLng(52.450429, -1.726726),
            new GLatLng(52.450466, -1.726911),
            new GLatLng(52.450535, -1.727094),
            new GLatLng(52.450819, -1.727461),
            new GLatLng(52.451525, -1.728352),
            new GLatLng(52.451947, -1.728875),
            new GLatLng(52.452179, -1.729261),
            new GLatLng(52.452880, -1.730538),
            new GLatLng(52.453191, -1.731141),
            new GLatLng(52.453292, -1.731608),
            new GLatLng(52.453295, -1.731973),
            new GLatLng(52.453086, -1.732590),
            new GLatLng(52.452988, -1.732526),
            new GLatLng(52.453194, -1.732037),
            new GLatLng(52.453243, -1.731775),
            new GLatLng(52.453200, -1.731388),
            new GLatLng(52.452789, -1.730568),
            new GLatLng(52.451971, -1.729076),
            new GLatLng(52.450552, -1.727284),
            new GLatLng(52.450379, -1.726920),
            new GLatLng(52.450301, -1.726255),
            new GLatLng(52.450471, -1.725675)
        ], "#c72137", 0, 0, "#c72137", 0.8);
        map.addOverlay(polygon); // DRAW POLYGON
        
        // Terminal 1
        var polygon = new GPolygon([
            new GLatLng(52.453966, -1.733311),
            new GLatLng(52.453456, -1.734577),
            new GLatLng(52.453914, -1.735157),
            new GLatLng(52.453025, -1.737388),
            new GLatLng(52.452802, -1.737045),
            new GLatLng(52.453456, -1.735371),
            new GLatLng(52.452462, -1.734213),
            new GLatLng(52.453301, -1.732162),
            new GLatLng(52.453543, -1.732655),
            new GLatLng(52.453438, -1.732795)
            ], "#1e86be", 0, 0, "#1e86be", 0.8);
        map.addOverlay(polygon); // DRAW POLYGON
        
        // Terminal 2
        var polygon = new GPolygon([    
            new GLatLng(52.45252, -1.73370),
            new GLatLng(52.45235, -1.73407),
            new GLatLng(52.45139, -1.73301),
            new GLatLng(52.45069, -1.73483),
            new GLatLng(52.449964, -1.73413),
            new GLatLng(52.45089, -1.73184)
        ], "#1e86be", 0, 0, "#1e86be", 0.8);
        map.addOverlay(polygon); // DRAW POLYGON
        
        /* t1 */
        var icon = new GIcon(G_DEFAULT_ICON);
            icon.image = "/img/googlemap/m-t1.png";
            icon.iconSize = new GSize(31, 34);
            icon.shadowSize = new GSize(0, 0);
        map.addOverlay(new GMarker(new GLatLng(52.452959, -1.73404), { icon:icon,clickable:false }));
        
        /* t2 */
        var icon = new GIcon(G_DEFAULT_ICON);
            icon.image = "/img/googlemap/m-t2.png";
            icon.iconSize = new GSize(31, 34);
            icon.shadowSize = new GSize(0, 0);
        map.addOverlay(new GMarker(new GLatLng(52.450749, -1.73393), { icon:icon,clickable:false }));
        
        /* track */
        var icon = new GIcon(G_DEFAULT_ICON);
            icon.image = "/img/googlemap/m-ar.png";
            icon.iconSize = new GSize(31, 34);
            icon.shadowSize = new GSize(0, 0);
        map.addOverlay(new GMarker(new GLatLng(52.450352, -1.72684), { icon:icon,clickable:false }));
        
        /* rail */
        var icon = new GIcon(G_DEFAULT_ICON);
            icon.image = "/img/googlemap/m-rail.png";
            icon.iconSize = new GSize(31, 34);
            icon.shadowSize = new GSize(0, 0);
        map.addOverlay(new GMarker(new GLatLng(52.450581, -1.72513), { icon:icon,clickable:false }));
        
        /* NEC */
        var icon = new GIcon(G_DEFAULT_ICON);
            icon.image = "/img/googlemap/m-nec.png";
            icon.iconSize = new GSize(31, 34);
            icon.shadowSize = new GSize(0, 0);
        map.addOverlay(new GMarker(new GLatLng(52.451782, -1.72230), { icon:icon,clickable:false }));
        
        /* LG */
        var icon = new GIcon(G_DEFAULT_ICON);
            icon.image = "/img/googlemap/m-lg.png";
            icon.iconSize = new GSize(31, 34);
            icon.shadowSize = new GSize(0, 0);
        map.addOverlay(new GMarker(new GLatLng(52.448264, -1.72057), { icon:icon,clickable:false }));
        
    }
    
}

$(document).ready( function() {
    amenitiesMap();
});
