$(document).ready(function() {
    // loads rollover script
    //SwapImage.rollover.init();

    // sub navs
    $('#nav li div').hide().addClass('withJS');

    $('#nav li').hover(function() {
        $(this).children('div').stop(true, true);
        $(this).children('div').fadeIn(170);
    }, function() {
        $(this).children('div').stop(true, true);
        $(this).children('div').fadeOut(170);

    });

    if ($('.imgRight').length > 0) {
        $("a.fancy").fancybox({
            'zoomSpeedIn': 200,
            'zoomSpeedOut': 200,
            'overlayShow': true,
            'overlayOpacity': 0
        });
    }

    // datepicker
    if ($('.datepicker').length) {
        $(".datepicker").datepicker();

    }


    // generic form functions

    if ($('.genericForm').length) {

        $('.genericFormDesc').hide();

        $('.genericFormDescButton').toggle(function() {
            $(this).parent().next().next().next().slideDown('fast');
            return false;
        }, function() {
            $(this).parent().next().next().next().slideUp('fast');
            return false;
        });

        // hide others
        $('#streetAddress').show();
        $('#street2Address').show();
        $('#cityAddress').hide();
        $('#companyAddress').show();
        //set to Bermuda
        $('#countryAddress').hide();
        $('#stateAddress').hide();
        $('#parishAddress').show();
        $('#parishAddressBDA').show();
        $('#parishAddressOther').hide();
        $('#codeAddressOther').show();
        $('#codeAddressUS').hide();
        $('#zipAddress').show();

    }


    //billing address country selector
    $('#BermudaAddress').change(function() {
        // hide others
        $('#streetAddress').show();
        $('#street2Address').show();
        $('#cityAddress').hide();
        $('#companyAddress').show();
        //set to Bermuda
        $('#countryAddress').hide();
        $('#bcountry').val("BM");

        $('#stateAddress').hide();
        $('#parishAddress').show();
        $('#parishAddressBDA').show();
        $('#parishAddressOther').hide();
        $('#codeAddressOther').show();
        $('#codeAddressUS').hide();
        $('#zipAddress').show();
    });

    //billing address country selector
    $('#UnitedStatesAddress').change(function() {
        // hide others
        $('#streetAddress').show();
        $('#street2Address').show();
        $('#cityAddress').show();
        $('#companyAddress').show();
        //set to Bermuda
        $('#countryAddress').hide();
        $('#bcountry').val("US");

        $('#stateAddress').show();
        $('#parishAddress').hide();
        $('#parishAddressBDA').hide();
        $('#parishAddressOther').show();
        $('#codeAddressOther').hide();
        $('#codeAddressUS').show();
        $('#zipAddress').show();
    });

    //billing address country selector
    $('#OtherAddress').change(function() {
        // hide others
        $('#streetAddress').show();
        $('#street2Address').show();
        $('#cityAddress').show();
        $('#companyAddress').show();
        //set to Bermuda
        $('#bcountry').val("GB");
        $('#countryAddress').show();

        $('#stateAddress').hide();
        $('#parishAddress').show();
        $('#parishAddressBDA').hide();
        $('#parishAddressOther').show();
        $('#codeAddressOther').show();
        $('#codeAddressUS').hide();
        $('#zipAddress').show();
    });

    if ($('#extraInformation').length > 0) {
        $('#extraInformation').hide();
    }
    $('select#donationOptions').change(function() {
        var selected = $('#donationOptions option:selected');
        if ($('#donationOptions option:selected').attr('data-extra-label')) {
            var text = $('#donationOptions option:selected').attr('data-extra-label');
            $('#extraInformation label').text(text);
            $('#extraInformation').slideDown();

        }
        else {
            $('#extraInformation').slideUp();
        }

    });

});



