For an arbitrary number of colors you could create a variable holding the last color, and then create a div and update the variable, e.g.
<switch $lastcolor>
<case ffffff><$lastcolor=cccccc>
<case cccccc><$lastcolor=ccffcc>
<default><$lastcolor=ffffff>
</switch>
<div style="background: $lastcolor">
.... <!-- The record display code -->
</div>
<switch $lastcolor>
<case ffffff><$lastcolor=cccccc>
<case cccccc><$lastcolor=ccffcc>
<default><$lastcolor=ffffff>
</switch>
<div style="background: $lastcolor">
.... <!-- The record display code -->
</div>