gold ends at record high of $1,004 as dollar weakens