var $imageCnt;
$(document).ready(function(){

	// This initialises carousels on the container elements specified, in this case, carousel1.
	$("#carousel1").CloudCarousel(
		{
		  xPos: 290,
		  yPos: 50,
		  buttonLeft: $("#left-but"),
		  buttonRight: $("#right-but"),
		  altBox: $("#alt-text"),
		  titleBox: $("#title-text"),
      reflHeight: 70,
      reflGap: 0,
      minScale: 0.25,
      FPS: 24,
      yRadius: 120,
      xRadius: 290
		}
	);

	carouselOverHandler();
	carouselNavHandler();
	imageCntId = $("img.cloudcarousel").attr("id");
	$imageCnt = getToken(imageCntId, 2, '_');
	$sumImageCount = $("img.cloudcarousel").length;

});

function carouselOverHandler() {
	$(".cloudcarousel").mouseover(function() {
		$longText = $(".longtext", $(this).next(".cloudcarouseltext")).html();
		$shortText = $(".shorttext", $(this).next(".cloudcarouseltext")).html();
    $pdfBerater = $(".pdf_berater", $(this).next(".cloudcarouseltext")).html();
    $pdfCoaching = $(".pdf_coaching", $(this).next(".cloudcarouseltext")).html();
		$(".carousel").html($longText);
		$(".carouselShort").html($shortText);
    $(".carouselPDF").html($pdfBerater);
    $(".carouselPDF2").html($pdfCoaching);
	});
}

function carouselNavHandler() {
  $("#right-but, #left-but").click(function() {
    $imageCnt = parseInt($imageCnt)+ (($(this).attr('id') == 'right-but') ? -1 : 1);

		if($imageCnt <= 0)
		  $imageCnt = $sumImageCount;
		else if($imageCnt >=($sumImageCount+1)) {
			$imageCnt = 1;
		}

    $longText = $(".longtext", $("#image_"+$imageCnt).next(".cloudcarouseltext")).html();
    $shortText = $(".shorttext", $("#image_"+$imageCnt).next(".cloudcarouseltext")).html();
    $pdfBerater = $(".pdf_berater", $("#image_"+$imageCnt).next(".cloudcarouseltext")).html();
    $pdfCoaching = $(".pdf_coaching", $("#image_"+$imageCnt).next(".cloudcarouseltext")).html();
    $(".carousel").html($longText);
    $(".carouselShort").html($shortText);
    $(".carouselPDF").html($pdfBerater);
    $(".carouselPDF2").html($pdfCoaching);
  });
}

