var _currentLob = 0;
var _rotateLob = true;
var _currentlyFading = false;
var _currentOpacity = 0;
var _backgroundDiv = null;
var _bigImage = null;
var _ratingImage = null;

//setTimeout("LobNext2()", 7000);

function LobNext() {
    _rotateLob = false;
    if (_currentlyFading)
    {
        return;
    }
    LobNext2();
}

function LobNext2() {
    _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);
        _ratingImage = document.getElementById(_ratingImageId);
    }
    
    document.getElementById("lobtoptext1").innerHTML = _lobTopText1[_currentLob];
    document.getElementById("lobtoptext2").innerHTML = _lobTopText2[_currentLob];
    document.getElementById("lobtoptext3").innerHTML = _lobTopText3[_currentLob];
    document.getElementById("lobtoptext4").innerHTML = _lobTopText4[_currentLob];
    document.getElementById(_bigImageLinkId).href = _recipeLinks[_currentLob];

    //_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];
    _ratingImage.src = _ratingSrc[_currentLob];
    _currentOpacity = 0;    
    setTimeout("nextFade()", 50);
}

function nextFade() {
    _currentOpacity += 10;
    changeOpacity(_currentOpacity, _bigImage);
    if (_currentOpacity < 100)
    {
        setTimeout("nextFade()", 50);
    }
    else
    {
        fadeComplete();
    }
}

function fadeComplete() {
    //_backgroundDiv.style.backgroundImage = "url(" + _bigImage.src + ")";
    
    _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);	
}


