I noticed that sometimes after a gym gets taken over the opposing team is able to add multiple Pokémon's without training. How much time is available to add a Pokémon to a friendly gym after its taken over? And do you have to be part of the battle to take over a gym in order to assign a pokemon?
When a gym loses its last defending pokemon, it gets set to zero prestige. Adding a pokemon gives a gym +2000 prestige. It just so happens that the first three gym slots require 0, 2000, 4000, 8000 prestige for the first four pokemon.
So when the first person adds a pokemon, the gym goes from 0->2000, opening a second slot. The second pokemon added makes the gym go from 2000->4000, opening a second slot. The third pokemon added makes the gym go from 4000->6000, meaning 2000 more prestige from training is required to add the fourth pokemon. Time is mostly irrelevant - you just need to get there fast enough (so people on your team don't take the "free" slots 2/3 or other team's don't knock the first guy out)
The reason a team is able to do this is because a gym receives 2000 prestige when a player places a Pokemon into the gym. The requirement to get to gym level 2 is 2000 prestige, so upon placing the first Pokemon into a gym it will straight away go to level 2, this provides room for a second Pokemon.
Since the prestige needed to get to level 3 is 4000 prestige, the same will happen when the second Pokemon is placed in the gym, it levels up to level 3 allowing a total of 3 Pokemon to be placed into a gym from scratch without training.
The next level (level 4) requires an additional 4000 prestige. So after placing the third Pokemon, an additional 2000 prestige is required.
To directly answer you questions:
There is no time limit, as long as the gym is at a high enough level and has room (ie. no one else beats you to placing a Pokemon at the gym) you can place your own.
No, you do not need to be a part of the battle, as long as the gym is under your team's control and has an empty spot, you can assign a Pokemon to defend it.
When you take over an empty gym by adding a Pokémon to it, the gym starts at level 2, which means that there is an empty space for someone else on your team to add a Pokémon of their own. They do not have to have participated in the battle; they just have to belong to your team. If there is no one with you when you take over a gym, you can leave the second slot empty for a future passerby--and if you happen to pass by a gym belonging to your team that has an empty slot, feel free to fill it.