jQuery(function CardesignAvatar() {

	jQuery("body").bind('click', function () {
     	jQuery('.p4cardesign_clickable_avatar_content').remove();
     	jQuery('.p4cardesign_active_avatar').removeClass('p4cardesign_active_avatar');
	});

   jQuery('.p4cardesign_clickable_avatar').bind('click', function (event) {
     event.preventDefault();
     event.stopPropagation();   
     jQuery('.p4cardesign_clickable_avatar_content').remove();
     jQuery('.p4cardesign_active_avatar').removeClass('p4cardesign_active_avatar');
     
     
	  
     var user_profile_path = this.href;
     var profile_url = this.href;
     profile_url = profile_url.replace(location.protocol + "//" + location.host  + "/profile/", '');
     var user_id = profile_url.replace("/","");

     jQuery(this).addClass('p4cardesign_active_avatar');
     var height = jQuery(this).children(":first-child").height();

     jQuery(this).html(jQuery(this).html() + '<div class="p4cardesign_clickable_avatar_content"><img src="/@/comment/rotater.gif" style="width:20px !important; height:20px !important" /></div>');
  
     AC.simple('?LRPC=p4cardesign.profile.useravatar&args={}', 'POST', {'uid' : user_id },
         function(txt) {
            if (txt == 0) {
               location.href = user_profile_path;
            } else {
               jQuery('.p4cardesign_clickable_avatar_content').html(txt);
               
               jQuery('.p4cardesign_active_avatar_list a').bind('click', function (event) {
                  event.preventDefault();
                  event.stopPropagation();
                  location.href = this.href; 
               });
               
               event.stopPropagation();       
            }
         }
      );
   }); 
})


