First of all I suggest you contact an attorney should a dispute arise between your landlord and yourself. My answer is going to be based on the common law as taught in law school; however, our cases were Illinois cases and therefore could be applicable.
In order for a landlord to keep any of your security deposit he or she must provide you with an itemized account of repairs, etc that had to be made as a result of your damage to the property. An example might be a new closet door that you put a hole in.
It used to be (and might still be) that landlords had to provide a warranty of habitability to renters. In other words, landlords could not rent out property that had serious problems such as toilets that didn't work, no heat in the winter, or serious mold problems. There are cases where tenants recovered money damages from landlords under this theory.
It sounds as if the water damage and resulting mold problem were caused due to a defect in the property itself as opposed to damage you caused. Without knowing all of the facts, in my opinion your landlord would not be entitled to retain any of your security deposit for any of the water damage and/or mold.
If you broke your lease by moving out early your landlord might attempt to keep your security deposit; however, it you broke your lease because of his inability to fix the mold and water problem (which could be legitimate health concerns) you may have a defense and be entitled to your security deposit ,minus any real damage caused be you. Again, I suggest you consult an attorney because my understanding of the law might be outdated. Good luck.