// Cufon replacements
Cufon.replace('#eventi-content h3');
Cufon.replace('#eventi-content h5');
Cufon.replace('.blog-entry h2');
Cufon.replace('#novita-box h3');

$.fn.imageSwitcher = function(birra) {
	return this.each(function() {
		var image = new Image();
		image.onload = function() {
			$('#header-foto').fadeIn('slow');
			$('#beer-description').text(birre[currentIndex]['desc']).fadeIn('slow');
		};
		image.src = birra['src'];
		$('a', this).attr('href', birra['url']).html(image);
	});
}

var currentIndex = 0;

$(function() {
	// Mostra la prima foto nell'header
	$('#header-foto').imageSwitcher(birre[currentIndex]);
	
	// Gestisce il click sulle frecce dell'image switcher
	$('#beer-switcher-up a').click(function() {
		$('#header-foto').hide();
		$('#beer-description').hide();
		if (currentIndex < birre.length - 1) {
			currentIndex++;
		} else {
			currentIndex = 0;
		}
		$('#header-foto').imageSwitcher(birre[currentIndex]);
		return false;
	});
	$('#beer-switcher-down a').click(function() {
		$('#header-foto').hide();
		$('#beer-description').hide();
		if (currentIndex == 0) {
			currentIndex = birre.length - 1;
		} else {
			currentIndex--;
		}
		$('#header-foto').imageSwitcher(birre[currentIndex]);
		return false;
	});
});

