if(typeof MooTools == 'undefined') {
    throw 'Unable to load Shadowbox, MooTools library not found.';
}

var Shadowbox = {};

Shadowbox.lib = {

    getStyle: function(el, style){
        return $(el).getStyle(style);
    },

    setStyle: function(el, style, value){
        el = $(el);
        if(typeof style != 'object'){
            var temp = {};
            temp[style] = value;
            style = temp;
        }
        for(var s in style){
            el.setStyle(s, style[s]);
        }
    },

    get: function(el){
        return $(el);
    },

    remove: function(el){
        el.parentNode.removeChild(el);
    },

    getTarget: function(e){
        return e.target;
    },

    preventDefault: function(e){
        new Event(e).preventDefault();
    },

    /**
     * Adds an event listener to the given element. It is expected that this
     * function will be passed the event as its first argument.
     *
     * @param   {HTMLElement}   el          The DOM element to listen to
     * @param   {String}        name        The name of the event to register
     *                                      (i.e. 'click', 'scroll', etc.)
     * @param   {Function}      handler     The event handler function
     * @return  void
     * @public
     */
    addEvent: function(el, name, handler){
        $(el).addEvent(name, handler);
    },

    removeEvent: function(el, name, handler){
        $(el).removeEvent(name, handler);
    },

    animate: function(el, obj, duration, callback){
        var config = {
            duration: (duration * 1000) /* convert to milliseconds */
        };
        if(typeof callback == 'function'){
            config.onComplete = callback;
        }
        var anim = new Fx.Styles(el, config);
        var o = {};
        for(var p in obj){
            o[p] = String(obj[p].to);
            if(p != 'opacity') o[p] += 'px';
        }
        anim.start(o);
    }

};

Element.extend({

    setOpacity: function(opacity){
        var s = this.style;
        if(window.ie){
            s.zoom = 1;
            s.filter = (s.filter || '').replace(/alpha\([^\)]*\)/gi,"") +
                       (opacity == 1 ? "" : " alpha(opacity=" + opacity * 100 + ")");
        }else{
            s.opacity = opacity;
        }
    }

});
