// JavaScript Document
src = ["http://www.healthehuman.com/media/images/home/home_first.png", 
	"http://www.healthehuman.com/media/images/home/home_weightloss.png",
	"http://www.healthehuman.com/media/images/home/home_highbloodpressure.png",
	"http://www.healthehuman.com/media/images/home/home_diabetes.png",
	"http://www.healthehuman.com/media/images/home/home_fibromyalgia.png",
	"http://www.healthehuman.com/media/images/home/home_ibs.png"]
links = ["http://www.healthehuman.com/features", 
	"http://www.healthehuman.com/weight-loss",
	"http://www.healthehuman.com/high-blood-pressure",
	"http://www.healthehuman.com/diabetes",
	"http://www.healthehuman.com/fibromyalgia",
	"http://healthehuman.com/irritable-bowel-syndrome"]
duration = 10;

runCount=0;
selectedPos=0;
running=true;
imgNext=null;
nextPos=0;

function setPosition(inPos)
{
	running=false;
	setSlidePosition(false);
	selectedPos=inPos;
	document.getElementById("imageAd").src = src[selectedPos];
	document.getElementById("linkAd").href = links[selectedPos];
	setSlidePosition(true);
}

function startEffect()
{
	if (running)
	{
		runCount++;
		if (runCount > 1)
		{
			$('#imageAd').fadeOut('fast', switchImage);
		}
		else
		{
			loadNext();
			setTimeout("startEffect()", duration * 1000);
		}
	}
}

function switchImage()
{
	setSlidePosition(false);
	selectedPos++;
	if (selectedPos >= src.length)
	{
		selectedPos = 0;
	}
	document.getElementById("imageAd").src = src[selectedPos];
	document.getElementById("linkAd").href = links[selectedPos];
	setSlidePosition(true);
	$('#imageAd').fadeIn('fast');
	loadNext();
	setTimeout("startEffect()", duration * 1000);
}

function loadNext()
{
	nextPos = selectedPos + 1;
	if (nextPos >= src.length)
	{
		nextPos = 0;
	}
	imgNext = new Image;
	imgNext.src = src[nextPos];
}
	
function setSlidePosition(select)
{
	document.getElementById('slideImage' + selectedPos).src = "http://www.healthehuman.com/media/theme/" + (select ? "slide_selected.gif": "slide.gif");
}

onload = function()
{
	if (document.images)
	{
           startEffect();
	}
}
