
// ****************************
// jQuery code for RAFFLE.ASPX
// ****************************

var carouselRaffle_items = [
	{ imagesrc:'Raffle-001.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-002.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-003.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-004.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-005.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-006.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-007.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-008.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-009.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-010.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-011.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-012.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-013.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-014.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-015.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-016.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-017.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-018.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-019.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-020.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-021.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' },
	{ imagesrc:'Raffle-022.jpg', title:'Villa Las Palmas, Cabo San Lucas, Mexico' }
];

function carouselRaffle_preload()
{
	for (var i = 0; i < carouselRaffle_items.length; i++)
	{
		var carouselImageSrc = "photos/thumbs/" + carouselRaffle_items[i].imagesrc;
		var carouselImage = $("<img />").attr("src", carouselImageSrc);
	}
}

function carouselRaffle_getItemHTML(item)
{
	return '<a href="photos/' + item.imagesrc + '" title="' + item.title + '"><img src="photos/thumbs/' + item.imagesrc + '" alt="' + item.title + '" /></a>';
};

function carouselRaffle_itemLoad(carousel, state)
{
	for (var i = carousel.first; i <= carousel.last; i++)
	{
		if (carousel.has(i))
			continue;
		
		if (i > carouselRaffle_items.length)
			break;
		
		// Create an object from HTML
		var item = $(carouselRaffle_getItemHTML(carouselRaffle_items[i - 1])).get(0);
		
		// Apply thickbox
		tb_init(item);
		
		carousel.add(i, item);
	}
};


function carouselRaffle_itemVisibleIn(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a given index which is out of the actual item range
    var idx = carousel.index(i, carouselRaffle_items.length);
    
	// Create an object from HTML
	var item = $(carouselRaffle_getItemHTML(carouselRaffle_items[idx - 1])).get(0);
	
	// Apply thickbox
	tb_init(item);
	
	carousel.add(i, item);
};

function carouselRaffle_itemVisibleOut(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

$(document).ready(function() {
	
	// Shuffle the carousel images
	//carouselRaffle_items = $.shuffle(carouselRaffle_items);
	
	// Preload the carousel images
	carouselRaffle_preload();
	
	// Fire up the carousel
	$("#carouselRaffle").jcarousel({
		vertical: true,
		buttonPrevHTML: null,
		buttonNextHTML: null,
		scroll: 5,
		auto: 8,
		animation: "slow",
		wrap: "circular",
		itemLoadCallback: {onBeforeAnimation: carouselRaffle_itemLoad},
		itemVisibleInCallback: {onBeforeAnimation: carouselRaffle_itemVisibleIn},
		itemVisibleOutCallback: {onAfterAnimation: carouselRaffle_itemVisibleOut}
	});

});

