/******************************************************************************************************************/
// Carousel
/******************************************************************************************************************/
var curr = 0;
var num = 0;

function showItem(){
	$('#carousel .viewport li').hide();
	$('#carousel .nav li').removeClass('sel');
	
	$('#carousel .viewport li:eq('+ curr +')').fadeIn(800);
	$('#carousel .nav li:eq('+ curr +')').addClass('sel');
}

function loopItems(){
	showItem()
	
	curr++;
	if (curr >= num) curr = 0;
	
	mytimer = window.setTimeout('loopItems()', 4000);
}

function handleCarousel(){
	num = $('#carousel .viewport li').size();
	
	if (num > 0) loopItems();
	
	$('#carousel .nav li').click(function(){
		if (!$(this).hasClass('sel')) {
			curr = $('#carousel .nav li').index(this);
			clearTimeout(mytimer);
			showItem();
		}
	});
}

/******************************************************************************************************************/
// Gallery
/******************************************************************************************************************/

function handleGallery(){
	/*$('.gallery .small .photo a').click(function(){ return false; });
	
	$('.gallery .small li:eq(0)').addClass('sel');
	myimg  = $('.gallery .small li:eq(0) img').attr('src');
	myhref  = $('.gallery .small li:eq(0) a').attr('href');
	
	$('.gallery .big img').attr('src', myimg);
	$('.gallery .big a').attr('href', myhref);
	
	$('.gallery .small li').hover(function(){
		$('.gallery .small li').removeClass('sel');
		$(this).addClass('sel');
		
		myimg  = $(this).find('img').attr('src');
		myhref  = $(this).find('a').attr('href');
		
		$('.gallery .big img').attr('src', myimg);
		$('.gallery .big a').attr('href', myhref);
	}, function(){
		// nothing to do
	});*/
	
}

/******************************************************************************************************************/
// On document load...
/******************************************************************************************************************/

$(function(){
	// fancybox
	$('.fancybox').fancybox();
	
	// carousel
	handleCarousel();
	
	// gallery
	handleGallery();
});
