function init() {
	//set defaults

	// hide the child submenus
	$('#FolderList > li > ul').hide();
	
	// add the tree icons and set the event listeners for 
	// when the user clicks on the tree icons
	$('#FolderList > li').has('ul').each(createTreeImage);

	// get breadcrumb into array and then call showChildren for each matching item in FolderList
	var breadcrumb = [];
	$('#Breadcrumb').find('li[class!=first] a').each(function(n){
		breadcrumb[n] = $(this).attr('href');
	});
	for ( i=0; i<breadcrumb.length; i++ ) {
		var img = $('#FolderList').find('a[href="'+breadcrumb[i]+'"]').prev();
		$(img).each(showChildren);
	}
}
function createTreeImage() {
	var treeImg = document.createElement('img');
	$(treeImg).attr('src','/images/general/next.png')
			.addClass('treeicons')
			.bind('click',showChildren);			
	$(this).prepend(treeImg);
}
function showChildren() {
	// this = img element (sibling of ul)
	// get the child list whose list items are to be expanded
	var subul = $(this).parent().children('ul');
	
	// before expanding the list check if the treeicon image is already 
	// on each list item and if not then add it
	var liWithImg = $(subul).find('li > img.treeicons');
	if ( liWithImg.length == 0 ) {
		// find all list items of the child list that will be shown
		// if they have a nested list then add the treeicon
		$(subul).children('li').has('ul').each(createTreeImage);
	}
	
	// hide the child submenus
	$(subul).children('li').children('ul').hide();
	
	// change the source of the clicked on image to indicate the expanded sub-menu
    $(this).attr('src','/images/general/down.png')
           .unbind('click',showChildren)
           .bind('click',hideChildren);
           
    // expand the sub-menu
    $(subul).slideDown('slow');
}
function hideChildren() {
	// this = img element (sibling of ul)
	var subul = $(this).parent().children('ul');
        $(subul).slideUp('slow');
        $(this).attr('src','/images/general/next.png')
                .unbind('click',hideChildren)
                .bind('click',showChildren);
}
$(document).ready(init);

