// DOM ready!
$(function() {
    if (undefined === window.HighVisibility) {
        window.HighVisibility = false;
    }
    
    // Use the cookie plugin
    $.fn.EasyWidgets({
        behaviour: {
            useCookies: true
        }
    });
});


// EFFECTS

$(function(){
    $.fn.EasyWidgets({
        effects : {
            effectDuration : 200,
            widgetShow : 'fade',
            widgetHide : 'fade',
            widgetClose : 'fade',
            widgetExtend : 'fade',
            widgetCollapse : 'fade',
            widgetOpenEdit : 'fade',
            widgetCloseEdit : 'fade',
            widgetCancelEdit : 'fade'
        }
    });
});

//CONFIRM ON ADD WIDGETS
var EASettings = {}

// ADD WIDGETS
$(function() {
    $.fn.EasyWidgets(EASettings);

    if (NoCookieSetUpFlag == true) {
        groupWidgets('Residents');
        setWidgetsToBoxes();
    } else {
        setBoxesToWidgets();
    }
});

function AddWidget(url, placeId){
    $.get(url, function(html){
        $.fn.AddEasyWidget(html, placeId, EASettings);
    });
}

$(function(){

    // Very basic usage
    $.fn.EasyWidgets({
        callbacks : {
            onClose : function(link, widget){
                alert(widget.attr('id') + ' has been removed.')
            }
        }
    });
});


// EVERTHING ELSE!


//set an array to link checkbox buttons to widgets
CreateWidgetIndex();

