How does the volume control work on my iPod touch? OK, I'm going to sound like an idiot for asking this, but...

How's the volume control work on an iPod Touch (iOS 4)?  I always seem to surprise myself when I discover that the volume is up when I assume it's down, or vice versa.

I've owned (pre-iOS) iPod, and they were easy: there's one volume setting.  For the iPod Touch, having a speaker, running "OS X", and using the Mac OS X semi-transparent gray volume icon overlay, I figured it'd be just like my Mac.  That is, two separate volume settings, one for the speaker and one for the headphones, and it uses the correct one depending on whether there's something plugged in.

After a while, I found that it doesn't work this way.  I can't figure out quite how it works, though.  One thought was that maybe the volume control is per-app, but that doesn't seem to always be true, either.  Or is it per-app and per-headphones/speaker?

Another aspect that confuses me: when setting the volume, sometimes I get the Mac-style gray icon overlay, and sometimes it uses a round slider in the app itself.  It doesn't seem to be just the app: sometimes the YouTube app shows the gray overlay, even when its own slider is visible!  Is this visual distinction supposed to be useful to me?  It seems like it might be, but I haven't figured out the pattern yet.

Can anyone explain to me how this is supposed to work?  Or is there any official documentation on how the volume controls work?

I'm so confused...

EDIT: Example: I go to Flashcards, set the volume to 0%.  Go to home screen, set volume=50% (up from 25%).  Go to Youtube, set volume=25%.  Start playing a video, it shows volume=0% now (why?), so I turn it up to 25%.  Exit, go back to Flashcards, volume here is now 25% (why?).  (This is all with no headphones plugged in -- I'd like to understand the simple case before I even try to figure out how headphone volume works!)

It's obviously not simply a per-app setting: I've never set the volume in Flashcards to be anything other than 0%, yet it keeps getting turned up, in this case to the volume I set in Youtube.  But the Youtube volume isn't a global setting, either, since I set the volume on the home screen, and Youtube showed me 2 different volume settings (depending on whether a video was playing), and neither of them used that setting.

My next theory was that there's a "shared app volume" setting that was used by Flashcards and Youtube-but-only-when-not-playing-video (but not by the home screen, which is silly, since the home screen doesn't have any sound).  So I tried setting the volume in Youtube-not-playing-video and going back to Flashcards ... nope, in this direction the Flashcards volume stays the same.

My latest theory is that Youtube-not-playing-video can set the shared-app-volume, and Youtube-playing-video will read the shared-app-volume, and Flashcards will both set and read this volume.  (And Youtube itself has 2 volume settings, neither of which is the same as the one I set on the home screen, so I always have to just set the Youtube volume twice.  And double this if I decide to plug in headphones.)

This is the simplest theory I've found to explain most of what I'm seeing, but it seems completely insane.  If anybody has a way to explain this that doesn't involve epicycles, I'd love to hear it.
You’re technically right. There are two settings, one for the speaker, one for the headphones. Both volumes are independent; if you have volume low on speaker and connect a headphone, you’re going to get the headphone volume, and that’s what you’re going to adjust until you disconnect it. 

Now, applications can alter the device’s volume, but they can also have their own independent volume level. For example a game might have a volume setting and if you put it all the way down, the ipod’s volume (alarms, music, etc.) is not altered. As far as I can remember (should check the latest iOS SDK) that is possible. 

Applications can of course mute themselves without altering the device’s settings.