// Needs JQuery 1.3
// add_to_cart plugin

(function($) {

	$.extend({
		
		add2cart: function(_source_, _target_) {

			var source = $(_source_).parent().children().children();
			var target = (_target_ != '')? $('#' + _target_ ) : $('#divShoppingCard');

			$('body').prepend('<div id="_shadow" style="display: none; background-color: #ddd; border: solid 1px darkgray; position: static; top: 0px; z-index: 100000;">&nbsp;</div>');
			var shadow = $('#_shadow');
				  
			if( !shadow ) { alert('Cannot create the shadow div');
			}else{ 
			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');
				if(target){
					//shadow.animate( { width: target.innerWidth(), height: target.innerHeight(), top: target.offset().top, left: target.offset().left }, { duration: 300 } ).animate( { opacity: 0 }, { duration: 100  } ); // , complete:
					shadow.animate( { 
							width: (0.5)*source.width(),
							height: (0.5)*source.height(),
							top: target.offset().top + Math.floor((0.5)*target.height()),
							left: target.offset().left + Math.floor((0.5)*target.width())},
									{ 
							duration: 500
									} 
								).animate( { opacity: 0 }, { duration: 100, complete: function(){$(this).remove();} } );
				}
			}
		}
	});
})(jQuery);

