jQuery(document).ready(function($){

    //$(document).pngFix();
    //$('#container').pngFix();

    $('a[href^=#][href!=#]').click(function(e){
        $('html,body').animate({ 'scrollTop': $($(this).attr('href')).offset().top });
        window.location.hash = 'header'; // Yuck
        e.preventDefault();
    });

    // Contact us page
    if ($('#post-136').length) {
        $('#cf_field_3').change(function(){
            $('#cf_field_3 option:selected').each(function() {
                if ($(this).text() == 'Joining the choir') {
                    $('#cf_field_4').text('Please include the following.\nYour phone number: \nPrevious musical experience: \nVoice type (first or second soprano, alto, tenor or bass): \nCan you sight-read? \nHow you heard about us: \nAnything else: ');
                } else {
                    $('#cf_field_4').text('');
                }
            });
        });
    }

    if (document.getElementById('map')) {
        if (typeof(map_lat)=='undefined' || typeof(map_lon)=='undefined') {
            map_lat = 52.4822;
            map_lon = -1.8962;
            zoom = 17;
        } else {
            zoom = 16;
        }
        var mapOpts = {
            zoom: zoom,
            center: new google.maps.LatLng(map_lat, map_lon),
            mapTypeControl: false,
            navigationControl: true,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById('map'), mapOpts);
        var marker = new google.maps.Marker({
            map: map,
            position: new google.maps.LatLng(map_lat, map_lon)
        });

        google.maps.event.addListener(map, 'zoom_changed', function() {
            if (map.getZoom() < 13) {
                map.setZoom(13);
            };
            if (map.getZoom() > 17) {
                map.setZoom(17);
            };
        }); 
    }

    $('#giftaid').html('<form style="width:20em"><h3>Gift Aid Calculator</h3> <p>Proposed Donation: &pound; <input type="text" size="4" name="donation"> <input type="button" value="Calculate" onclick="computeForm(this.form)"> <p>Full value with Gift Aid: &pound; <input type="text" size="4" name="amount"> <p>If you pay a higher tax rate, you may reclaim further higher rate relief of: &pound; <input type="text" size="4" name="high_relief"></form>');

});

function computeForm(form) {
    var basic = 20;
    var high = 40;
    calcrate = 100 / (100 - basic);
    money = Math.round(100 * form.donation.value * calcrate) / 100;
    claimback = Math.round(100 * money * ((high - basic)/100) ) / 100;
    form.amount.value = money;
    form.high_relief.value = claimback;
}



