var _currentLob = 0;
var _rotateLob = true;
var _currentlyFading = false;
var _currentOpacity = 0;
var _backgroundDiv = null;
var _bigImage = null;

setTimeout("LobNext2()", 7000);

function LobNext() {
    _rotateLob = false;
    if (_currentlyFading)
    {
        return;
    }
    LobNext2();
}

function LobNext2() {
    if (!_lobHasMultipleImages)
    {
        return;
    }
    
    _currentLob++;
    if (_currentLob >= _lobTops.length)
    {
        _currentLob = 0;
    }
    
    startFade();
}
function LobPrevious() {
    _currentLob--;
    if (_currentLob < 0)
    {
        _currentLob = _lobTops.length - 1;
    }

    startFade();
}

function nextRotate() {
    if (!_rotateLob) {
        return;
    }
    LobNext2();
    setTimeout("nextRotate()", 10000);
}

function startFade() {
    _currentlyFading = true;
    if (_backgroundDiv == null)
    {
        _backgroundDiv = document.getElementById("bigimtop");
        _bigImage = document.getElementById(_bigImageId);
    }

    _backgroundDiv.style.backgroundImage = "url(" + _bigImage.src + ")";
    // without this pause IE has flicker
    setTimeout("startFade2()", 100);
}

function startFade2() {
    changeOpacity(0, _bigImage);
    // without this pause the new image loads before the opacity applies
    setTimeout("startFade3()", 100);
}

function startFade3() {
    _bigImage.src = _lobTops[_currentLob];
    _currentOpacity = 0;    
    setTimeout("nextFade()", 50);
}

function nextFade() {
    _currentOpacity += 10;
    changeOpacity(_currentOpacity, _bigImage);
    if (_currentOpacity < 100)
    {
        setTimeout("nextFade()", 50);
    }
    else
    {
        fadeComplete();
    }
}

function fadeComplete() {
    
    var titleImage = document.getElementById(_titleImageId);
    titleImage.src = _lobTopImage2[_currentLob];

    if (_lobTopImage2Width[_currentLob] != undefined)
    {
        titleImage.style.width = _lobTopImage2Width[_currentLob] + "px";
    }

    if (_lobTopImage2Height[_currentLob] != undefined)
    {
        titleImage.style.height = _lobTopImage2Height[_currentLob] + "px";
    }
    
    _backgroundDiv.style.backgroundImage = "url(" + _bigImage.src + ")";
           
    document.getElementById("lobtoptext1").innerHTML = _lobTopText1[_currentLob];
    document.getElementById("lobtoptext2").innerHTML = _lobTopText2[_currentLob];
    
    var lobText3 = document.getElementById("lobtoptext3");
    if (lobText3)
    {    
        lobText3.innerHTML = _lobTopText3[_currentLob];
    }
    _currentlyFading = false; 
    
    if (_rotateLob)
    {
        setTimeout("LobNext2()", 7000);
    }
}

function changeOpacity(opacity, element) {
	var object = element.style; 
	object.filter = "alpha(opacity=" + opacity + ")";
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);	
}