/*
GoodCorners - A simple script to enhance select elements by applying CSS3 rounded edges in supported browsers using a unified syntax.
	Ryan Rampersad 2009
*/

var GoodCorners;

(function () {
    var styles = {
        gecko: {
            topleft: "-moz-border-radius-topleft",
            topright: "-moz-border-radius-topright",
            bottomleft: "-moz-border-radius-bottomleft",
            bottomright: "-moz-border-radius-bottomright",
            radius: "-moz-border-radius"
        },
        webkit: {
            topleft: "-webkit-border-top-left-radius",
            topright: "-webkit-border-top-right-radius",
            bottomleft: "-webkit-border-bottom-left-radius",
            bottomright: "-webkit-border-bottom-right-radius",
            radius: "-webkit-border-radius"
        }
    },
    layout = null,
    BE = Browser.Engine,
    options = new Hash({
        radius: "10px",
        selector: ".gc",
        cornered: "good-cornered"
    });

    if (BE.webkit) {
        layout = "webkit";
    }
    if (BE.gecko) {
        layout = "gecko";
    }

    GoodCorners = {

        options: function (opt) {
            options.extend(opt);
            return this;
        },

        round: function (selector, how) {
            if (layout == null) {
                return false;
            }

            // Default rounding is 10px all the way around.
            how = new Hash(how || {
                radius: options.radius
            });
            how.each(function (value, key, obj) {
                // ignore other styles completly
                if ($defined(styles[layout][key]) == false) {
                    return;
                }
                how.set(styles[layout][key], value);
                how.erase(key);
            });

            // Anything with the gc class attached to it, round it.
            $$(selector || options.selector).setStyles(how.getClean()).addClass(options.cornered);
            return true;
        }

    };

})();