To further expand on what a number of people have said:
1. you need to decide from which parcel or parcels of shares purchased you are selling. 2. You then need to work out the gain/loss on EACH parcel sold 3. If the parcel was held for less than 12 months, the full gain/loss is taxable 4. If the parcel was held for more than 12 months then remember that only 50% of the gains are added to taxable income
So, there is no such thing as an average purchase price. Each purchase must be accounted for as an individual parcel when the shares are sold. You may use an average for tracking portfolio performance etc, but when you account to the tax man there is no such animal as an average. Each purchase is handled on its own.
The end result is you need good record keeping. Records to track which parcel or parcels have been sold in a partial sell off and to be able to fully track all costs etc.