var root = "http://www.ghidini-gb.it/";

function ImageRotator(ctrlid, images)
{
    this.index = 1;
    this.imageUrl = images.split(';');
    this.images = new Array();
    this.ctrl = ctrlid;
    
    this.Init();      
}

ImageRotator.prototype.Init = function()
{
    for(var x = 0; x < this.imageUrl.length; x++)
    {
        var img = new Image();
        img.src = root + this.imageUrl[x];
        this.images.push(img);
    }
}

var img;
var opacity = 0;
var objSave;
var enabled = true;

function MinusOpacity(obj)
{
    if(obj != null)
    {    
        objSave = obj;
        img = document.getElementById(obj.ctrl);

        if(img != null)
        {
            var delay = 1000;
            var step = 0;
            var maxStep = 20;
            var stepIncrement = 100;
                 
            for(; step < stepIncrement * maxStep; step += stepIncrement)
                setTimeout('incrementOpacity()', step);
            
            step += delay;
                            
            for(; step < delay + 2 * stepIncrement * maxStep; step += stepIncrement)
                setTimeout('decrementOpacity()', step);
        }
    }
}

function decrementOpacity()
{
    if(enabled == false)
        return;

    opacity -= 5;
    setOpacity(img, opacity);
    
    if(opacity == 0)
    {
        img.src = objSave.images[objSave.index++].src;
        if(objSave.index == objSave.images.length)
            objSave.index = 0;        
    }
}

function incrementOpacity()
{
    if(enabled == false)
        return;

    opacity += 5;
    setOpacity(img, opacity);
}

function setOpacity(obj, opacity) 
{
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}


