Funk is a slang term with a good deal of meanings. It can mean a somewhat intangible quality attributed to certain music; whether or not it is in the actual musical genre by that name. Tends to mean music that (regardless of whether the tempo of the song is actually appropriate for dance music) encourages one to move. Usually characterized by strong
rhythm guitar, bass and bursts of
horns on the upbeat. Something or someone can "have funk" or "the funk." (This kind of adds another meaning since funk can also be something you can posess, like say
The Force).
Funky can mean weird or offbeat (even as a compliment), but it's sometimes used more specifically to mean unusual and questonable, or just worthless, like fishy. But funky can also mean cool (see also groovy). This due to the same kind of intentional inversion that created terms like "bad" and "wicked," and started in the american black population in the 30's. It also of course means an odd or offensive smell. "In a (blue) funk" means "in a bad mood" or "in a state of panic or terror."
The origin of most of the usages of this word is difficult to discern. The phrase "in a funk" originated as Oxford (UK) slang in the mid-eighteenth century, and seems to originate from a Flemish phrase in de fonck siin, which also meant "in a state of panic." A (presumably separate) deprecated slang term is "a Peter Funk", which means bidder at an auction who works for the auctioneer, bidding high to stimulate competitive bids - this was sometimes also shortened to simply "funk." I don't know if it's considered that that contributed to the modern meaning.
So many and varied are the meanings, people have started to use it as a word that pretty much describes pretty much anything. The musical sense may have in part come from a venue in New Orleans colloquially referred to as "Funky Butt Hall." I don't know if that scene has a particular place in musical history to be so honored, or the term just snowballed.
As for "in a blue funk", at the time when that phrase originated in England, "blue" was popular as an emphatic term (don't ask me why). Hence, a "blue funk" was a state of especially dire panic.