/* JQuery functionality
*/
$(document).ready(function() {
    //create the slider object for the local cq drop down
    var slider = new SlideOut($('.combobox'), null, null, "ul");
    slider.Start();

    //initdropdowns for other sliders (i.e. filters)
    initDropDowns();

    // Replaces last content bubble with no connector
    $(".contentBubble:last .contentBubbleBtm").addClass("noConnector");

    $(".contentBubble:first .contentBubbleTop").addClass("withConnector");

    // Replaces all lists and links with coloured bubbles
    var bullets = new Array("bubbleBlue", "bubbleGreen", "bubbleOrange", "bubblePink", "bubblePurple", "bubbleRed");
    $(".contentItem ul li").each(function(i) {
        $(this).addClass(bullets[i % bullets.length]);
    });
    $(".sectionItem a").each(function(i) {
        $(this).addClass(bullets[i % bullets.length]);
    });    
    $(".searchItem a").each(function(i) {
        $(this).addClass(bullets[i % bullets.length]);
    });    
    
});

//listen for ajax postbacks
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(InitializeRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function InitializeRequestHandler(sender, args) {

}

function EndRequestHandler(sender, args) {
    //need to re-initialize our drop downs!
    initDropDowns();
}

function resizeWindow(width, height) {
    $("#header").css("width", width);
    $("#header").css("height", height);
}

function initDropDowns() {

    //ensure all slider objects are cleared
    $('table tr th div').each(function() {
        $(this).data("slider", null);
    });

    //Creates a slider for each drop down.
    //Each slider is then stored in the data element of the jquery element
    //so the developer can get access to the slider object by looking up the jquery object and accessing data("slider")
    $('table tr th div').each(function() {
        var slider = new SlideOut($(this), null, null);
        $(this).data("slider", slider);
        slider.Start();
    });

}

