if (! $.browser.msie) {
// Just don't do any of this if IE is involved. For the sanity of all.

$(document).ready(function()
{
    var target_boxes    = "fwdc-collapse";               // Everything with this class
    var target_rail     = "sidebar-right";              // Everything with this class
    var collapse_rail   = "sidebar-right-collapse";     // Everything with this class
    var expand_rail     = "sidebar-right-expand";       // Everything with this class

    // Click listener for boxes
    $(".fwdc-block-close").click(function() {
        var block_id = $(this).parent().parent().parent().parent().parent().parent().attr('id');
        $("#"+block_id+" div.content").toggle(300);     // Hide or show the content box
        $("#"+block_id+" div h2.title").toggleClass('collapsed');
        if( $("#"+block_id+" div h2.title").hasClass('collapsed') ){
            $.cookie(block_id, 'collapsed');            // Remember this setting        
        } else {
            $.cookie(block_id, '');                     // Remember this setting        
        } 
        return false;                                   // Exit
    });

    // Click listener for right rail collapse
    $("."+collapse_rail).click(function() {
        $("#"+target_rail).hide(300);                   // Hide the rail 
        $.cookie(target_rail, 'collapsed');             // Remember this setting
        return false;                                   // Exit
    });
    
    // Click listener for right rail expand
    $("."+expand_rail).click(function() {
        $("#"+target_rail).show(300);                   // Show the rail 
        $.cookie(target_rail, '');                      // Remember this setting
        return false;                                   // Exit
    });
    
    // Check initial block cookie settings on ready
    $(".fwdc-block-close").each(function() {            // Loop through all target boxes
        var block_id = $(this).parent().parent().parent().parent().parent().parent().attr('id');
        var showBox = $.cookie(block_id);               // Get cookie value for this box
        if (showBox == 'collapsed') {                   // If supposed to be hidden then act
            $("#"+block_id+" div.content").hide();       // Hide the box
            $("#"+block_id+" div h2.title").toggleClass('collapsed');
        }                                               // Else, do nothing
    });
    
    // Check initial rail cookie settings on ready
    var showRail = $.cookie(target_rail);               // Get cookie value for this rail
    if (showRail == 'collapsed') {                      // If supposed to be hidden then act
        $("#"+target_rail).hide();                      // Hide the rail
    }                                                   // Else, do nothing
    
});
    
// End protection from IE insanity
}