function CreateWidgetIndex() {

    WidgetIndex = new Array(20)
    WidgetIndex[0] = new Array(2)
    WidgetIndex[0][0] = "input1"
    WidgetIndex[0][1] = "Events"
    WidgetIndex[1] = new Array(2)
    WidgetIndex[1][0] = "input2"
    WidgetIndex[1][1] = "EducationWidget"
    WidgetIndex[2] = new Array(2)
    WidgetIndex[2][0] = "input3"
    WidgetIndex[2][1] = "RateThisPageWidget"
    WidgetIndex[3] = new Array(2)
    WidgetIndex[3][0] = "input4"
    WidgetIndex[3][1] = "Incidents"
    WidgetIndex[4] = new Array(2)
    WidgetIndex[4][0] = "input5"
    WidgetIndex[4][1] = "Maps"
    WidgetIndex[5] = new Array(2)
    WidgetIndex[5][0] = "input6"
    WidgetIndex[5][1] = "ContactsWidget"
    WidgetIndex[6] = new Array(2)
    WidgetIndex[6][0] = "input7"
    WidgetIndex[6][1] = "Newsletters"
    WidgetIndex[7] = new Array(2)
    WidgetIndex[7][0] = "input8"
    WidgetIndex[7][1] = "RecentUpdates"
    WidgetIndex[8] = new Array(2)
    WidgetIndex[8][0] = "input9"
    WidgetIndex[8][1] = "MySafetyWidget"
    WidgetIndex[9] = new Array(2)
    WidgetIndex[9][0] = "input10"
    WidgetIndex[9][1] = "Weather"
    WidgetIndex[10] = new Array(2)
    WidgetIndex[10][0] = "input11"
    WidgetIndex[10][1] = "Jobs"
    WidgetIndex[11] = new Array(2)
    WidgetIndex[11][0] = "input12"
    WidgetIndex[11][1] = "OurVideos"
    WidgetIndex[12] = new Array(2)
    WidgetIndex[12][0] = "input13"
    WidgetIndex[12][1] = "Polls"
    WidgetIndex[13] = new Array(2)
    WidgetIndex[13][0] = "input14"
    WidgetIndex[13][1] = "Blogs"
    WidgetIndex[14] = new Array(2)
    WidgetIndex[14][0] = "input15"
    WidgetIndex[14][1] = "FreedomOfInformation"
    WidgetIndex[15] = new Array(2)
    WidgetIndex[15][0] = "input16"
    WidgetIndex[15][1] = "PressReleases"
    WidgetIndex[16] = new Array(2)
    WidgetIndex[16][0] = "input17"
    WidgetIndex[16][1] = "CadetsWidget"
    WidgetIndex[17] = new Array(2)
    WidgetIndex[17][0] = "input18"
    WidgetIndex[17][1] = "FireStations"
    WidgetIndex[18] = new Array(2)
    WidgetIndex[18][0] = "input19"
    WidgetIndex[18][1] = "MostPopular"
    
    Sets = new Array(5)
    Sets['Business'] = new Array(16);
    Sets['Business'][0] = true; //features
    Sets['Business'][1] = false;//education
    Sets['Business'][2] = true;//rate
    Sets['Business'][3] = true;//incidents
    Sets['Business'][4] = true;//map of incidents
    Sets['Business'][5] = true;//contacts
    Sets['Business'][6] = false;//newsletters
    Sets['Business'][7] = true;//Recent Updates
    Sets['Business'][8] = true;//safety
    Sets['Business'][9] = false;//weather
    Sets['Business'][10] = false;//jobs
    Sets['Business'][11] = true;//videos
    Sets['Business'][12] = false;//polls
    Sets['Business'][13] = false;//blogs
    Sets['Business'][14] = true;//Freedom of info
    Sets['Business'][15] = true;//press releases
    Sets['Business'][16] = false; //cadets
    Sets['Business'][17] = true; //fire stations
    Sets['Business'][18] = true; //Most Popular

    Sets['Residents'] = new Array(16);
    Sets['Residents'][0] = true; //features
    Sets['Residents'][1] = true; //education
    Sets['Residents'][2] = true; //rate
    Sets['Residents'][3] = true; //incidents
    Sets['Residents'][4] = true; //map of incidents
    Sets['Residents'][5] = true; //contacts
    Sets['Residents'][6] = true; //newsletters
    Sets['Residents'][7] = true; //Recent Updates
    Sets['Residents'][8] = true; //safety
    Sets['Residents'][9] = true; //weather
    Sets['Residents'][10] = true; //jobs
    Sets['Residents'][11] = true; //videos
    Sets['Residents'][12] = true; //polls
    Sets['Residents'][13] = true; //blogs
    Sets['Residents'][14] = true; //Freedom of info
    Sets['Residents'][15] = true; //press releases
    Sets['Residents'][16] = true; //cadets
    Sets['Residents'][17] = true; //fire stations
    Sets['Residents'][18] = true; //Most Popular

    Sets['Visitors'] = new Array(16);
    Sets['Visitors'][0] = true; //features
    Sets['Visitors'][1] = true; //education
    Sets['Visitors'][2] = true; //rate
    Sets['Visitors'][3] = true; //incidents
    Sets['Visitors'][4] = true; //map of incidents
    Sets['Visitors'][5] = true; //contacts
    Sets['Visitors'][6] = true; //newsletters
    Sets['Visitors'][7] = true; //Recent Updates
    Sets['Visitors'][8] = true; //safety
    Sets['Visitors'][9] = true; //weather
    Sets['Visitors'][10] = true; //jobs
    Sets['Visitors'][11] = true; //videos
    Sets['Visitors'][12] = true; //polls
    Sets['Visitors'][13] = true; //blogs
    Sets['Visitors'][14] = true; //Freedom of info
    Sets['Visitors'][15] = true; //press releases
    Sets['Visitors'][16] = true; //cadets
    Sets['Visitors'][17] = true; //fire stations
    Sets['Visitors'][18] = true; //Most Popular

    Sets['YP'] = new Array(16);
    Sets['YP'][0] = true; //features
    Sets['YP'][1] = true; //education
    Sets['YP'][2] = true; //rate
    Sets['YP'][3] = true; //incidents
    Sets['YP'][4] = false; //map of incidents
    Sets['YP'][5] = true; //contacts
    Sets['YP'][6] = false; //newsletters
    Sets['YP'][7] = true; //Recent Updates
    Sets['YP'][8] = true; //safety
    Sets['YP'][9] = true; //weather
    Sets['YP'][10] = false; //jobs
    Sets['YP'][11] = true; //videos
    Sets['YP'][12] = true; //polls
    Sets['YP'][13] = true; //blogs
    Sets['YP'][14] = false; //Freedom of info
    Sets['YP'][15] = false; //press releases
    Sets['YP'][16] = true; //cadets
    Sets['YP'][17] = true; //fire stations
    Sets['YP'][18] = true; //Most Popular
    
    
    Sets['Kids'] = new Array(16);
    Sets['Kids'][0] = true; //features
    Sets['Kids'][1] = true; //education
    Sets['Kids'][2] = false; //rate
    Sets['Kids'][3] = false; //incidents
    Sets['Kids'][4] = false; //map of incidents
    Sets['Kids'][5] = false; //contacts
    Sets['Kids'][6] = false; //newsletters
    Sets['Kids'][7] = false; //Recent Updates
    Sets['Kids'][8] = false; //safety
    Sets['Kids'][9] = true; //weather
    Sets['Kids'][10] = false; //jobs
    Sets['Kids'][11] = true; //videos
    Sets['Kids'][12] = false; //polls
    Sets['Kids'][13] = false; //blogs
    Sets['Kids'][14] = false; //Freedom of info
    Sets['Kids'][15] = false; //press releases
    Sets['Kids'][16] = true; //cadets
    Sets['Kids'][17] = true; //fire stations
    Sets['Kids'][18] = true; //Most Popular
}

