
var page = {
    setup: function() {
        text.init();
        faq.init();
        //news.init();
    }
}

var text = {
    typing: false,
    init: function() {
   
        // set up click event handlers    
        $("#decText").click(text.decreaseFontSize);
        $("#incText").click(text.increaseFontSize);

        // set search textbox functionality
        $(".jsSearch").val("enter search term...").focusin(function() {
            $(".jsSearch").val("");
        }).keyup(function() {
            text.typing = true;
        }).focusout(function() {
            if (!text.typing) {
                $(".jsSearch").val("enter search term...");
            }
        });
    },

    // increase font size
    increaseFontSize: function() {
        // font sizes
        var currFontSize = parseFloat($("body").css("font-size"), 10);
        var newFontSize = currFontSize * 1.2;

        // update font size
        $("body").css("font-size", newFontSize);
        return false
    },

    // decrease font size
    decreaseFontSize: function() {
        // font sizes
        var currFontSize = parseFloat($("body").css("font-size"), 10);
        var newFontSize = currFontSize * 0.8;

        // update font size
        $("body").css("font-size", newFontSize);
        return false
    }
}

var faq = {

    // initialise faqs
    init: function() {

        // all faqs have a clickable image with this class, collapse to start with | set its click event to togglePanel() function.
        faq.collapseFaqs();
        $(".openFaq").click(faq.togglePanel);

    },

    // collapses all faq panels
    collapseFaqs: function() { $(".collapsible").hide(); },

    // this function toggles the faq panels visiblity
    togglePanel: function() {
        // this line gets the clickable images closest <dt> (its parent), and finds that dts sibling (the dd)
        var $objToExpand = $(this).closest("dt").next();
        var COLLAPSED_SRC = '/images/arrow-transition-270.png';
        var EXPANDED_SRC = '/images/arrow-transition-090.png';

        // switch arrow image and toggle visibility with a slide animation
        $(this).attr("toggle") == 'open' ? $(this).attr({ toggle: "closed",
            src: COLLAPSED_SRC
        })
                                         : $(this).attr({ toggle: "open",
                                             src: EXPANDED_SRC
                                         });

        $objToExpand.slideToggle(function() {
            $("dt").css("margin", "0").css("margin", "5px 0");
        });

    }
}

//var news = {

//    // initialise news tabs
//    init: function() {

//        $("#news-tab1, #news-tab2").click(news.switchTab);
//        $("#middle-tab-2").hide();
//    },

//    switchTab: function() {

//        var $tab = $(this);

//        if ($tab[0].id == "news-tab1") {
//            $("#news-tabs").removeClass("newsTopDev").addClass("newsTop");
//            
//            $("#middle-tab-2").hide();
//            $("#middle-tab-1").show();
//        } else {
//            $("#news-tabs").removeClass("newsTop").addClass("newsTopDev");
//            
//            $("#middle-tab-1").hide();
//            $("#middle-tab-2").show();
//        }
//        
//        

//    }
//}

// initialise text functions
$(document).ready(page.setup);
