// JavaScript Document
$(document).ready(function () {

    if ($('.the-donor #thumbs').length) {

        $('#thumbs a').click(function (e) {
            e.preventDefault();
        })

        $('#thumbs img').click(function () {

            var largePath = $(this).attr('src').replace('-thumb.jpg', '-large.jpg');
            var largeAlt = $(this).attr('alt');

            if (!$(this).hasClass('highlight')) {
                $(this).parent().parent().parent().find('.highlight').attr('class', '').stop().animate({ opacity: 0.5 }, 10);
                $(this).addClass('highlight');
            }

            $('#featureImage').attr({ src: largePath, alt: largeAlt });
            $('#caption').html(largeAlt);
        });

        $('ul#thumbs li:first-child img').click();

        $('ul#thumbs li img').each(function () {

            if (!$(this).parent().parent().is('ul#thumbs li:first-child')) {
                $(this).animate({ opacity: 0.5 }, 1);
            }

            $(this).hover(function () {
                $(this).stop().animate({ opacity: 1.0 }, 100);
            }, function () {
                if (!$(this).hasClass('highlight')) {
                    $(this).stop().animate({ opacity: 0.5 }, 10);
                }
            });
        });

    };

});
