Cycling though different materials on mouse click

I'm trying to set up a script that allows me to repeatedly click on an object to cycle through the material array.

I know I can use the following function to access the material but I'm unsure how to cycle through the array.

function OnMouseDown(){    
object.renderer.material.mainTexture = texture;

Any help would be appreciated.

Something along the lines of this:

var textures : Texture2D[];
var current : int = 0;

function OnMouseDown()
    //increment, wrap around when it hits the end of the array
    if (++current >= textures.Length) current = 0;

    //assign from the array at the current index
    renderer.material.mainTexture = textures[current];