A theory of algebraic cocycles