var curSL;
var SLImages;
var intervalID;

$(document).ready(function() {
		
	// Using custom configuration
	$("#home_sl_carousel").carouFredSel({
		items				: 1,
		direction			: "up",
		pagination			: "#home_sl_pagination",
		auto:{
			play:true,
			pauseDuration: 10000
		},
					
		scroll : {
			items			: 1,
			duration		: 1000,							
			pauseOnHover	: true
		}					
	});
	/*
	curSL = 0;
	SLImages = new Array();
	
	SLImages[0] = {url:"/what-we-do/",loc:"/images/home_sl_kai20.png",title:"20 Years doing work that matters"};
	SLImages[1] = {url: "/what-we-do/meeting-and-event-planning/",loc: "/images/home_sl_meeting.png",title:"Meeting and Event Planning"};
	SLImages[2] = {url:"/what-we-do/training-and-technical-assistance/",loc:"/images/home_sl_training.png",title:"Training and Technical Assistance"};
	SLImages[3] = {url:"/what-we-do/communications/",loc:"/images/home_sl_communications.png",title:"Communications"};
	SLImages[4] = {url:"/what-we-do/management-support/",loc:"/images/home_sl_management.png",title:"Management Support"};
	SLImages[5] = {url:"/what-we-do/research-and-evaluation/",loc:"/images/home_sl_research.png",title:"Research and Evaluation"};
	SLImages[6] = {url:"/what-we-do/grant-support/",loc:"/images/home_sl_grants.png",title:"Grant Support"};
	for(x=0;x<SLImages.length;x++)
	{
		eval("pic"+x+" = new Image(100,100)");
		eval("pic"+x+".src = 'http://new.kauffmaninc.com"+SLImages[x].loc+"'");
	}
	intervalID = setInterval("advance(1)",8000);
	updateSLCarousel();
	*/
});

function setCarouselDisplay()
{
	document.getElementById('home_sl_carousel').style.backgroundImage = "url("+SLImages[curSL].loc+")";
	document.getElementById('home_sl_link').href = SLImages[curSL].url;
	document.getElementById('home_sl_link').title = SLImages[curSL].title;
	
	$('#home_sl_bullets a img').each(function (i){this.src = "/images/home_sl_bullet.png"});
	$('#home_bullet_'+curSL+' img')[0].src = "/images/home_sl_bullet_full.png";
}

function updateSLCarousel()
{
	setCarouselDisplay();
}

function setIndex(v)
{
	clearInterval(intervalID);
	curSL = v;
	setCarouselDisplay();
	intervalID = setInterval("advance(1)",8000);
}

function advance(v)
{
	if((curSL + v) == SLImages.length)
		curSL = 0;
	else if((curSL + v) < 0)
		curSL = SLImages.length - 1;
	else
		curSL += v;
		
	clearInterval(intervalID);
	updateSLCarousel();
	intervalID = setInterval("advance(1)",8000);
}

