
var obj1, obj2, cycle, fadeInCycle, fadeOutCycle, ads;

// Populate the ads array
ads = new Array();

ads[0] = new Object();
ads[0].href="";
ads[0].alt="New England";

ads[1] = new Object();
ads[1].href="";
ads[1].alt="Boston";

ads[2] = new Object();
ads[2].href="";
ads[2].alt="House";

ads[3] = new Object();
ads[3].href="";
ads[3].alt="Fuel Truck";

ads[4] = new Object();
ads[4].href="";
ads[4].alt="House";

ads[5] = new Object();
ads[5].href="";
ads[5].alt="Fuel Delivery";


//****************************************************
function StartAdCycle(id1, id2)
{
	obj1 = document.getElementById(id1);
	obj1.opacity = 1;
	obj1.fadeIn = true;
	obj1.fadeOut = false;
	obj1.ad = 1;

	obj2 = document.getElementById(id2);
	obj2.opacity = 0;
	obj2.fadeIn = false;
	obj2.fadeOut = true;
	obj2.ad = 2;
	
	cycle = setInterval(cycleImages, 12000);
}

function cycleImages()
{
	obj1.fadeIn = !obj1.fadeIn;
	obj1.fadeOut = !obj1.fadeOut;
	
	obj2.fadeIn = !obj2.fadeIn;
	obj2.fadeOut = !obj2.fadeOut;
	
	fadeInCycle = setInterval(fadeIn, 50);
	fadeOutCycle = setInterval(fadeOut, 50);
}

function fadeIn()
{
	var obj = (obj1.fadeIn == true ? obj1 : obj2);
	
	if (obj.opacity >= .5)
		obj.parentNode.href = ads[obj.ad - 1].href;
	if (obj.opacity >= 1)
	{
		clearInterval(fadeInCycle);
		obj.opacity = 1;
	}
	else
		obj.opacity += .05;
	setOpacity(obj);
}


function fadeOut()
{
	var obj = (obj1.fadeOut == true ? obj1 : obj2);
	
	if (obj.opacity <= 0)
	{
		clearInterval(fadeOutCycle);
		obj.opacity = 0;
		swapImage(obj);
	}
	else
		obj.opacity -= .05;
	setOpacity(obj);
}


function setOpacity(obj)
{
	obj.style.opacity = obj.opacity;
	if (obj.filters)
		obj.filters.item("alpha").opacity = obj.opacity * 100;
}


function swapImage(obj)
{
	if (obj.ad % 2 == 0)
	{
		if (obj.ad < ads.length - 2)
			obj.ad += 2;
		else
			obj.ad = 1;
	}
	else
	{
		if (obj.ad < ads.length - 1)
			obj.ad += 2;
		else
			obj.ad = 2;
	}
	
	obj.src = "images/slideshow/" + obj.ad + ".jpg";
	obj.alt = ads[obj.ad - 1].alt;
}
