$(window).load(function () {
    // match heights
    var max_height = Math.max($('#body').height(), $('#sidebar').height());

    $('#body, #sidebar, #separator').height(max_height);

    // center floated (left) elements
    $('.js_center_floats').each(function () {

        var $container = $(this);
        var width = $container.width();
        var inner_width = 0;

        $container.children().not('.clear').each(function () {
            inner_width += $(this).outerWidth(true);
        });

        var add_left_margin = (width - inner_width) / 2.0;

        //alert(left_margin);

        var $first_child = $container.children().eq(0);
        var first_child_left_margin = $first_child.css('margin-left');
        var first_child_left_margin_px = 0;

        if(first_child_left_margin.match('px'))
        {
            first_child_left_margin_px = parseFloat(first_child_left_margin);
        }

        //alert($first_child.css('margin-left'));
        //alert(first_child_left_margin);

        var new_left_margin = first_child_left_margin_px + add_left_margin;

        //alert(new_left_margin);

        $first_child.css({'margin-left': new_left_margin+'px'});
    });

    // center a bunch of elements which are positioned vertically
    $('.js_center_vertical').each(function () {

        var $container = $(this);
        var height = $container.height();
        var inner_height = 0;

        $container.children().each(function () {
            inner_height += $(this).outerHeight(true);
        });

        var add_top_margin = (height - inner_height) / 2.0;

        //alert(left_margin);

        var $first_child = $container.children().eq(0);
        var first_child_top_margin = $first_child.css('margin-top');
        var first_child_top_margin_px = 0;

        if(first_child_top_margin.match('px'))
        {
            first_child_top_margin_px = parseFloat(first_child_top_margin);
        }

        //alert($first_child.css('margin-left'));
        //alert(first_child_left_margin);

        var new_top_margin = first_child_top_margin_px + add_top_margin;

        //alert(new_left_margin);

        $first_child.css({'margin-top': new_top_margin+'px'});
    });
});

