Pseudo code for AJAX login needed

I want to create a website.
I am starting AJAX and advanced in PHP/Flash ActionScript. The requirements are:

Every page contains the login form on the top(username, password, login button, register button and Password recovery button).

User can login from any page. After clicking Login button, the page must not be reloaded. It can be achieved using XMLHttpRequest.

After login, username and password field have to disappear and a Welcome message with Name of the person shows; and also the button Login changes to Logout.
There are five main pages; we can enter two of them as guest and other pages require login. So, show the first two buttons before login and All of them after login without reloading the page.
PHP is used for communicating with database. The php login SESSION is used so keep logged while navigating other pages until log out.
Please share your ideas… Thanks in advance…