function projectCarousel() {
	function onSlide(carousel, item, current_page, state) {
		$("#project_preview_current").text(current_page); // Update Page Count
		$("#project_preview_header").text(item.title); // Update Page Title
		
	}
	function projectInit(carousel) {	
		var pages = $('#project_preview_content').children().size(); // Number of pages
		
		/* Create the page title HTML */
		var pageTitleHTML = '<h4 id="project_preview_header"></h4>';
		
		/* Create the arrows */
		var arrowsHTML = '<ul id="project_preview_nav">';
		
		if (pages > 1) {
			arrowsHTML += '<li id="project_preview_prev" class="project_preview_arrow"><a href="#project_preview_content" title="Previous">Previous</a></li>'
			+ '<li id="project_preview_counter"><span id="project_preview_current">1</span> of <span id="project_preview_total">' + pages + '</span></li>'
			+ '<li id="project_preview_next" class="project_preview_arrow"><a href="#project_preview_content" title="Next">Next</a></li>';
		} else {
			arrowsHTML += '<li id="project_preview_prev" class="project_preview_arrow">Previous</li>'
			+ '<li id="project_preview_counter"><span id="project_preview_current">1</span> of <span id="project_preview_total">1</span></li>'
			+ '<li id="project_preview_next" class="project_preview_arrow">Next</li>';
		}
		
		arrowsHTML += '</ul><!-- End project_preview_nav -->';
		
		$("#project_header").append(pageTitleHTML + arrowsHTML); // Write title and arrows to header
		
		/* Capture clicks on previous/next arrows */
		$("#project_preview_prev").click(function(event) {
			event.preventDefault();
			carousel.prev();
		});
		$("#project_preview_next").click(function(event) {
			event.preventDefault();
			carousel.next();
		});
		
		/* Update total number of items */
		$("#project_preview_total").text(pages);
/*
		// Create "next" and "previous" controls
		var controls_list = $('#poster_controls ul'); // Find this element once and reuse it below to cut down on DOM searching
		var controls = "<a href='#poster' class='carousel_control carousel_prev' title='See previous poster content'>Previous</a><a href='#poster' class='carousel_control carousel_next' title='See next poster content'>Next</a>";

		controls_list.after(controls);

		// Create pagination controls
		for(i=1; i <= pages; i++) {
			controls_list.append("<li><a href='#poster' id='page" + i + "' + title='See poster page: " + i + "'>" + i + "</a></li>");
		}

		// Set first page indicator to current
		$('#poster_controls ul li:first-child').addClass('current');
*/
/*
		// Bind click function to pagination controls
		$('#poster_controls li').bind('click', function() {
			carousel.scroll($.jcarousel.intval($(this).text()));
			$('#poster_controls li').each(function() {
				if ($(this).hasClass('current')) {
					$(this).removeClass('current');
				}
			});
			$(this).toggleClass('current');
			carousel.startAuto(0);
			return false;
		});
*/
/*
		// Disable autoscrolling if the user clicks the prev or next button.
		$('#poster_controls a.carousel_prev').bind('click', function() {
			carousel.prev();
			carousel.startAuto(0);
			execAppTapEvent(this, "Event65", false);
			return false;
		});

		$('#poster_controls a.carousel_next').bind('click', function() {
			carousel.next();
			carousel.startAuto(0);
			execAppTapEvent(this, "Event65", false);
			return false;
		});

		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
*/
	}
/*
	
*/
	$('#project_preview_content').jcarousel({
		auto: 0,
		animation: 250,
		easing: 'linear',
		scroll: 1,
		wrap: 'both',
		initCallback: projectInit,
		itemFirstInCallback: onSlide,
		buttonNextHTML: null,
		buttonPrevHTML: null
	});
}

$(document).ready(function() {
	if ($('#project_preview_content').length) { projectCarousel(); }
});