function DisplayWidgetAudience() {
    var BusinessFlag = true;
    var ResidentsFlag = true;
    var VisitorsFlag = true;
    var YPFlag = true;
    var KidsFlag = true;
    var AllFlag = true;
    
    //alert("GO");
    for (var i in WidgetIndex) {
        //Audience update code
        if ($('#' + WidgetIndex[i][0]).attr('checked') == false) {
            AllFlag = false;
        }

        if ($('#' + WidgetIndex[i][0]).attr('checked') != Sets['Business'][i]) BusinessFlag = false;
        if ($('#' + WidgetIndex[i][0]).attr('checked') != Sets['Residents'][i]) ResidentsFlag = false;
        if ($('#' + WidgetIndex[i][0]).attr('checked') != Sets['Visitors'][i]) VisitorsFlag = false;
        if ($('#' + WidgetIndex[i][0]).attr('checked') != Sets['YP'][i]) YPFlag = false;
        if ($('#' + WidgetIndex[i][0]).attr('checked') != Sets['Kids'][i]) KidsFlag = false;

        
    }
    if (AllFlag == true) {
        $("#AudienceContent").html("Audience: All");
    } else if (BusinessFlag == true) {
        $("#AudienceContent").html("Audience: Business");
    } else if (ResidentsFlag == true) {
        $("#AudienceContent").html("Audience: Residents");
    } else if (VisitorsFlag == true) {
        $("#AudienceContent").html("Audience: Visitors");
    } else if (YPFlag == true) {
        $("#AudienceContent").html("Audience: Young People");
    } else if (KidsFlag == true) {
        $("#AudienceContent").html("Audience: Kids");
    } else{
        $("#AudienceContent").html("Audience: Custom");
    }
    
}

function groupWidgets(grouping){
    for (var i in WidgetIndex) {
        if (Sets[grouping][i] == true) {
            $('#' + WidgetIndex[i][0]).parent().addClass("selected");
            $('#' + WidgetIndex[i][0]).parent().find(":checkbox").attr("checked", "checked");
        } else {
            $('#' + WidgetIndex[i][0]).parent().removeClass("selected");
            $('#' + WidgetIndex[i][0]).parent().find(":checkbox").removeAttr("checked");
        }
        
    }
    //setWidgetsToBoxes();
}

// jQuery Expandable Panel for add Homepageitems
jQuery(function() {



    $("#items").hide();
    $("#additems, #Audience").toggle(function(event) {
        event.preventDefault();
        //$(this).addClass("active");
        $("#additems").addClass("dropdownactive");
    }, function() {
        //$(this).removeClass("active");
        $("#additems").removeClass("dropdownactive");
    });


    $("#additems, .cancelit, #Audience").click(function(event) {
        event.preventDefault();
        setBoxesToWidgets()
        $("#items").slideToggle("slow");

    });

    $(".sendit").click(function(event) {
        event.preventDefault();
        setWidgetsToBoxes();
        $("#items").slideToggle("slow");

    });

    $("#resethomepage").click(function(event) {
        event.preventDefault();
        //render all boxes checked;
        for (var i in WidgetIndex) {
            $('#' + WidgetIndex[i][0]).parent().addClass("selected");
            $('#' + WidgetIndex[i][0]).parent().find(":checkbox").attr("checked", "checked");
        }
        setWidgetsToBoxes();
        $.fn.ResetpositionWidgets();
    });


});

//Add Items to Home Page Fancy Checkboxes


