Looks like you're in quite a mess, but don't worry, I think that you can get through this. If what you say is true then this is a classic example of "illegal search and seizure". The police cannot open the door and search your car unless they have reason to believe that you have broken the law. If you can prove that this was a case of illegal search and seizure then all evidence the police had obtained through the illegal search gets thrown out and it cannot be used against you.
However, if the police can prove that they had good reason to search the car then it could be a whole other story. They could use your friends frantic babbling as a piece of evidence (keep in mind, it is VERY important what your friend said and how he said it, it could make or beak you). They could also claim to have seen it lying on the floor (they ARE allowed to peek in the car, but not the open the door). They could try any number of things, and knowing the crooked cops I would wager that they would make something up just to get you convicted.
My advice: get a good lawyer and you MAY be able to win this, but it's a tough call. Remember, just because you're in the right doesn't mean that you will win the case, the jury may find you guilty regardless of whether their activity was legal or not. It all depends, there are FAR too many variables to properly predict this. Best of luck, pray the jury are a bunch of stoners