
jQuery.fn.initBogoFolders=function(opts,rootFolder){var self=this;opts=jQuery.extend({separator:'',debuggering:false,parentDirLabel:'..',activeItemClass:null},opts?opts:{});var dbgdiv=null;var startingDir=rootFolder;var target=$(opts.target);function dbg(msg){if(dbgdiv)dbgdiv.prepend("BogoFolders: "+msg+"<br/>");};if(opts.debuggering){target.after("<div id='BogoFoldersDebugDiv'>BogoFolders debugging area<br/></div>").after('<hr/>');dbgdiv=jQuery('#BogoFoldersDebugDiv');dbgdiv.css('border','1px dashed #000');dbg("debugging activated.");}
function tagFolders(theFolder,parentFolder){dbg("Tagging folder named \""+theFolder.name+"\"");theFolder.parentFolder=parentFolder;if(theFolder.selected){startingDir=theFolder;}
if(!theFolder.children){return;}
for(ndx in theFolder.children){tagFolders(theFolder.children[ndx],theFolder);}};tagFolders(rootFolder,null);opts.previousFolder=null;function showContent(theFolder){target.empty();if(opts.activeItemClass){if(opts.previousFolder&&opts.previousFolder.anchor)
{opts.previousFolder.anchor.removeClass(opts.activeItemClass);}
opts.previousFolder=theFolder;if(theFolder.anchor)
{theFolder.anchor.addClass(opts.activeItemClass);}}
var ctype=theFolder.contentType?theFolder.contentType:'html';var content=theFolder.content?theFolder.content:'';dbg('typeof content == '+typeof(content));if('function'==typeof(content)){dbg("Calling .content function.");content=content();}
if('object'==typeof(content)){ctype='object';}
switch(ctype){case'object':target.append(content);break;case'html':target.html(content);break;case'text':case'txt':target.text(content);break;default:target.html("Error: theFolder.contentType could not be determined");break;};};var addFolderEntry=function(theFolder){var label=theFolder.name?theFolder.name.replace(/\'/,'&apos;'):null;if(theFolder.chdirProxy){var tmp=theFolder.chdirProxy;delete theFolder.chdirProxy;theFolder=tmp;}
var icon=(theFolder.icon||(theFolder.icon===null))?theFolder.icon:opts.icon;var anchor=jQuery("<a href='#'/>");anchor[0].folderObj=theFolder;theFolder.anchor=anchor;if(icon){anchor.append("<img src='"+icon+"' alt='"+(label?label:'')+"'/>");}
if(label){anchor.append(label);}
anchor.click(function(){if(0&&('function'==typeof(opts.onclick))){opts.onclick(this.folderObj,opts.previousFolder);}
showContent(this.folderObj);if(this.folderObj.children)chdir(this.folderObj);if(0&&('function'==typeof(opts.afterclick))){opts.afterclick(this.folderObj,opts.previousFolder);}
return false;});self.append(anchor);return self;};var chdir=function(theFolder){dbg('chdir(<code>'+(theFolder.name?theFolder.name:theFolder.toSource())+"</code>)");self.empty();if(theFolder.parentFolder){var cdup={name:opts.parentDirLabel,chdirProxy:theFolder.parentFolder};addFolderEntry(cdup);}
if(!theFolder.children){return;}
var count=theFolder.children.length;if(count&&theFolder.parentFolder){self.append(opts.separator);}
for(var i=0;i<count;++i){addFolderEntry(theFolder.children[i]);if((i!=(count-1))&&opts.separator){self.append(opts.separator);}}};chdir(rootFolder);showContent(rootFolder);return self;};