OpenLayers has some excellent in-built classes that can help you out quite a bit. I think the classes you are looking for are OpenLayers.Strategy.Filter and OpenLayers.StyleMap.
The Filter Strategy allows you to specify a Filter object to a layer that will hide features that do not match the filter.
The StyleMap allows you to define Style objects to the features based on attributes or computed attributes (function output).
For both of these, there are great examples that you can find online (using the Google) to see these classes in action.