jit.Vimeo = (function() {
    var self;

    return self = {
        init: function() {
            $('a.vimeo').each(function() {
                var link  = $(this),

                    videoID  = link.attr('href').match(/^http:\/\/[^\/]+\/(\d+)/)[1],
                    videoURL = 'http://vimeo.com/moogaloop.swf?clip_id=' + videoID + '&fullscreen=1',

                    videoWidth  = 504,
                    videoHeight = 380;

                link.click(function(e) {
                    e.preventDefault();

                    new jit.widget.Dialog({
                        width: videoWidth + 'px',
                        height: videoHeight + 'px',

                        beforeRender: function(dialog) {
                            dialog.setBody('');

                            $(dialog.body).css('padding', '0');

                            var swf = new SWFObject(videoURL, 'vimeo', videoWidth, videoHeight, '9', '#ffffff')

                            swf.addParam('allowfullscreen', 'true');
                            swf.write(dialog.body);
                        },

                        afterRender: function(dialog) {
                            $(dialog.mask).click(function() {
                                dialog.hide();
                                $(this).unbind('click');
                            });
                        }
                    });
                });
            });
        }
    }
})();

$(jit.Vimeo.init);

