
var current_photo = 0;
var mode = 'thumbnails';

$(document).ready(function() 
{
    $(".fade").hover(function() {
        $(this).fadeTo("fast", 0.3); // This sets the opacity to 60% on hover
    }, function() {
        $(this).fadeTo("fast", 1.0); // This sets the opacity back to 100% on mouseout
    });
}
);

function switchView()
{ 
	if (mode == 'thumbnails')
	{
		switchToLarge();
		mode = 'large';		
		showPhoto(current_photo);
	}
	else
	{
		switchToThumbnails();
		mode = 'thumbnails';
	}
}

function switchToThumbnails()
{
	$("#large").fadeOut('fast');
	$('#thumbnails').fadeIn('fast');
	$('#switch').attr('src', '/media/images/thumbnails.gif');
}

function switchToLarge()
{
	$("#thumbnails").hide();
	$('#large').fadeIn('fast');
	$('#switch').attr('src', '/media/images/large.gif');
}


function showPhoto(i)
{
	if (mode == 'thumbnails')
	{
		switchToLarge();
		mode = 'large';
	}

	current_photo = (i > (photos.length-1)) ? 0 : i;
	current_photo = (i < 0) ? photos.length-1 : current_photo;
	$('#large').html('<img src="'+photo_url+photos[current_photo][1]+'" onclick="showPhoto('+(current_photo+1)+')" alt="" /><br /><span class="photo_caption">'+photos[current_photo][2]+'</span>');
	updateCounter();	
}

function updateCounter()
{
	if (photos.length == 0)
	{
		$("#switch").hide();
		$("#counter").hide();
	}
	else
	{
		$("#counter_value").html((current_photo+1) + ' / ' + photos.length);
	}
}

function showNextPhoto()
{
	showPhoto(current_photo+1);
}

function showPreviousPhoto()
{
	showPhoto(current_photo-1);
}