$(document).ready(
    function() {


        /*$("input[type=checkbox][checked]").each(
            function() {
                $(this).parent().addClass("selected");
                $(this).parent().find(":checkbox").attr("checked", "checked");
            }
        );*/

        $(".checklist .checkbox-select").click(
            function(event) {
                event.preventDefault();
                $(this).parent().addClass("selected");
                $(this).parent().find(":checkbox").attr("checked", "checked");                            
            }
        );

        $(".checklist .checkbox-deselect").click(
            function(event) {
                event.preventDefault();
                $(this).parent().removeClass("selected");
                $(this).parent().find(":checkbox").removeAttr("checked");               
            }
        );

    }
);


function setWidgetsToBoxes() {
    //var setting = ""; /*Array;
    /*setting["behaviour"] = Array;
    setting["behaviour"]["useCookies"] = true;*/
    
    for (var i in WidgetIndex) {

        if ($('#' + WidgetIndex[i][0]).attr('checked') == true) {
            
            var widget = $('#' + WidgetIndex[i][1]);
            if (widget.css('display') == 'none') {
                $.fn.ShowEasyWidget(WidgetIndex[i][1], "");
                PostBack(WidgetIndex[i][1])
            } else {
                $.fn.ShowEasyWidget(WidgetIndex[i][1], "");
            }
            
        }else{
            $.fn.HideEasyWidget(WidgetIndex[i][1], "");
        }
    }
    DisplayWidgetAudience()
   
}

function setBoxesToWidgets() {
    for (var i in WidgetIndex) {
        //alert(WidgetIndex[i][0]);
        var widget = $('#' + WidgetIndex[i][1]);
        if (widget.css('display') != 'none') {
            //alert("displayed Apparently");
            $('#' + WidgetIndex[i][0]).parent().addClass("selected");
            $('#' + WidgetIndex[i][0]).parent().find(":checkbox").attr("checked", "checked");  
        } else {
            $('#' + WidgetIndex[i][0]).parent().removeClass("selected");
            $('#' + WidgetIndex[i][0]).parent().find(":checkbox").removeAttr("checked"); 
        }
    }
    DisplayWidgetAudience()
    //alert("Setting boxes to widgets");
}


//Ticker
$(function() {
    var randomNumber = Math.floor(Math.random() * 100001)
    //News Load
    $('#newsTickerContent').html("Loading News...");
    $('#newsTickerContent').load("/newsfeed.aspx?rnd=" + randomNumber, function() {
        for (var i = 1; i <= NewsTickerInstances; i = i + 1) {
            if (i == NewsTickerCurrentInstance) {
                $("#NewsTickerItem" + i).show();
            } else {
                $("#NewsTickerItem" + i).hide();
            }
        }
        intval = window.setInterval(NewsTickerControl, 5000);
    });

    $("#newsToggle").toggle(function(event) {
        event.preventDefault();
        NewsTickerToggle();
        if (window.HighVisibility == false) {
            $("#newsToggle").html('<img src="images/newsplay.png" alt="Play News Ticker" title="Play News Ticker" />');
        } else {
        $("#newsToggle").html('<img src="images/hvnewsplay.png" alt="Play News Ticker" title="Play News Ticker" />');
        }
    }, function() {
        NewsTickerToggle();
        if (window.HighVisibility == false) {
            $("#newsToggle").html('<img src="images/newspause.png" title="Pause News Ticker" alt="Pause News Ticker" />');
        } else {
            $("#newsToggle").html('<img src="images/hvnewspause.png" title="Pause News Ticker" alt="Pause News Ticker" />');
        }
    });

    $("#newsNext").click(function(event) {
        event.preventDefault();
        NewsTickerNext();
    });

    $("#newsPrevious").click(function(event) {
        event.preventDefault();
        NewsTickerPrevious();
    });
});

var NewsTickerPaused = false;

function NewsTickerToggle() {
    if (NewsTickerPaused == false) {
        NewsTickerPaused = true;
    } else {
        NewsTickerPaused = false;
    }
}

function NewsTickerControl() {
    if (NewsTickerPaused==false) {
        NewsTickerNext();
    }
}

function NewsTickerNext() {
    $("#NewsTickerItem" + NewsTickerCurrentInstance).fadeOut(2, function() {
        NewsTickerCurrentInstance += 1;
        if (NewsTickerCurrentInstance > NewsTickerInstances) { NewsTickerCurrentInstance = 1; }
        $("#NewsTickerItem" + NewsTickerCurrentInstance).fadeIn();
    });
}

