﻿var rotators = [];

// Use this function to resolve IE scope issues
var handleInterval = function(id)
{
	var scope = rotators[id];
	scope.swap();
}


	
function loadRotator()
{
    var spans = document.getElementsByTagName("span");
    for(var i in spans)
    {
		if(spans[i].className == "imagerotator")
	    	new rotator(spans[i]);
    }
}
    
rotator = function(el) 
{
    this.el = el;
	
	// Unique index for this rotator
    this.rotatorIndex = 0;
	
	// Current image index
	this.imageIndex = 0;
    this.images = el.getElementsByTagName("img");
    this.interval = null;
    
	// Initialize rotator
    this.init = function()
    {
		this.rotatorIndex = rotators.length;
		rotators.push(this);
		
		this.swap();
	
        this.interval = setInterval("handleInterval(" + this.rotatorIndex + ")", 5000);
    };
    
	// Swap images
    this.swap = function()
    {
        for(var i = 0; i < this.images.length; i++)
		{
            if(i == this.imageIndex)
                this.images[i].style.display = "block";
            else
                this.images[i].style.display = "none";
		}
		this.imageIndex = (this.imageIndex + 1) % this.images.length;
    };
	
	this.init();
}
