﻿__panels = {};

__panels.createBlock = function(el, color) {
    var el_h1 = 0;
    var el_h2 = 0;

    switch (color) {
        case "blue":
            el_h1 = 20;
            el_h2 = 18;
            break;

        case "white":
            el_h1 = 30;
            el_h2 = 40;
            break;
    }

    var box = jQuery("<div style='position: relative;'></div>");
    box.height(el.height() + el_h1);
    box.width(el.width());
    box.css("margin", el.css("margin"));

    var bg = jQuery("<div class='box_" + color + "'>&nbsp;</div>");
    bg.height(el.height() + el_h2);
    bg.width(el.width() - 2);
    box.append(bg);

    box.append("<div class='box_" + color + "_bm'>&nbsp;</div>");
    box.append("<div class='box_" + color + "_tm'>&nbsp;</div>");
    box.append("<div class='box_" + color + "_lm'>&nbsp;</div>");
    box.append("<div class='box_" + color + "_rm'>&nbsp;</div>");

    box.append("<div class='box_" + color + "_lt'>&nbsp;</div>");
    box.append("<div class='box_" + color + "_lb'>&nbsp;</div>");
    box.append("<div class='box_" + color + "_rt'>&nbsp;</div>");
    box.append("<div class='box_" + color + "_rb'>&nbsp;</div>");

    return box;
}

__panels.process = function() {
    jQuery("[uitype='panel_blue']").each(function(e) {
        var el = jQuery(this);
        if (el.attr("uiprocessed"))
            return;

        var box = __panels.createBlock(el, "blue");
        jQuery(el).before(box);
        jQuery(el).appendTo(box);

        el.attr("className", "box_blue_content");
        el.css("z-index", "5");
        el.height(box.height() - 20);
        el.width(box.width() - 20);

        el.attr("uiprocessed", true);
    });

    jQuery("[uitype='panel_white']").each(function(e) {
        var el = jQuery(this);
        if (el.attr("uiprocessed"))
            return;

        var box = __panels.createBlock(el, "white");
        jQuery(el).before(box);
        jQuery(el).appendTo(box);

        el.attr("className", "box_blue_content");
        el.css("z-index", "5");
        el.height(box.height());
        el.width(box.width());

        el.attr("uiprocessed", true);
    });
};

jQuery("document").ready(function() {
    __panels.process();
});
