// This uses Prototype

// Without this javascript the user can click the name or the image in a category-block
// This javascript makes the entire block clickable
// It finds the first link in the block and makes the entire block click go to that
// It also makes the browser add the category-block-hover class to a block when the
// user hovers over that block
$$(".category-block").each(function(elmt) {

    // mousedown is used instead of click because IE doesn't detect which mouse button is used otherwise
    elmt.observe('mousedown', function(event) {
        // isLeftClick doesn't work in IE9 with this version of Prototype
        //if (Event.isLeftClick(event)) {
            window.location = $(this).down("a").readAttribute("href");
            return false;
        //}
    });


    elmt.observe('mouseover', function() {
        this.addClassName('category-block-hover');
    });
    elmt.observe('mouseout', function() {
        this.removeClassName('category-block-hover');
    });

});


/*
// Change the background color for the category list items
$$(".category-list-item").each(function(elmt) {

    elmt.observe('mouseover', function() {
        this.addClassName('category-list-item-hover');
    });
    elmt.observe('mouseout', function() {
        this.removeClassName('category-list-item-hover');
    });

});
*/



// Collapse the FAQs on page load
$$(".faq_ans").each(function(elmt) {
    elmt.addClassName('faq_collapsed');
});


// When the user clicks a FAQ heading, expand or collapse the FAQ answer
$$(".faq li h3").each(function(elmt) {    

    // mousedown is used instead of click because IE doesn't detect which mouse button is used otherwise
    elmt.observe('mousedown', function(event) {
        // isLeftClick doesn't work in IE9 with this version of Prototype
        //if (Event.isLeftClick(event)) {

            // Toggle between a plus and minus sign
            this.toggleClassName('faq_expanded');

            // Toggle between this node collapsed or expanded
            this.siblings().each(function(childElmt) {

                if (childElmt.tagName.toLowerCase() == 'ul') {
                    childElmt.toggleClassName('faq_collapsed');
                }
            });
        //}
    });

});



