//Written: 03/09/2010 02:57 PM
var _imageRotatorPaths = new Array();
var _imageRotatorStatus = new Array();
var _imageRotatorCurrent = new Array();
var _imageRotatorCurrentOpacity = new Array();

function ir_initImageRotate(imageClientId, divClientId)
{
    _imageRotatorCurrent[imageClientId] = 0;
    setTimeout("ir_startFade('" + imageClientId + "', '" + divClientId + "')", 5000);
}

function ir_startFade(imageClientId, divClientId) {
    _imageRotatorCurrent[imageClientId]++;

    if (_imageRotatorCurrent[imageClientId] >= _imageRotatorPaths[imageClientId].length)
    {
        _imageRotatorCurrent[imageClientId] = 0;
    }
    _imageRotatorStatus[imageClientId] = true;

    document.getElementById(divClientId).style.backgroundImage = "url(" + document.getElementById(imageClientId).src + ")";
    // without this pause IE has flicker
    setTimeout("ir_startFade2('" + imageClientId + "', '" + divClientId + "')", 100);
}

function ir_startFade2(imageClientId, divClientId) {
    ir_changeOpacity(0, document.getElementById(imageClientId));
    // without this pause the new image loads before the opacity applies
    setTimeout("ir_startFade3('" + imageClientId + "', '" + divClientId + "')", 100);
}

function ir_startFade3(imageClientId, divClientId) {
    document.getElementById(imageClientId).src = _imageRotatorPaths[imageClientId][_imageRotatorCurrent[imageClientId]]; //_lobTops[_currentLob];
    //_currentOpacity = 0;    
    _imageRotatorCurrentOpacity[imageClientId] = 0;
    setTimeout("ir_nextFade('" + imageClientId + "', '" + divClientId + "')", 50);
}

function ir_nextFade(imageClientId, divClientId) {
    _imageRotatorCurrentOpacity[imageClientId] += 10;
    ir_changeOpacity(_imageRotatorCurrentOpacity[imageClientId], document.getElementById(imageClientId));
    if (_imageRotatorCurrentOpacity[imageClientId] < 100)
    {
        setTimeout("ir_nextFade('" + imageClientId + "', '" + divClientId + "')", 50);
    }
    else
    {
        ir_fadeComplete(imageClientId, divClientId);
    }
}

function ir_fadeComplete(imageClientId, divClientId) {
    document.getElementById(divClientId).style.backgroundImage = "url(" + document.getElementById(imageClientId).src + ")";
           
    _imageRotatorStatus[imageClientId] = true;
    
    setTimeout("ir_startFade('" + imageClientId + "', '" + divClientId + "')", 5000);
}

function ir_changeOpacity(opacity, element) {
	var object = element.style; 
	object.filter = "alpha(opacity=" + opacity + ")";
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);	
}