// The Ghetto Fantabulous SchoolRack Slideshow
// (C) 2007 SchoolRack, Written by Michael Whalen

$(document).ready(function() {
    
    // Initialize the count..
    var photoCount = 1;
    var totalPhotos = $('.totalPhotos').html();
        
    function updateCount() {
		$('.currentPhotoNumber').html(photoCount)
    };
    
    function toggleButtons() {
        if (photoCount == "1") {
            $('a.previousPhoto').addClass('disabled');
        }
        if (photoCount == totalPhotos) {
            $('a.nextPhoto').addClass('disabled');
        }
    };
    
    $('a.previousPhoto').addClass('disabled');
    
    if (photoCount == totalPhotos) {
        $('a.nextPhoto').addClass('disabled');
    };
        
    $('a.nextPhoto').bind('click', function(event) {
        if (photoCount == totalPhotos) {
            return false
        } else {
            $('a').removeClass('disabled');
            var currentPhoto = '#photo-'+photoCount
            photoCount++;
            var nextPhoto = '#photo-'+photoCount;

            $(currentPhoto).fadeOut()
            $(nextPhoto).fadeIn()

            updateCount()
            toggleButtons()
            return false
        };        
    });
    
    $('a.previousPhoto').bind('click', function(event) {
        if (photoCount == "1") {
            return false
        } else {
            $('a').removeClass('disabled');
            var currentPhoto = '#photo-'+photoCount;
            photoCount--;
            var previousPhoto = '#photo-'+photoCount;

            $(currentPhoto).fadeOut()
            $(previousPhoto).fadeIn()

            updateCount()
            toggleButtons()
            return false
        };
    });
        
});
