(function($) {

    $.extend({
        add2cart: function(sourceSelector, target_id, callback) {
            _callback = function(){
                shadow.hide();
                if(callback) callback();
            };
            var source = $(sourceSelector );
            var target = $('#' + target_id );
              
            var shadow = $('#' + source.attr('id') + '_shadow');
            if( !shadow.attr('id') ) {
                $('body').prepend('<div id="' + source.attr('id') + '_shadow" style="display: none; background-color: #ddd; border: solid 1px darkgray; position: static; top: 0px; z-index: 1000;">&nbsp;</div>');
                var shadow = $('#'+source.attr('id')+'_shadow');
            }
              
            if( !shadow ) {
                alert('Cannot create the shadow div');
            }
              
            shadow.width(source.css('width')).height(source.css('height')).css('top', source.offset().top).css('left', source.offset().left).css('opacity', 0.5).show();
            shadow.css('position', 'absolute');
              
            shadow.animate( { opacity: 0.5, width: target.innerWidth(), height: target.innerHeight(), top: target.offset().top, left: target.offset().left }, { duration: 400 } )
              .animate( { opacity: 0.1 }, { duration: 100, complete: _callback } );
              
            shadow.hide();
        }
    });
})(jQuery);