function CreateCarousel(vert, auto)
{	//		auto : auto,
	$('#tvcarousel').jcarousel
	({
		vertical : vert,

		wrap : 'circular',
		auto : 5,
        itemLoadCallback: LoadCarouselItems
    });
}

function LoadCarouselItems(carousel, state)
{
    // Check if the requested items already exist
    if (carousel.has(carousel.first, carousel.last))
	{
        return;
    }

    jQuery.get
	(
        'api/query.php',
        {
            first : carousel.first,
            last : carousel.last,
			special : "top100tv",
			domain : "watch.io",
			cache : 'true',
			max : 10
        },
        function(data) {
            AddCarouselItems(carousel, carousel.first, carousel.last, data);
        },
        'json'
    );
};

function AddCarouselItems(carousel, first, last, data)
{
    // Set the size of the carousel
    carousel.size(data.episodes.length);

    for(var i = 0; i < data.episodes.length; i++)
	{
		carousel.add(first + i, CreateCarouselItem(data.episodes[i]));
	}

};

function CreateCarouselItem(item)
{
    return '<div class="carouselitem">'
	+ '<img src="' + item.thumb + '" >'
	+ '<a href="' + item.watchurl + '" target="_blank">' + item.showname + " : " + item.title + '</a><br>'
	+ item.synopsis
	+ '</div>';
};
