﻿    //
    //  ACCORDIAN
    //

$(document).ready(function() {

	// initialize scrollable
    $(".scrollable").scrollable();
	
    // gregs flags

    $(".main_flag").click(function() {
        $(".choose_flag").toggle("slow");
    });

    // resource centre page active link

    if ($('#aspnetForm').is('._members_login')) {
        $('._nav_documents_default').addClass('active');
    }

    //  search text
    $('.search_text').each(function() {

        //  remove inactive when focused
        $(this).focus(function() {
            $(this).removeClass('search_text_inactive');
            if ($(this).val() == 'Search') {
                $(this).val('');
            }
        });

        //  add inactive when blurred
        $(this).blur(function() {
            if ($(this).val() == '') {
                $(this).addClass('search_text_inactive');
                $(this).val('Search');
            }
        });

    });

    //  loop over each list item
    $('.category_list ul li.level_1').each(function() {

        // alert(this.tagName);
        //  check for sub items and adds handlers if required
        var items = $(this).children('ul');
        if (items.length != 0) {
            var active_items = items.find('li.active');
            if (active_items.length == 0) items.hide();
            $(this).find('a').bind("click", categoryHandler);
            items.find('a').unbind("click");
        }

    });

});

    var categoryHandler = function(event) {

        event.preventDefault();

        //  toggle sub item visibility
        var items = $(this).parent().children('ul');
        if (!items.is(':visible')) {
            items.slideDown();
            
        } else {
            items.slideUp();
        }

    }
    		        

