function opacity(id, opacStart, opacEnd, millisec) 
{
	var speed = Math.round(millisec / 100);
    var timer = 0;

    if (opacStart > opacEnd) 
	{	
		for (i = opacStart; i >= opacEnd; i--)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    } 
	else if (opacStart < opacEnd)
	{
		for (i = opacStart; i <= opacEnd; i++) 
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
			timer++;
		}
	}
}

function changeOpac(opacity, id)
{
	var object = document.getElementById(id).style;
    
	object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

function blendimage(divid, imageid, imagefile, millisec) 
{
	var speed = Math.round(millisec / 100);
    var timer = 0;
	
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";

    changeOpac(0, imageid);

    document.getElementById(imageid).src = imagefile;

    for (i = 0; i <= 100; i++)
	{
		setTimeout("changeOpac(" + i + ",'" + imageid + "')", (timer * speed));
        timer++;
    }
} 

function timerloop() 
{
	if (typeof timerloop.i == 'undefined')
	{
		timerloop.i = 1;
		var ret = setTimeout(timerloop, 6000);
		return;
	}
	
	++timerloop.i;
	if (timerloop.i == 5) timerloop.i = 1;
	
	switch(timerloop.i)
	{
		case 1: blendimage("blend", "blend-image", "./image/control-module-industries-time-management-splash.jpg", 750);
		document.getElementById('slide-link').href = "./time-management";
		document.getElementById('blend-image').alt = "Time Management Division";
		break;

		case 2: blendimage("blend", "blend-image", "./image/control-module-industries-cabaire-splash.jpg", 750);
		document.getElementById('slide-link').href = "./cabaire";
		document.getElementById('blend-image').alt = "CabAire Division";
		break;

		case 3: blendimage("blend", "blend-image", "./image/control-module-industries-evse-splash.jpg", 750);
		document.getElementById('slide-link').href = "./evse";
		document.getElementById('blend-image').alt = "EVSE Division";
		break;

		case 4: blendimage("blend", "blend-image", "./image/control-module-industries-fleet-management-splash.jpg", 750);
		document.getElementById('slide-link').href = "./fleet-management";
		document.getElementById('blend-image').alt = "Fleet Management Division";
		break;
	}
	
	var ret = setTimeout(timerloop, 6000);
}
        
window.onload = function() {timerloop();};
