$(document).ready(function() {
    $('#news-pod li').click(function() {
        $(this).parent().children().removeClass('selected');
        $(this).addClass('selected');

        $('#content_left div.news-pod').hide();
        $('#'+$(this).attr('id').replace('-btn','-pod')).show();

        return false;
    });

    $('#music-heading, #theatre-heading, #events-heading, #comedy-heading, #books-heading, #exhibitions-heading, #movies-heading').click(function() {
        $(this).parent().parent().find('h3').removeClass('selected');
        $(this).addClass('selected');

        $('#whats-on ul.ae-content, #whats-on p.read-more').hide();
        $('#'+$(this).attr('id').replace('-heading','-content')).show().next().show("fast", function() {
            pos = $('#whats-on ul li ul:visible').position().top;
            if (pos > 78) {
                $('#whats-on ul li ul:visible').css('top', '-'+(pos-78)+'px');
            }
        });

        return false;
    });

    $('.dropdown_list').change(function() {
        if ($(this).val() != 'Select...') {
            window.location = '/'+$(this).val();
        }
    });

    if ($('#map').length == 1) {
        outputMap();
    }

    $("a[rel='external']").click(function() {
        this.target = "_blank";
    });
});

function outputMap() {
    if (GBrowserIsCompatible()) {
        address = $('#map').text();
        if (address != '') {
            $('#map').show();
            var map = new GMap2(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.setCenter(new GLatLng(-33.8671070938201, 151.207096675957), 12);
            var bounds = new GLatLngBounds();

            geocoder = new GClientGeocoder();
            if (geocoder) {
                geocoder.getLatLng(address, function(point) {
                    if (point) {
                        map.setCenter(point, 16);
                        map.addOverlay(new GMarker(point));
                        map.openInfoWindow(map.getCenter(), '<div class="map_info"><p><strong>'+$('#article h3:first').text()+'</strong><br />'+address+'</p></div>');
                    }
                });
            }
        }
    }
}