function initCarousel(index) {

	/* ----- story names ------ */
	var horseNames = new Array();
	horseNames[1] = 'Mission & Goals';
	horseNames[2] = 'Business Packages';
	horseNames[3] = 'Personal Packages';
	horseNames[4] = 'Consulting Services';
	horseNames[5] = 'Development Process';
	

    /* ----- procedural setup >>>> ----- */
    var root = index;
    var horseCount = $("#"+root+" .horses li.horse").size();
    var startHorse = 0;

    // get the width of the wrapper window
    var trackSize = $("#"+root+" #carousel").width();
    // get the width of an individual item
    var horseSize = $("#"+root+" .horses li:first").width();
    
    // figure out how many items fit in the window
    var horsesPerPage = Math.floor(trackSize / horseSize);
    var pagesOfHorses = Math.ceil(horseCount / horsesPerPage);
    
    // set the width of the list of shows
    var horsesSize = trackSize * pagesOfHorses;
    $("#"+root+" ul.horses").css("width", horsesSize);

    // set the page to that of the current show
    var startPage = Math.floor(
        startHorse / horsesPerPage
    );
    
    $("#"+root+" .horses").css({ left: "-"+(startPage * trackSize)+"px" });
    
    var currentIndex = startPage;
    manuSlide(startPage);

    // set the thumbnail of the current show
    $("#"+root+" .horses li:eq(" + startHorse + ")").addClass("select");
    
    // build the indexes list
    $("#"+root+" #carousel-interact").prepend("<ol class=\"indexes\"></ol>");
    $("#"+root+" .horses li.horse").each( function(i) {
        i++;
        $("#"+root+" ol.indexes").append("<li class=\"index\"><a href=\"#slide" + i + "\">" + horseNames[i] + "</a></li>");
    });
    $("#"+root+" ol.indexes li.index:eq(0)").addClass("select");
    
    // show the controls if there is more than one horse
    if( horseCount > 1 ) {
        $("#"+root+" #carousel-interact").show().animate({ bottom: "0px" }, 500);
    }
    
    // autoplay the slideshow
    var horseInterval;
    startAutoPlay();
    
    
    /* ----- <<<< procedural setup ----- */

    /* ----- general functions >>>> ----- */

    // manual click on a particular horse
    function manuSlide(page) {
		oldIndex = currentIndex;
		currentIndex = page;
        slideShowsList(currentIndex);
        $("#"+root+" .indexes .index").eq(oldIndex).removeClass("select");
        $("#"+root+" .indexes .index").eq(currentIndex).addClass("select");
	}

    // step from one horse to another
    function stepSlide(direction) {
        oldIndex = currentIndex;

        // move forward
        if( direction == "next" ) {
            currentIndex = (oldIndex + 1) % pagesOfHorses;
        }

        // move backward
        else if( direction == "prev" ) {

            // if the departing horse is not the first one
            if( oldIndex > 0 ) {
                currentIndex = (oldIndex - 1) % pagesOfHorses;
            }

            // if the departing horse is the first one
            else if( oldIndex == 0 ) {
                currentIndex = pagesOfHorses - 1;
            }
        }

        slideShowsList(currentIndex);
        $("#"+root+" .indexes .index").eq(oldIndex).removeClass("select");
        $("#"+root+" .indexes .index").eq(currentIndex).addClass("select");
    }
    
    
    // handle autoplay slides
    function autoSlide() {
        stepSlide("next");
    }


    // slide the carousel
    function slideShowsList(slideTo) {
        $("#"+root+" .horses").animate({ left: "-"+(slideTo * trackSize)+"px" }, 200 );
    }
    
    function startAutoPlay() {
    	if( index == 'carousel-wrapper' ){
	        horseInterval = setInterval(autoSlide,5500); //time in milliseconds
    	    $("#"+root+" .controls .playpause a").removeClass().addClass("playing").text("playing").attr("title","Pause show");
    	}else{
    	    horseInterval = setInterval(autoSlide,3500); //time in milliseconds
    	    $("#"+root+" .controls .playpause a").removeClass().addClass("playing").text("playing").attr("title","Pause show");
    	}
    }
    function stopAutoPlay() {
        clearInterval(horseInterval);
        $("#"+root+" .controls .playpause a").removeClass().addClass("paused").text("paused").attr("title","Play show");
    }

    /* ----- <<<< general functions ----- */


    /* ----- interactive buttons >>>> ----- */

    // click on the next button
    $("#"+root+" .controls .next a").click(function(e) {
        e.preventDefault();
        stepSlide("next");
        stopAutoPlay();
    });

    // click on the prev button
    $("#"+root+" .controls .prev a").click(function(e) {
        e.preventDefault();
        stepSlide("prev");
        stopAutoPlay();
    });

    // click on the play/pause button
    $("#"+root+" .controls .playpause a").click(function(e) {
        e.preventDefault();
        var autoplaystate = $(this).attr("class");
        if(autoplaystate == "paused") {
            startAutoPlay();
        } else {
            stopAutoPlay();
        }      
    });

    // click on an index button
    $("#"+root+" .indexes .index").click(function(e) {
        e.preventDefault();
        var thisPage = $("#"+root+" .indexes .index").index(this);
        manuSlide(thisPage);
        stopAutoPlay();
    });

    /* ----- <<<< interactive buttons ----- */
}

$(document).ready(function(){
    initCarousel("carousel-wrapper");
});