(function(window, $, undef) {
    if($ === undef) {
        throw new Error('Dépendence non satisfaite : jQuery');
    }

    $(function() {
        var script = document.createElement('SCRIPT');
        script.type = 'text/javascript';
        script.src = 'http://s7.addthis.com/js/250/addthis_widget.js';
        document.getElementsByTagName('HEAD')[0].appendChild(script);
    });

    window.addthis_language = 'fr';
    window.addthis_options = 'favorites, facebook, google, live, delicious, digg, twitter, linkedin, more';
    window.addthis_offset_top = 20;
    window.addthis_localize = {
        favorites: 'Favoris',
        more: 'suite...'
    };

    var optionsList = /^addthis_language|addthis_options|addthis_offset_top|addthis_localize|addthis_offset_left$/;

    $.fn.AddThisButton = function(options) {
        for(var key in options) {
            if(optionsList.test(key)) {
                window[key] = options[key];
            }
        }

        return this
            .mouseover(function() {
                if(typeof addthis_open === 'function') {
                    return addthis_open(this, '', '[URL]', '[TITLE]');
                }
            })
            .mouseout(function() {
                if(typeof addthis_close === 'function') {
                    return addthis_close();
                }
            })
            .click(function() {
                if(typeof addthis_sendto === 'function') {
                    return addthis_sendto();
                }
            });
    };
}(this, this.jQuery));
