/**
 * An adapter for Shadowbox and the jQuery JavaScript library.
 *
 * This file is part of Shadowbox.
 *
 * Shadowbox is an online media viewer application that supports all of the
 * web's most popular media publishing formats. Shadowbox is written entirely
 * in JavaScript and CSS and is highly customizable. Using Shadowbox, website
 * authors can showcase a wide assortment of media in all major browsers without
 * navigating users away from the linking page.
 *
 * Shadowbox is released under version 3.0 of the Creative Commons Attribution-
 * Noncommercial-Share Alike license. This means that it is absolutely free
 * for personal, noncommercial use provided that you 1) make attribution to the
 * author and 2) release any derivative work under the same or a similar
 * license.
 *
 * If you wish to use Shadowbox for commercial purposes, licensing information
 * can be found at http://mjijackson.com/shadowbox/.
 *
 * @author      Michael J. I. Jackson <mjijackson@gmail.com>
 * @copyright   2007-2008 Michael J. I. Jackson
 * @license     http://creativecommons.org/licenses/by-nc-sa/3.0/
 * @version     SVN: $Id: shadowbox-jquery.js 103 2008-06-27 06:19:21Z mjijackson $
 */

if(typeof jQuery == 'undefined'){
    throw 'Unable to load Shadowbox, jQuery library not found';
}

// create the Shadowbox object first
var Shadowbox = {};

Shadowbox.lib = {

    adapter: 'jquery',

    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;
    },

    getPageXY: function(e){
        return [e.pageX, e.pageY];
    },

    preventDefault: function(e){
        e.preventDefault();
    },

    keyCode: function(e){
        return e.keyCode;
    },

    addEvent: function(el, name, handler){
        jQuery(el).bind(name, handler);
    },

    removeEvent: function(el, name, handler){
        jQuery(el).unbind(name, handler);
    },

    append: function(el, html){
        jQuery(el).append(html);
    }

};

(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);
