if(typeof jQuery == 'undefined'){
    throw 'Unable to load Shadowbox, jQuery library not found.';
}
var Shadowbox = {};
Shadowbox.lib = {
    getStyle: function(el, style){
        return jQuery(el).css(style);
    },
    setStyle: function(el, style, value){
        if(typeof style != 'object'){
            var temp = {};
            temp[style] = value;
            style = temp;
        }
        jQuery(el).css(style);
    },
    get: function(el){
        return (typeof el == 'string') ? document.getElementById(el) : el;
    },
    remove: function(el){
        jQuery(el).remove();
    },
    getTarget: function(e){
		return e.srcElement || e.currentTarget || e.target; 
    },
    preventDefault: function(e){
        e = e.browserEvent || e;
        if(e.preventDefault){
            e.preventDefault();
        }else{
            e.returnValue = false;
        }
    },
    addEvent: function(el, name, handler){
        jQuery(el).bind(name, handler);
    },
    removeEvent: function(el, name, handler){
        jQuery(el).unbind(name, handler);
    },
    animate: function(el, obj, duration, callback){
        duration = Math.round(duration * 1000); // convert to milliseconds
        var o = {};
        for(var p in obj){
            for(var p in obj){
                o[p] = String(obj[p].to);
                if(p != 'opacity') o[p] += 'px';
            }
        }
        jQuery(el).animate(o, duration, null, callback);
    }
};
jQuery.fn.shadowbox = function(options){
    return this.each(function(){
        var $this = $(this);
        var opts = $.extend({}, options || {}, $.metadata ? $this.metadata() : $.meta ? $this.data() : {});
        var cls = this.className || '';
        opts.width  = parseInt((cls.match(/w:(\d+)/)||[])[1]) || opts.width;
        opts.height = parseInt((cls.match(/h:(\d+)/)||[])[1]) || opts.height;
        Shadowbox.setup($this, opts);
    });
};
