var ImageRotator = function(id, images, timeout) { 
    this.id = id; 
    this.current = 0; 
    this.images = images; 
    this.timeout = timeout; 
    this.ir = $(id);
    this.iri = $(id + '_img');
    this.opacity = 0.0;
    this.preloader = [];
    setTimeout('ImageRotator.Rotate(\'' + this.id + '\')', this.timeout);
    for (var i = 1; i < this.images.length; i++) {
        var img = new Image();
        img.src = this.images[i];
        this.preloader[i] = img;    
    } 
}
ImageRotator.Rotate = function(id) {
    var h = $(id).h;    
    h.ir.style.backgroundImage = 'url(' + h.iri.src + ')';
    h.iri.setOpacity(0.0);
    h.opacity = 0.0;
    h.current++;
    if (h.current >= h.images.length)
        h.current = 0;
    h.iri.src = h.images[h.current]; 
    ImageRotator.FadeIn(h.id);
}
ImageRotator.FadeIn = function(id) {
    var h = $(id).h;
    h.opacity += 0.01;
    h.iri.setOpacity(h.opacity);  
    if (h.opacity < 1)
        setTimeout('ImageRotator.FadeIn(\'' + id + '\')', 50);
    else
        setTimeout('ImageRotator.Rotate(\'' + h.id + '\')', h.timeout); 
}

