$(document).ready(function() {
    $('#gallery').cycle({
        fx:     'fade',
        speed:  2000,
        pager:  '#gallery-nav',
        next: '#gallery'
    });

    var fragment = window.location + '';
    fragment = fragment.substring(fragment.lastIndexOf('#'));

    $('#gallery').css('height', '300px');
    $('#everymonth').click();

    if (fragment != '#regulargiving')
    {
        $('.regulargiving').hide();
    }

    $('.examplesoneoff').hide();

    // Hide unwanted radio buttons
    $('.examplesregular input').css('position', 'absolute');
    $('.examplesregular input').css('left', '-9000px');
    $('.examplesoneoff input').css('position', 'absolute');
    $('.examplesoneoff input').css('left', '-9000px');

    // Add 'regular giving more info' link
    $('#rglrgiving').before('<a id="rgivingmoreinfo" href="#">How regular giving saves children\'s lives &raquo;</a>');

    $('#onceonly').click(function() {
        $('.regulargiving').slideUp('slow');
        $('#rgivingmoreinfo').html('How regular giving saves children\'s lives &raquo;');
        $('.examplesregular').hide();
        $('.examplesoneoff').show();
    });
    $('#everymonth').click(function() {
        $('.examplesoneoff').hide();
        $('.examplesregular').show();
    });

    $('#rgivingmoreinfo').click(function() {
        if ($('.regulargiving').is(':visible'))
        {
            $('.regulargiving').slideUp('slow');
            $('#rgivingmoreinfo').html('How regular giving saves children\'s lives &raquo;');
        }
        else
        {
            $('.regulargiving').slideDown('slow');
            $('#rgivingmoreinfo').html('&laquo; Children need you, not just today but every day');
        }
        return false;
    });

    $('.examplesregular input[type=radio]').click(function() {
        $('#donate-amount').val($(this).val());
        id = this.id;

        // highlight the label too
        $("label").removeClass('current').filter("[for=" + id + "]").addClass("current");

        // ... and record a google analytics 'hit'
        urchinTracker("/donate-amount/" + $(this).val());
    });

    $('.examplesoneoff input[type=radio]').click(function() {
        $('#donate-amount').val($(this).val());
        id = this.id;

        // highlight the label too
        $("label").removeClass('current').filter("[for=" + id + "]").addClass("current");

        // ... and record a google analytics 'hit'
        urchinTracker("/donate-amount/" + $(this).val());
    });

    $('#donate-amount').change(function() {
        $("label").removeClass('current');
    });
});