var chapters = dataChapter.split('\\');
var root = {}
var tree_pointer = {}; // зачем тут была строка?
for(var j=0, jlen = chapters.length; j < jlen; j++){
if(!tree_pointer.hasOwnProperty("name")) {
tree_pointer['name'] = chapters[j];
}
tree_pointer['children'] = {}; // зачем тут была строка?
}
var elements = $('span'),
setnext = function(){
var selected = elements.filter('.selected').removeClass('selected'),
index = elements.index(selected);
index = (++index == elements.length)? 0 : index ;
elements.index(index).setClass('selected')
}