Apple puts things into application layers rather than "every windows is equal" like windows does. This is a holdover from Switcher/MultiFinder which was the hack that allowed multitasking on the old OS. So Mac users think of "which application is active".
The key to telling which application is active is to watch the menubar. Right next to the apple on the left is the name of the current app.
With the advent of Cocoa, they changed it a little bit, there is still an application layer, but windows can intermix somewhat. IOW, its possible to have one Safari window be in front, then the Mail window behind it, then more Safari windows. However, if you close the current Safari window and the others are behind the windows of other applications, then the next frontmost Safari window will pop into the current Safari app layer (comes to the front).
I know it sounds complicated but you get used to it pretty fast. Window mixing only occurs when you switch apps by clicking on windows. If you click on an icon on the doc or use the alt-tab to switch apps, then all app windows are pulled into the app's layer.
Also, most apps continue to run even after the last window for that app is closed. To quit an app you have to select Quit from the app's menu (or cmd-Q). This is likely what happened when you switched to an app using alt-tab but found there were no windows.
You might start getting acquainted with expose (F9) - that'll help you see what all you have open.
I hope this helps.