function NewsTickerPrevious() {
    $("#NewsTickerItem" + NewsTickerCurrentInstance).fadeOut(2, function() {
        NewsTickerCurrentInstance -= 1;
        if (NewsTickerCurrentInstance <1) { NewsTickerCurrentInstance = NewsTickerInstances; }
        $("#NewsTickerItem" + NewsTickerCurrentInstance).fadeIn();
    });
}


// Cornerz
jQuery(function() {
    if (window.HighVisibility == false) {
        /*
        DD_roundies.addRule('.fatwidget', '10px');
        DD_roundies.addRule('.quizbox', '10px');
        DD_roundies.addRule('.headercorners', '10px');
        DD_roundies.addRule('.navcorners', '10px');
        DD_roundies.addRule('.quizcentersubmit', '10px');
        DD_roundies.addRule('.widget', '10px');
        DD_roundies.addRule('#menu', '10px');
        DD_roundies.addRule('#menu', '10px');
        alert('HELLO');
        /* /
        
        
        
        $('.fatwidget').corner("10px cc:#CBCBCB");
        $('.quizbox').corner("10px cc:#3085D0");
        //$('.headercorners').corner("8px cc:#dbded3");
        $('.headercorners').corner("8px cc:#F0EBE8");
        $('.navcorners').corner("10px cc:#FFFFFF");
        $('.quizcentersubmit').corner("10px cc:#FBFBEA");
        $('.widget').corner("10px cc:#CBCBCB");
        $('.yellowcorners').corner("8px cc:#FCD208");
        $('#MyAreaHiddenForm').corner("Bottom 10px cc:#CBCBCB");
        $('.accordian_corner').corner("8px cc:#a6a9ba");
        $('.accordian_corner_white').corner("8px cc:#ffffff");
        $('#menu').corner("10px cc:#CBCBCB");//*/

        //DD_roundies.addRule('.widget', '10px', 1);

        /*DD_roundies.addRule('.accordian_corner', '8px');
        DD_roundies.addRule('.accordian_corner_white', '8px');*/


        /*DD_roundies.addRule('#menu', '10px', 1);
        DD_roundies.addRule('.headercorners', '8px', 1);
        DD_roundies.addRule('.yellowcorners', '8px', 1);

        DD_roundies.addRule('.blogcorners', '8px', 1);
        DD_roundies.addRule('.mediaCorners', '8px', 1);
        DD_roundies.addRule('.firstmenunavitem', '8px 0px 0px 8px', 1);*/

        //*
        $('.widget').cornerz({ radius: 10, background: "#CBCBCB" });

        $('.fatwidget').cornerz({ radius: 10, background: "#CBCBCB" });
        $('.quizbox').cornerz({ radius: 10, background: "#3F71B4" });//"#3085D0" });
        $('.quizbutton').cornerz({ radius: 8, background: "#3F71B4" });
        $('.headercorners').cornerz({ radius: 8, background: "#F0EBE8" });
        $('.navcorners').cornerz({ radius: 10, background: "#FFFFFF" });
        $('.quizcentersubmit').cornerz({ radius: 10, background: "#FBFBEA" });
        $('.yellowcorners').cornerz({ radius: 8, background: "#FCD208" });
        $('.accordian_corner').cornerz({ radius: 8, background: "#a6a9ba" });
        $('.workplacesafer_corner').cornerz({ radius: 8, background: "#CFE7F1" });
        $('.HSDcorners').cornerz({ radius: 8, background: "#A79D93" });
        $('.accordian_corner_white').cornerz({ radius: 8, background: "#ffffff" });
        $('#menu').cornerz({ radius: 10, background: "#CBCBCB" }); //*/
        $('#MyAreaHiddenForm').cornerz({ corners: "br bl", radius: 10, background: "#CBCBCB" });
        

    } else {
        /*
        $('.widget').corner("10px cc:#222");
        $('.yellowcorners').corner("8px cc:#000");
        $('.resizeButton').corner("8px cc:#000"); //*/
        $('.widget').cornerz({ radius: 10, background: "#222222" });
        $('.yellowcorners').cornerz({ radius: 8, background: "#000000" });
        $('.resizeButton').cornerz({ radius: 8, background: "000000" });
    }

});


// jQuery Slider for Latest Incidents
jQuery(function(){  
$("#slider").easySlider();
});


// jQuery Tabs Slider for What's On
//jQuery(function() {
//    $(".tab_content").hide(); //Hide all content
//    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
//    $(".tab_content:first").show(); //Show first tab content
    //On Click Event
