One day, SpongeBob wakes up and plays fetch with Gary. When SpongeBob throws the stick, Gary digs up a treasure chest. He brings the treasure chest to SpongeBob and he finds a magic bottle. Rubbing the bottle releases coins all over Bikini Bottom and the Flying Dutchman appears. The Flying Dutchman tells SpongeBob that he will take Gary to work on his ship, but SpongeBob responds by begging to be taken to work on The Flying Dutchman instead of Gary. The Flying Dutchman decides to give Gary some time before taking him.
SpongeBob now must find all the letters that spell his name. Doing so, he will find treasure. After finding the first treasure, the Flying Dutchman takes Gary. SpongeBob discovers that the only way to defeat the Flying Dutchman is by collecting all of the seven items he carried close to him while he was alive.
Source: Wikipedia, "SpongeBob SquarePants: Revenge of the Flying Dutchman", available under the CC-BY-SA License.