/**
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 * @copyright   2007 Michael J. I. Jackson
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL 3.0
 * @version     SVN: $Id: shadowbox-jquery.js 75 2008-02-21 16:51:29Z mjijackson $
 */

if(typeof jQuery == 'undefined'){throw 'Unable to load Shadowbox, jQuery library not found.';}

// create the Shadowbox object first
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.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);
    }

};
(function($){
$.fn.shadowbox = function(options){
    return this.each(function(){
        var $this = $(this);
        // support jQuery metadata plugin
        var opts = $.extend({}, options || {}, $.metadata ? $this.metadata() : $.meta ? $this.data() : {});
        // support embedded opts (for w/h) within the class attr
        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);
    });
};
})(jQuery);
