(function(){
    var $ = window.jQuery;
    if (!$ || !$.fn) {
        var res = prompt('It appears that jQuery is not being used within this document. If it is and you know its alias, please enter it here:');
        if (res && window[res]) {
            $ = window[res];
        } else {
            res && alert('Ah nevermind; maybe next time...');
            return;
        }
    }
    $.getScript('http://ajax.googleapis.com/ajax/libs/jquery/' + $.fn.jquery + '/jquery.min.js', function(){
        var JQ = jQuery.noConflict(true),
            plugins = [],
            shorten = function(s) {
                return (s.length > 13) ? s.substring(0, 10) + '&hellip;' : s;
            };
        for (var i in $.fn) {
            if (typeof JQ.fn[i] === 'undefined') {
                var href = 'http://www.google.com/search?q=jQuery+plugin+' + i;
                plugins.push('<li><span>jQuery.fn.<a href="' + href + '" title="' + i + '">' + shorten(i) + '</a></span></li>');
            }
        }
        if (!plugins.length) {
            plugins.push('<li>Nothing! :(</li>');
        }
        var d = false,x,y,uid=(+new Date()),
        u = $('<div id="jq' + uid + '"/>')
            .css({
                position: 'fixed',
                background: '#000',
                zIndex: 9999,
                color: '#FFF',
                border: '3px solid white',
                fontSize: '13px',
                top: 0,
                outline: '1px solid #000',
                display: 'none',
                width: '250px',
                '-webkit-box-shadow': '0 0 20px #888'
            })
            .append('<ul>' + plugins.join('') + '</ul>')
            .find('ul')
                .css({
                    padding: '20px 20px 0 20px',
                    margin: 0
                })
                .each(function(){
                    if ($(this).children().length > ($(window).height() / 2 / 40)) {
                        $(this).css({
                            height: $(window).height() / 2,
                            overflow: 'auto'
                        });
                    }
                })
            .end()
            .find('li')
                .css({
                    padding: '0 10px',
                    lineHeight: '40px',
                    listStyle: 'none',
                    fontFamily: '"Consolas","Lucida Console",Courier,mono',  
                    textAlign: 'left',
                    margin: '0',
					color: 'white'
                })
            .end()
            .find('li:gt(0)').css('borderTop','1px solid #EEE').end()
            .find('li:last').css('paddingBottom','20px').end()
            .find('span').css('cursor','default').end()
            .find('a')
                .css({
                    color: 'white',
                    textDecoration: 'underline',
                    fontWeight: '700'
                })
            .end()
            .mousedown(function(e){
                if (e.target === $('div',u)[0]) {
                    d = true;
                    return false;
                }
            })
            .prepend(
                $('<div/>').css({
                    background: 'white',
                    padding: '10px 20px',
                    color: 'black',
                    cursor: 'move',
                    fontFamily: '"Consolas","Lucida Console",Courier,mono',
                    textAlign: 'center'
                }).append('PLUGINS USED ').append(
                    $('<a href="#">[CLOSE]</a>')
                        .css({
                            color: 'black',
                            fontSize: '12px'
                        })
                        .click(function(){
                            u.animate({
                                left: -u.outerWidth(),
                                top: -u.outerHeight()
                            }, function(){u.remove();});
                            return false;
                        })
                )
            )
            .appendTo('body')
            .each(function(){
                $('#s' + uid).remove();
                $('<style id="s' + uid + '">#jq' + uid + '{_position:absolute !important;}</style>').appendTo('head');
                $(this).css({
                    left: -$(this).outerWidth(),
                    top: -$(this).outerHeight(),
                    display: 'block'
                });
            })
            .animate({
                left: 20,
                top: 20
            });
        $(document).mousemove(function(e){
            if(d) {
                u.css({
                    left : e.pageX - (x || (x = (e.pageX - u.offset().left))),
                    top : e.pageY - (y || (y = (e.pageY - u.offset().top)))
                });
            }
        }).mouseup(function(){
            d=false; x=null; y=null;
        });
    });
    
})();