//    $("ul.tabs li a").click(function(event) {
        //alert("clicked");
        //event.preventDefault();
        //$("ul.tabs li").removeClass("active"); //Remove any "active" class
        //$(this).addClass("active"); //Add "active" class to selected tab
       
        //$(".tab_content").hide(); //Hide all tab content
        
        //var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
        //alert(activeTab);
        //$(activeTab).fadeIn(); //Fade in the active content
//    });
//});

// jQuery Tabs Slider for Fire authority Info
jQuery(function(){  
$("#authorityinfo .infotab_content").hide(); //Hide all content
$("#authorityinfo ul.infotabs li:first").addClass("active").show(); //Activate first tab
$("#authorityinfo .infotab_content:first").show(); //Show first tab content
//On Click Event
$("#authorityinfo ul.infotabs li").click(function(event) {
event.preventDefault();
$("#authorityinfo ul.infotabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$("#authorityinfo .infotab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
});
});



// jQuery Tabs Slider for get Connected
/*jQuery(function(){  
$("#getconnected .contab_content").hide(); //Hide all content
$("#getconnected ul.contabs li:first").addClass("active").show(); //Activate first tab
$("#getconnected .contab_content:first").show(); //Show first tab content
//On Click Event
$("#getconnected ul.contabs li").click(function(event) {
event.preventDefault();
$("#getconnected ul.contabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$("#getconnected .contab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
});
});*/


// Clock
jQuery(function() {
     
jQuery('#clock') 
.epiclock({format: "j F Y H:i"})
.clocks(EC_RUN);


}); 

//Accordion for My Safety
$(document).ready(function(){
$("#accordion").accordion({ autoHeight: false, active: 4, collapsible: true } );
});

//Accordion for Cadets
$(document).ready(function(){
    $("#cadetsresults").hide(); //Hide all content

    $("#cadetsdropdown").accordion({ autoHeight: true, active: 1, collapsible: true } );
    $("#cadetsdropdown div ul li a").click(function(ev) {
        ev.preventDefault();
        $("#cadetsdropdown").accordion('activate');
        $("#cadetsresults").show();
        $("#cadetsresults").slideDown();

        $(".closerblue").click(function(ev) {
            ev.preventDefault();
            $("#cadetsresults").hide();

        });

    });
});



//Accordion for Firestations
$(document).ready(function() {
    //alert("What first?");
    $("#firestationresults").hide(); //Hide all content

    $("#firestationdropdown").accordion({ autoHeight: true, active: 1, collapsible: true });
    $("#firestationdropdown div ul li a").click(function(ev) {
        ev.preventDefault();
        $("#firestationdropdown").accordion('activate');
        $("#firestationresults").show();
        $("#firestationresults").slideDown();
        $(".closer").click(function(ev) {
            ev.preventDefault();
            $("#firestationresults").hide();

        });

    });
});


function reactivateFireStationCloseButton() {
    //alert("What?");
    $("#firestationresults").show();
    $('.firestationcorner').corner("8px cc:#FFF");
    $("#firestationresults").slideDown();
    $(".closer").click(function(ev) {
       ev.preventDefault();
        $("#firestationresults").hide();

    });
}

function reactivateCadetsCloseButton() {
    //alert("What?");
    $("#cadetsresults").show();
    $('.cadetscorner').corner("8px cc:#FFF");
    $("#cadetsresults").slideDown();
    $(".cadetscloser").click(function(ev) {
        ev.preventDefault();
        $("#cadetsresults").hide();

    });
}



//Accordion for My area
$(document).ready(function() {
//alert("What first?");

    
    $("#MyAreaHiddenForm").hide(); //Hide all content

// SCRIPT REMED OUT DUE TO SHAW TRUST NOT LIKING THE SLIDER FUNCTION

//    $("#myAreaActivate").toggle(function(event) {
//        event.preventDefault();
//        $("#MyAreaHiddenForm").slideToggle("slow");
//    }, function() {
//        $("#MyAreaHiddenForm").slideToggle("slow");
//    });
    
});

//Accordion for Freedom of Info
$(document).ready(function() {
    $("#FOIdropdown").accordion({ autoHeight: false, active: 6, collapsible: true });
});

//Accordion for Contacts
$(document).ready(function(){
$("#contactsmenu").accordion({ autoHeight: false, active: 6, collapsible: true } );
});

//Input change on Focus
function cngit(a) {
    if (document.getElementById('postcode').value == "Type here") {
        document.getElementById('postcode').value = a;
    }
}
function cngit2(a){
    document.getElementById('qt').value = a;
}
function cngit3(a){
   document.getElementById('latestsearchfield').value = a;
}
function cngit4(a){
   document.getElementById('latestincidentsearch').value = a;
}
function cngit5(a){
   document.getElementById('overlaypostcode').value = a;
}
function cngit6(a){
   document.getElementById('whatsonsearchinput').value = a;
}
function cngit7(a){
   document.getElementById('subscribesearchinput').value = a;
}
function cngit8(a) {
    if (document.getElementById('feedbacktext').value == "Your comment") {
        document.getElementById('feedbacktext').value = a;
    }
}
function cngit9(a) {
    if (document.getElementById('name').value == "Your name") {
        document.getElementById('name').value = a;
    }
}
function cngit10(a) {
    if (document.getElementById('email').value == "Your email address") {
        document.getElementById('email').value = a;
    }
}
function cngit11(a) {
    if (document.getElementById('hiddenpostcode').value == "Type here") {
        document.getElementById('hiddenpostcode').value = a;
    }
}


// Accessibility Banner
$(document).ready(function() {
    $(".accessCommand").click(function(event) {
        var currentId = $(this).attr('id');
        event.preventDefault();
        //alert(currentId);
        if (currentId == "resetFont2") {
            accessibilityCommand("resetFont");
        } else {
            accessibilityCommand(currentId);
        }
    });
});


//Rate This Page Handling
//$(document).ready(function() {
//    $("#ratings a").click(function(event) {
//        event.preventDefault();
//   
//        var myClass = $(this).attr("class");
//        //alert(myClass);
//        var dataString = 'rating=' + myClass;
//        $('#ratethispage').html("<div style='width: 100%; height:150px; padding-top:100px; text-align:center; font-size:0.7em; font-weight:bold;'><img src='/images/ajax-loader.gif' alt='loading'><br /><span style='padding-left:30px;'>Sending Feedback</span></div>");

//        $.post("/Widgets/RateThisPage/SubmitRating.aspx", dataString,
//                    function(data) {
//                        $('#ratethispage').html(data);
//                    });
//
//});
//});

//Feedback Form Handling
$(document).ready(function() {
    $("#feedbackSubmit").click(function(event) {
        event.preventDefault();

        // get all the inputs into an array.
        var $inputs = $('#feedbackform :input');


        // get an associative array of just the values.
        var values = {};
        $inputs.each(function() {
            values[this.name] = $(this).val();
            //alert(this.name + " " + $(this).val());
        });

        var radiovalue = $("#feedbackform input:radio:checked").val();
        var dataString = 'radiovalue=' + radiovalue + '&feedback=' + values["feedbacktext"] + '&name=' + values["name"] + '&email=' + values["email"]

        /*alert("feedback:" + values["feedbacktext"] +
                    " name:" + values["name"] +
                    " email:" + values["email"] +
                    " Radio:" + radiovalue +
                    " Data:" + dataString);*/

        if (radiovalue) {
            if (values["feedbacktext"] && values["name"] && values["email"] && values["name"] != "Your name" && values["feedbacktext"] != "Your comment" && values["email"] != "Your email address") {
                //alert(dataString);
                $('#feedback').html("<div style='width: 100%; height:150px; padding-top:100px; text-align:center; font-size:0.7em; font-weight:bold;'><img src='/images/ajax-loader.gif' alt='loading'><br /><span style='padding-left:30px;'>Sending Feedback</span></div>");

                $.post("/Widgets/Feedback/SubmitFeedback.aspx", dataString,
                    function(data) {
                        $('#feedback').html(data);
                    });
            } else {
                alert("Please fill in the form to send feedback");
            }

        } else {
            alert("Please select feedback type");
        }
        return false;
    });
});

function incidentSearch() {
    sURL = "incidents.aspx?";
    sURL = sURL + "s=" + document.getElementById("incidentWidgetSearch").value;
    sURL = sURL + "&dd=" + document.getElementById("incidentWidgetDD").value;
    sURL = sURL + "&mm=" + document.getElementById("incidentWidgetMM").value;
    sURL = sURL + "&yy=" + document.getElementById("incidentWidgetYY").value;
    location.href = sURL;
}
