function advanceCounter(state, carouselDiv) {
	var prevEnabled = false;
	switch(carouselDiv.attr("id")) {
		case "fullWidthCarousel":
			prevEnabled = fullEnabled;
		break;
		case "firstHalfCarousel":
			prevEnabled = firstEnabled;
		break;
		case "secondHalfCarousel":
			prevEnabled = secondEnabled;
		break;
	}
	if(state === "next") {
		carouselDiv.siblings(".dotCounter").children("img#current").attr("src","../images/lightdot.png");
		if(carouselDiv.siblings(".dotCounter").children("img#current").is(":last-child")) {
			carouselDiv.siblings(".dotCounter").children("img:first").attr("src","../images/darkdot.png");
			carouselDiv.siblings(".dotCounter").children("img:first").attr("id","next");
		} else {
			carouselDiv.siblings(".dotCounter").children("img#current").next().attr("src","../images/darkdot.png");
			carouselDiv.siblings(".dotCounter").children("img#current").next().attr("id","next");
		}
		carouselDiv.siblings(".dotCounter").children("img#current").removeAttr("id");
		carouselDiv.siblings(".dotCounter").children("img#next").attr("id", "current");
	} else if(state === "prev" && prevEnabled) {
		carouselDiv.siblings(".dotCounter").children("img#current").attr("src","../images/lightdot.png");
		carouselDiv.siblings(".dotCounter").children("img#current").prev().attr("src","../images/darkdot.png");
		carouselDiv.siblings(".dotCounter").children("img#current").prev().attr("id","next");
		carouselDiv.siblings(".dotCounter").children("img#current").removeAttr("id");
		carouselDiv.siblings(".dotCounter").children("img#next").attr("id", "current");
	}
};

function tinyInit(carousel, carouselDiv) {
	carouselDiv.siblings(".dotCounter").children("img:first").attr("src","../images/darkdot.png");
	carouselDiv.siblings(".dotCounter").children("img:first").attr("id","current");
	carouselDiv.siblings(".dotCounter").children("img").bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval($(this).attr("class")));
		$(this).siblings().attr("src","../images/lightdot.png");
		$(this).siblings().removeAttr("id");
		$(this).attr("id","current");
		$(this).attr("src","../images/darkdot.png");
	return false;
	});
	carouselDiv.parent().siblings(".jcarousel-next").bind('click', function() {
		carousel.next();
		advanceCounter("next",carouselDiv);
		return false;
	});
	carouselDiv.parent().siblings(".jcarousel-prev").bind('click', function() {
		carousel.prev();
		advanceCounter("prev",carouselDiv);
		return false;
	});
};

function prevCallback(carousel, button, enabled, carouselDiv) {
		switch(carouselDiv) {
			case "fullWidthCarousel":
				fullEnabled = enabled;
			break;
			case "firstHalfCarousel":
				firstEnabled = enabled;
			break;
			case "secondHalfCarousel":
				secondEnabled = enabled;
			break;
		}
};

$(document).ready(function() {
	var fullEnabled = false;
	var firstEnabled = false;
	var secondEnabled = false;



	// Initialize all work carousels.
	$("#fullWidthCarousel").jcarousel({
		scroll:1,
		animation:800,
		wrap:'last',
		initCallback: function (carousel) {tinyInit(carousel, $("#fullWidthCarousel"))},
		buttonPrevCallback: function (carousel, button, enabled) {prevCallback(carousel, button, enabled, "fullWidthCarousel")}
	});

	$("#firstHalfCarousel").jcarousel({
		scroll:1,
		animation:400,
		wrap:'last',
		initCallback: function (carousel) {tinyInit(carousel, $("#firstHalfCarousel"))},
		buttonPrevCallback: function (carousel, button, enabled) {prevCallback(carousel, button, enabled, "firstHalfCarousel")}
	});

	$("#secondHalfCarousel").jcarousel({
		scroll:2,
		animation:400,
		wrap:'last',
		initCallback: function (carousel) {tinyInit(carousel, $("#secondHalfCarousel"))},
		buttonPrevCallback: function (carousel, button, enabled) {prevCallback(carousel, button, enabled, "secondHalfCarousel")}
	});

	
});
