ありがとうございました is the past tense (or more precisely, completion), so it is used only when something was already done and you want to say thank you.
ありがとうございます can be taken as a general statement or present tense, so you can use it both ways - to express gratitude for something always being done for you, or something that is going to be done (but not yet).
(You're visiting a teacher. You and she were talking about a certain book.)
あの本を読みたいですか? Would you like to read that book?
はい、読みたいです。 Yes, I do.
では、貸してあげましょう。 Then, I'll rend it to you.
ありがとうございます。よろしくお願いします。 Yes please, thank you.
(She stands up and go to her book shelf, and is trying to find the book in question.
You say to her back

いつも本を貸してくださって
ありがとうございます。 Thank you for always rending me books.
(She came back to you with the book, and is handing it to you.)
さあ、どうぞ。Here you are.
ありがとうございます。 Thank you.
(3 days later, you met the teacher again.)
この前は本を貸してくださって
ありがとうございました。 Thank you for rending me the book the other day.
どういたしまして。またいつでもどうぞ。 You're welcome. Anytime.
----
Hope this helps.
