/*
Dynamically load jQuery if not loaded
*/
var jQueryScriptOutputted = false;
function initJQuery() {
    if (typeof(jQuery) == 'undefined') {     
        if (! jQueryScriptOutputted) {
            //only output the script once..
            jQueryScriptOutputted = true;
            
            //output the script (load it from google api)
            document.write("<scr" + "ipt type=\"text/javascript\" src=\"/js/jquery/jquery-1.3.2.min.js\"></scr" + "ipt>");
			document.write("<scr" + "ipt type=\"text/javascript\" src=\"/js/jquery/ui/js/jquery-ui-1.7.2.custom.min.js\"></scr" + "ipt>");
			
        }
        setTimeout("initJQuery()", 50);
    } else {
                        
        $(function() {  

		/* Do Function */
			$.extend($.fn, {
				treeview: function(options, callback) {
					// Defaults
					if (!options) var options = {};
			
					// initialise tree
					var tree = $(this);
					//collapse folder initially
					tree.find('ul.Treeview li.Theading').addClass('collapsed')
					//add click handler
					tree.click(function(e) { handleClick(e) });
			
					function handleClick(e) {
						//is the click on me or a child
						var node = $(e.target);
						//check the link is a directory
						if (node.is("li.Theading")) { //Is it a directory listitem that fired the click?
							//do collapse/expand
							if (node.hasClass('collapsed')) {
								node.find('>ul').toggle('blind','',500); //need the > selector else all child nodes open
								node.removeClass('collapsed').addClass('expanded');

							}
							else if (node.hasClass('expanded')) {
								node.find('>ul').toggle('blind','',500);
								node.removeClass('expanded').addClass('collapsed');

							}
							//its one of our directory nodes so stop propigation
							e.stopPropagation()
						} else if (node.attr('href') == '#' | node.hasClass('Tcontent')) {
							//its a file node with a href of # so execute the call back
							callback(e);
						}
						
					}
				}
			});	
		
			$('#Treeview').treeview(null, '');
			
		/* End Function */
		
		});
    }
            
}
initJQuery();