(function($) {

	$.extend({
		add2cart: function(source_id, target_id, callback) {
    
      var source = $('#' + source_id );
      var target = $('#' + target_id );
      
      var shadow = $('#' + source_id + '_shadow');
      if( !shadow.attr('id') ) {
          $('body').prepend('<div id="'+source.attr('id')+'_shadow" style="display: none; background-color: #808080; border: solid 1px darkgray; position: static; top: 0px; z-index: 100000;">&nbsp;</div>');
          var shadow = $('#'+source.attr('id')+'_shadow');
      }
      
      if( !shadow ) {
          alert('Cannot create the shadow div');
      }
      
      shadow.width(source.outerWidth()).height(source.outerHeight()).css('top', source.offset().top).css('left', source.offset().left).css('opacity', 0.5).fadeIn("200");
      shadow.css('position', 'absolute');
      
      shadow.animate( { width: target.innerWidth(), height: target.innerHeight(), top: target.offset().top, left: target.offset().left }, { duration: 600, complete: callback } )
        .animate( { opacity: 0 }, { duration: 200, complete: function() {shadow.remove()} } );
		}
	});
})(jQuery);


$(document).ready(function(){
    var base_url = $("#page_base_url").val();
    var ajax_url = base_url+"/modules/CatalogerCart/ajax.php";
    var action_add_to_cart = "ajax_add_to_cart";
    $(".add_to_cart_btn").click(function(){
        var elem_id = $(this).attr("id");
        var itemid = elem_id.split("_");
        itemid = itemid[2];
        $.ajax({
            url: ajax_url,
            type: "POST",
            data: "action="+action_add_to_cart+"&item_id="+itemid,
            success: function(msg){
                /*$("#cart_cnt").html(msg);*/
               /* $.add2cart( elem_id,  'full_cart');*/
                $.add2cart( "pdit_"+itemid,  'cart_cnt', function() {$("#cart_cnt").html(msg);});
            }
        });
        return false;    
    })
    
});

