Your approach seems to be not correct. You don't want to download a username/password to the client, and then use that to get images from server. Having the user name and password on the browser will make them available to the world. However, if you don't care about anyone knowing the username and there is no password then your approach is okay.
1) If you are going to load the username to the client and you have no concern about security then use something like jquery's document ready function to go get your images using an asynchronous call. Keep in mind though that if your images are on a different server than your page came from that this operation is not allowed by the browser and is called cross site scripting. However, there are some work arounds for this including special javascript libraries.
2) If you password does need to be protected, then
you should have your web application server go get your images for your browser. The browser will only talk to your web application server and the web app server will act as a proxy to the images server, relaying the images through itself to the browser.