<image> As shown in the figure, a rectangular flower bed is fenced with 12 meters of fence on three sides, with one side resting against the school wall. Let the length of side \(AB\) of rectangle \(ABCD\) be \(x\) meters, and the area be \(S\) square meters. 
(1) Write the function that relates \(S\) to \(x\);
(2) What value of \(x\) maximizes the area \(S\), and what is the maximum value?