First, welcome to the forum. Sorry to hear about the hairy custody battle you have to go through and the anxiety it is causing you. You need to project the most stable and consistant appearance you can.
First, stop immediately all contact with illegal substances and any associations with friends, family, or anyone else you know who has access to them. Cleaning up your act is really important. To handle the anxiety, immediately go see your primary care physician and tell him that you need something for anxiety (explain your circumstances). Ask him for a recommendation for a psychologist/psychiatrist (someone who can prescribe medications for you) and a some type of talk therapist that can help you work through your anxiety issues.
You also need to stop constantly reviewing all the bad points of your relationship with your ex in your head. The details are not important now, except for the information you need to document for your custody case. Do you have an attorney to represent you? Are you living in a stable environment? Do you have family around to help you out? I know you said your court case was on Valentine's Day, but try to get all these things in the works before your court date, so the judge will take it seriously. Maybe you can even find a "parenting" class to sign up for in the meantime.
Anyway, I hope things go well for you and that this post helped you out a little. Let us know how thing are progressing.
"The weather is here, I wish you were beautiful."