$(function(){
    $("li:last-child").addClass("last-child");
    $("li:first-child").addClass("first-child");
    if ($('#slideshow img').length > 1) {
        $('#slideshow').jshowoff({controls: false, links: false, speed: 7000}); 
    } else {
        $('#slideshow').css("height", "auto");
    }

    $('#mapcategories').bind('change', function () {
        var url = $(this).val(); // get selected value
        if (url) { // require a URL
            window.location = url; // redirect
        }
        return false;
    });
    $("a.listing_infobox").click(function(e) {
        //console.log(e);
        e.preventDefault();
        id = $(this).data("listing-id");
        //console.log(id);
        //console.log(map.entities);
        for (i = 0; i <= map.entities.getLength(); i++) {
            listing = map.entities.get(i)
            if (listing.id == id) {
                //console.log(listing);
                e.target = listing;
                Microsoft.Maps.Events.invoke(listing,"click", e);
                break;
            }
        }
    });

    $('.resident_news').click(function(e) {
        if ($(this).is(":checked")) {
            $('.resAddress').show();
        } else {
            $('.resAddress').hide();
        }
    });
    if ($('.resident_news').is(':checked')) {
        $('.resAddress').show();
    }
    $('#newsletterLink').click(function(e) {
        $('#newsletterSignup').css('left', e.pageX - 150).fadeToggle();
        return false;
    });
    $('#newsletterSignup .cancel').click(function(e) {
        $('#newsletterSignup').fadeToggle();
        return false;
    });
    
});

