// Given the id (or array of idas) of a page element, and an object containg style keys and values, sets those styles on the given object style names that start with an underscore are treated as object properties directly instead of properties of the style object
function styler(ids, styles) {
	if (typeof ids != 'object') { ids = [ids]; }
	for (var ididx = 0; ididx < ids.length; ids++) {
		var id = ids[ididx];
        if (!id) {return;}
        //var elem = el(id);
        elem = document.getElementById(id); //speedup
        GenericStyler.applyStyles(elem, styles);
	}
}

function child_styler(top, pairs) {
    var children = getAllChildren(el(top));
    for (var pairidx = 0; pairidx < pairs.length; pairidx++) {
        var ids = pairs[pairidx][0];
        var styles = pairs[pairidx][1];
        if (typeof ids != 'object') { ids = [ids]; }
        for (var ididx = 0; ididx < ids.length; ids++) {
            var id = ids[ididx];
            if (!id) {return;}
            var elem;
            for (var i=0; i < children.length; i++) {
                if (children[i].id == id) { elem = children[i]; }
            }
            GenericStyler.applyStyles(elem, styles);
        }
    }
}

var GenericStyler = new Object();

Object.extend(GenericStyler, {
   
    applyStyles: function(elem, styles) {
        for (var stylename in styles) {
            var stylevalue = styles[stylename];
            this.applyStyle(elem, stylename, stylevalue);
        }
    },
    
    
    // Styles that begin with and underscore and considered to be properties of the element itself
    // Style names with dahses will be converted to camelCase
    // ApplyStyle checks the GenericStyler.stylers object to see if there is a method for specificly handling this particular style.  This can be used to define new styles not native to the browser
    applyStyle: function(elem, name, value) {
        if (!elem) { return false; }
        var styler = GenericStyler.stylers[name];
        if (typeof styler == 'function') { return styler(elem, name, value); }
       
        try {
            var bits = name.match(/^_(.*)/);
            if (bits != null) {
                elem[bits[1]] = value;
            }
            else {
                elem.style[name] = value;
            }
        }
        catch (e) { }
    },
    
    stylers: {
        hidden: function(elem, name, value) {
            value || value == 'true' ? elem.hide() : elem.show();
        }
    }


});