function findNextImage(img) 
{
    while(img && img.tagName != 'A' && img.tagName != 'IMG')
		img = img.nextSibling;
	
    return img;
}

function getNextImage(image, container) 
{
    if(!(next = findNextImage(image.nextSibling))) 
		next = findNextImage(container.firstChild);
		
    return next;
}

function setGlobOpacity(obj, o) 
{
    obj.style.opacity = (o / 100);
    obj.style.MozOpacity = (o / 100);
    obj.style.KhtmlOpacity = (o / 100);
    obj.style.filter = 'alpha(opacity=' + o + ')';
}

function blendContainer(id, stop) 
{
    container = document.getElementById(id);
    image = findNextImage(container.firstChild);

    blend(image, 0, stop, container);
}

function blend(image, opacity, stop, container) 
{
    image.style.display = 'inline';
	
	opacity = opacity + 5;
	setGlobOpacity(image, opacity);

    if (opacity > 100) 
	{		
		setTimeout(function () {blendOff(image, 100,  stop, container)},  stop);
    } 
	else
	{
		setTimeout(function () {blend(image, opacity,  stop, container)}, 50);
	}
}

function blendOff(image, opacity, stop, container)
{
	if(opacity > 0)
	{
		opacity = opacity - 5;
		
		setGlobOpacity(image, opacity);
		setTimeout(function () {blendOff(image, opacity, stop, container)}, 50);
	}
	else
	{
		image.style.display = 'none';
		blend(getNextImage(image, container), 0,  stop, container);
	}
}

function init() 
{
    blendContainer('sponsorsleft', 10000);
    blendContainer('sponsorsright', 10000);
    blendContainer('headerimgs', 5000);
//    blendContainer('sponsorscenter', 5000);
}

window.onload = init;