Problem when visiting users profiles
You can get the user id from url using arg() function. for the first part you can do something like this.

global $user;
$user_id = arg(1);
if($user-&gt;uid == $user_id) {
// means it is logged in user profile - so show edit link


}


For the second part you are loading profile of logged in user, that is why it is always showing your picture you need to do the following instead.

$user_item = user_load($user_id); // user id we got from arg()
print theme('user_picture', array('account' =&gt;$user_item));