﻿$(function() {

    var myNeighbourhoodSelected = "my_neighbourhood_councillors";
    $("#my_neighbourhood_councillors").data("state", "down");
    $("#my_neighbourhood_planning").hide().data("state", "up");
    $("#my_neighbourhood_committee").hide().data("state", "up");
    $("#my_neighbourhood_whatson").hide().data("state", "up");
    $("#my_neighbourhood_news").hide().data("state", "up");

    $("#my_neighbourhood_accordion h3").click(function() {
        var selected_feed = $(this).next();
        $(selected_feed).slideToggle();
        if ($(selected_feed).attr("id") != myNeighbourhoodSelected && $("#" + myNeighbourhoodSelected).data("state") != "up") {
            $("#" + myNeighbourhoodSelected).slideToggle().data("state", "up");
        }
        myNeighbourhoodSelected = $(selected_feed).attr("id");
        $(selected_feed).data("state", $(selected_feed).data("state") == "up" ? "down" : "up");
    });

    $("#my_neighbourhood_change").text($("#my_neighbourhood_change A").text());
    $("#my_neighbourhood_change A").remove();

    $("#my_neighbourhood_reset").text($("#my_neighbourhood_reset A").text());
    $("#my_neighbourhood_reset A").remove();

    $("#my_neighbourhood_change").click(function() {
        $("#my_neighbourhood_postcode").css("display", "block");
        $("#my_neighbourhood_info").css("display", "none");
    });

    $("#my_neighbourhood_reset").click(function() {
        $("#my_neighbourhood_postcode").css("display", "block");
        $("#my_neighbourhood_info").css("display", "none");
        $("#my_neighbourhood_accordion").css("display", "none");
        $("#my_neighbourhood_postcode").find("input[type='text']").val("");
        var cookieOptions = { path: '/', expires: 10 };
        $.cookie("CWAC.Postcode", null, cookieOptions);
        $.cookie("CWAC.MyNeighbourhood.Display", null, cookieOptions);        
    });

});
