jQuery.noConflict();
// Put all your code in your document ready area
jQuery(document).ready(function ($) {

    /*  =======================
    NAS SCRIPTS
    inc : global;
    inc : display preferences;
    inc : remove text from form fields;
    inc : news and campaigns tabs;
    inc : nas community;
    inc : sitemap
    inc : calendar accordion;
    inc : calendar tooltip.
    ======================= */

    $(function () {
        $("#pageWrap").addClass('jq-enabled')
    });

    /* GLOBAL */
    var showText = 'Show';
    var hideText = 'Hide';
    var $help = ('<span class="rm">' + 'show ' + '</span>');

    // ------------------------------------------------------

    $('.javaTextInputArea').focus(function () {
        $(this).addClass("focusField");
        if (this.value == this.defaultValue) {
            this.value = '';
        }
        if (this.value != this.defaultValue) {
            this.select();
        }
    });
    $('.javaTextInputArea').blur(function () {
        if (this.value == '') {
            $(this).removeClass("focusField");
            this.value = this.defaultValue;
        }
        if (this.value != this.defaultValue) {

        }
    });

    // ------------------------------------------------------

    /* DISPLAY PREFERENCES */
    $(function () {
        $("#siteCustomisation .siteSelection").hide();
        $("#siteCustomisation").insertBefore("#pageWrapOne");
        $("#mastHead .button:lt(2) a").each(function (index) {

            $(this).click(function () {
                var id = $(this).attr('href');
                var $thisDiv = $(id);
                if ($('div:animated').length) { return false; }

                if ($thisDiv.siblings(':visible').not('h3').length) {
                    $thisDiv.siblings(':visible').slideUp(700, function () {
                        $thisDiv.slideDown();
                    });
                } else {
                    $thisDiv.slideToggle();
                }

                return false;
            });
        });
        $("#cpSetNation .button:lt(2) a").each(function (index) {

            $(this).click(function () {
                var id = $(this).attr('href');
                var $thisDiv = $(id);
                if ($('div:animated').length) { return false; }

                if ($thisDiv.siblings(':visible').not('h3').length) {
                    $thisDiv.siblings(':visible').slideUp(700, function () {
                        $thisDiv.slideDown();
                    });
                } else {
                    $thisDiv.slideToggle();
                }
                $('html, body').animate({ scrollTop: 0 }, 'slow');
                return false;
            });
        });
        $("#siteCustomisation .siteSelection .buttonClose").click(function () {
            $("#siteCustomisation .siteSelection").slideUp();
            return false;
        });
    });

    /* REMOVE TEXT FROM FORM FIELDS */
    $(function () {
        $('.formInput').focus(function () {
            value = $(this).val();
            $(this).attr("value", "");
        });
        $('.formInput').blur(function () {
            if ($(this).val() == "") {
                $(this).val(value);
            }
        });
    });

    /* NEWS AND CAMPAIGNS TABS */
    function wrapLink() {
        $('.tabs h2 a').live("click", function () {
            // hide all tabs 
            $(".tabBody").hide();

            // remove the class of 'selected' from all tab headings
            $(".tabs .tabSelector").removeClass('selected');

            // add the 'selected' class to the parent of the clicked link as this is now the selected tab
            $(this).parent().addClass('selected');

            // show the relevant tab depending on which link was clicked
            $(this).parent().next('.tabBody').show();

            return false;
        });
    }

    $(function () {
        // hide all tabs apart from the first one
        $(".tabs .tabBody:gt(0)").hide();

        // add a class of selected to the first tab heading
        $(".tabs .tabSelector:eq(0)").addClass('selected');

        // add links to all other tab headings
        $(".tabs .tabSelector").wrapInner('<a href="#"><span></span></a>');

        // call the function wrapLink
        wrapLink();
    })

    /* NAS COMMUNITY */
    $(function () {
        $(" div.slides:gt(0)").hide();
        $("#nasCommunity h3").wrapInner('<a href="#"></a>');
        $("#nasCommunity h3:eq(0)").addClass('logoHighlight');

        $('#nasCommunity h3 a').bind('mouseover focus', function () {
            $(".slides").hide();
            $('#nasCommunity h3').removeClass('logoHighlight');
            $(this).parent().addClass('logoHighlight');
            $(this).parent().next('.slides').show();
        });
    })

    /* SITEMAP SHOW/HIDE */
    $(function () {
        var showText = 'Show quick links';
        var hideText = 'Hide quick links';
        $("#footerWrapOne h2").remove();
        $("#sitemapToggle").prepend('<a class="toggleTrigger" href="#">' + hideText + '</a>');
        $("div#sitemapToggle a.toggleTrigger").click(function () {
            $('a.toggleTrigger').toggleClass('show');
            $("#footerWrapOne").stop(false, true).slideToggle(700);
            $(this).text($(this).text() == hideText ? showText : hideText);
            return false;
        });
    });


    /* ACCORDION FOR CALENDAR PAGES */
    $(function () {
        $('.accordion .blockBody').hide();
        $(".accordion .accordionHeader").wrapInner('<a href="#"></a>');

        $('.accordion .accordionHeader a').click(function () {
            $(this).toggleClass('show');
            $(this).parent().next().slideToggle('slow');
            return false;
        });
    });


    /* CALENDAR TOOLTIP */
    $(function () {
        $(".calendarBlock table a").bind('mouseover focus', function () {
            $(this).next("div").animate({ opacity: "show" }, "fast").css({ left: this.width - 22 });
        });
        $(".calendarBlock table a").bind('mouseleave blur', function () {
            $(this).next("div").animate({ opacity: "hide" }, "fast");
        });
    });

    $(function () {
        $('.scroll-pane').jScrollPane();
    });

});

