If you plead guilty it doesn't matter if you are actually guilty or not.
Sorry, I wasn't very clear.
I mean it doesn't matter from a sentencing point of view - if you plead guilty then the legal system treats you as guilty whether you actually are or not. Obviously from a moral point of view then it really does matter for the reasons you state (and others).
"Pleading guilty at the first opportunity" is one of the biggest jokes in the legal system.
To a judge, this means the first time the defendant appears at crown court. However, he has had many other opportunities to admit his guilt, starting with the first of possibly several police interviews. However, they choose to remain silent, or deny the offence, demand a trial by jury (where this is possible) and at the last moment before the trial begins, plead guilty and get credit for it.
Meanwhile, many hours of police, court and witnesses time have been spent preparing full files, organising witnesses etc. By all means, give then SOME credit for avoiding a full trial but let's not kid ourselves that they weren't testing the system to make sure the prosecution had all the witnesses lined up ready to go and had not bottled out, and all other aspects of the case were watertight.
Almost completely wrong I'm afraid. The first opportunity is the first time you appear in front of a magistrates and get asked to enter a plea (with one exception, see below). The timing of this happening is completely out of the alleged criminal's control (the people deciding when it happens are a combination of the police, CPS and courts service). In most cases it happens well within 48 hours of arrest, and where it doesn't it's almost always because the police need more time to collect evidence before they believe that the person alleged to have committed the crime is guilty (e.g. police bail). During this time, occasionally lasting years, your civil liberties can be restricted regardless of whether they eventually charge you or not, let alone whether you are actually guilty.
There are only three circumstances in which a defendant gets seen in a crown court:
1. When they have plead not guilty to an offence at a magistrates court and the magistrates have referred the matter to the crown court for trial. If you plead guilty when arriving at crown court in this circumstance then you did not plead guilty at the first opportunity and you get some but not all of the credit for doing so. If you change your plea part way through a crown court trial you get even less credit (roughly proportional to how far though - e.g. more credit for pleading guilty after day 1 than after day 4).
2. When they have plead guilty to an offence at a magistrates court and the magistrates have referred the matter to the crown court for sentencing. This is where you get the full credit for pleading guilty (even for an either way offence, you do not get to choose the venue of sentencing if you plead guilty at a magistrates court). There is no big trial with witnesses, etc. as you describe, only a sentencing hearing.
3. When they have appeared at a magistrates court and the magistrates have referred the matter to the crown court without the defendant being asked to enter a plea. Only in this circumstance is the crown court your first opportunity to plead guilty, and if you do so then you will get the full credit.
However, it is important to remember that you have an absolute right to a fair trial and that includes the right to plead not guilty, regardless of whether you are or are not guilty.
You can plead guilty to a lesser crime than you have been charged with (e.g. you can plead not guilty to murder but guilty of manslaughter). If the prosecution accepts your guilty plea to the lesser charge then, AIUI, you get the same credit as you would have if you'd been charged with that crime in the first place. What happens in terms of any credit if the prosecution doesn't accept your lesser plea but the jury does I don't know.