In the early 70s Lucas began working on a massive "Space Opera" called "The Star Wars". What he ended up with was a 12 part ... yes, 12 part story that was to be told in the manner of the old Flash Gordon series of the late 50's & 60's. He saw the changes happening in the industry and realized that it wouldn't work that way so he then cut it down to a 9 part 3 trilogy story. The first trilogy was to be about the rise and fall of Anakin Skywalker; the second trilogy was to be about the rise of Luke Skywalker and the redemption of Anakin Skywalker; the third trilogy was to be about the "other Skywalker" that Yoda mentions in ep V and again in ep VI. Lucas started showing the story to all the big movie production companies of the day and was told by all of them that the paper the story was written on wouldn't even make good toilet paper. Disappointed but not discouraged Lucas continued to work on the script and with the success of American Graffiti he gained a little clout in Hollywood so he started around with his Star Wars story again. Most still thought it wasn't worth making but FOX decided to roll the dice, still thinking it would be a flop, and gave Lucas the start up money that he needed to get to work on Star Wars.
As for did he have them all written and just start in the middle ... yes and no. Yes, he did have a general outline and what would happen in each trilogy set down but nothing was written in stone. No because that general outline that he had was NOT what we ended up seeing on the big screen. You can trace it right back to the event that changed the story and sent it in a different direction ... Lucas changed things so that Anakin and Vader were the same person ... yep, in the first outlines of the story they were two different people. The other thing that can be seen as changing the way the story went was when Lucas decided to make Leia the "other Skywalker". The duel between Luke and Vader in ep VI was the main reason why this change was made. Lucas was stumped on how to get Luke to attack his father in a dark side fueled rage, he did this by making Leia the "other Skywalker" and having Vader threaten her. This change had 3 major effects on the saga, first, everybody went EEWWWWW ... he kissed his sister ... on the lips ... lol ... second, it eliminated the third trilogy ... third it brought Harrison Ford back on board for the last movie. Ford thought that ending up frozen in a block of carbonite was the perfect way for Solo to die but when Lucas told him about the change and that the character would live on Ford changed his mind and came back for ep VI.
When Lucas decided to make the prequels he had a couple very huge things standing in his way. First, how was he ever going to make 3 more movies as good or better than the OT ... it couldn't be done. Second, much of the back story that he had laid out years ago was now junk because of the events of the OT so he had to go back in and write new scripts for them.
Source
https://answers.yahoo.com/question/index?qid=20081007152125AAu750N