if(typeof Prototype == 'undefined'){
    throw 'Unable to load Contentbox, Prototype framework not found';
}

// create the Contentbox object first
var Contentbox = {};

Contentbox.lib = function(){

    // local style camelizing for speed
    var styleCache = {};
    var camelRe = /(-[a-z])/gi;
    var camelFn = function(m, a){
        return a.charAt(1).toUpperCase();
    };
    var toCamel = function(style){
        var camel;
        if(!(camel = styleCache[style])){
            camel = styleCache[style] = style.replace(camelRe, camelFn);
        }
        return camel;
    };

    return {

        adapter: 'prototype',

        getStyle: function(el, style){
            return Element.getStyle(el, style);
        },

        setStyle: function(el, style, value){
            if(typeof style == 'string'){
                var temp = {};
                temp[toCamel(style)] = value;
                style = temp;
            }
            Element.setStyle(el, style);
        },

        get: function(el){
            return $(el);
        },

        remove: function(el){
            Element.remove(el);
        },

        getTarget: function(e){
            return Event.element(e);
        },

        preventDefault: function(e){
            Event.stop(e);
        },

        getPageXY: function(e){
            var p = Event.pointer(e);
            return [p.x, p.y];
        },

        keyCode: function(e){
            return e.keyCode;
        },

        addEvent: function(el, name, handler){
            Event.observe(el, name, handler);
        },

        removeEvent: function(el, name, handler){
            Event.stopObserving(el, name, handler);
        },

        append: function(el, html){
            Element.insert(el, html);
        }

    };

}();

