jQuery(function p4cardesign_sklad() {
    
   jQuery('.move_to_storehouse_anchor').bind('click', function(event) {
        event.preventDefault();
        var anchor_id = jQuery(this).attr('alt');
        var module_id_and_ref_id = anchor_id.substr(26);
        module_id_and_ref_id = module_id_and_ref_id.split('_');
        var module_id = module_id_and_ref_id[0];
        var ref_id = module_id_and_ref_id[1];
        
        jQuery('.move_to_storehouse_table_' + module_id + '_' + ref_id).toggle();
        jQuery('.processing_storehouse_table_' + module_id + '_' + ref_id).toggle();
        
        AC.simple('?LRPC=p4cardesign.favorites.act_add&args={}', 'POST', {'module_id' : module_id, 'ref_id' : ref_id},
           function(txt) {
        		jQuery('.processing_storehouse_table_' + module_id + '_' + ref_id).toggle();
        		jQuery('.remove_from_storehouse_table_' + module_id + '_' + ref_id).toggle();
       	   });
   });
   
   
   jQuery('.remove_from_storehouse_anchor').bind('click', function(event) {
	   event.preventDefault();
       var anchor_id = jQuery(this).attr('alt');
       var module_id_and_ref_id = anchor_id.substr(30);
       module_id_and_ref_id = module_id_and_ref_id.split('_');
       var module_id = module_id_and_ref_id[0];
       var ref_id = module_id_and_ref_id[1];
       
       jQuery('.remove_from_storehouse_table_' + module_id + '_' + ref_id).toggle();
       jQuery('.processing_storehouse_table_' + module_id + '_' + ref_id).toggle();
       
       AC.simple('?LRPC=p4cardesign.favorites.act_del&args={}', 'POST', {'module_id' : module_id, 'ref_id' : ref_id},
          function(txt) {
       		jQuery('.processing_storehouse_table_' + module_id + '_' + ref_id).toggle();
       		jQuery('.move_to_storehouse_table_' + module_id + '_' + ref_id).toggle();
      	   });
   });
   
   
   jQuery('.small_move_to_storehouse_anchor').bind('click', function(event) {
      small_move(event, this);
  });
   
   
   jQuery('.small_remove_from_storehouse_anchor').bind('click', function(event) {
      small_remove(event, this);
   });
   
   function small_move(event, pointer) {
	   event.preventDefault();
       var anchor_id = jQuery(pointer).attr('alt');
       var module_id_and_ref_id = anchor_id.substr(32);
       module_id_and_ref_id = module_id_and_ref_id.split('_');
       var module_id = module_id_and_ref_id[0];
       var ref_id = module_id_and_ref_id[1];
       
       var image = jQuery(pointer).children('img');
       var anchor = jQuery(pointer);
       
       image.attr('src', '/@/p4cardesign/favorites/rotater.gif');
       image.attr('alt', 'Подождите...');
       
       AC.simple('?LRPC=p4cardesign.favorites.act_add&args={}', 'POST', {'module_id' : module_id, 'ref_id' : ref_id},
          function(txt) {
    	     image.attr('src', '/@/p4cardesign/favorites/added.png');
             image.attr('alt', 'Уже в закладках...');
             anchor.removeClass();
             anchor.addClass('small_remove_from_storehouse_anchor');
             anchor.attr('alt', 'small_remove_from_storehouse_anchor_' + module_id + '_' + ref_id);
             anchor.unbind();
             anchor.bind('click', function(event) {
            	 				small_remove(event, this);
             					});
       });
   }
   
   function small_remove(event, pointer) {
	   event.preventDefault();
       var anchor_id = jQuery(pointer).attr('alt');
       var module_id_and_ref_id = anchor_id.substr(36);
       module_id_and_ref_id = module_id_and_ref_id.split('_');
       var module_id = module_id_and_ref_id[0];
       var ref_id = module_id_and_ref_id[1];
       
       var image = jQuery(pointer).children('img');
       var anchor = jQuery(pointer);
       
       image.attr('src', '/@/p4cardesign/favorites/rotater.gif');
       image.attr('alt', 'Подождите...');
       
       AC.simple('?LRPC=p4cardesign.favorites.act_del&args={}', 'POST', {'module_id' : module_id, 'ref_id' : ref_id},
          function(txt) {
    	     image.attr('src', '/@/p4cardesign/favorites/notadded.png');
             image.attr('alt', 'Добавить в закладки');
             anchor.removeClass();
             anchor.addClass('small_move_to_storehouse_anchor');
             anchor.attr('alt', 'small_move_to_storehouse_anchor_' + module_id + '_' + ref_id);
             anchor.unbind();
             anchor.bind('click', function(event) {
            	 				small_move(event, this);
             					});
      	   });
    }
   
});