function tocObject()
{
    this.pages = [];
    this.current = 0;
	this.defaults = {disableLink: false, opened: false, hidden: false, name: false, textTransform: 'none'};

    this.addPage = function(id, name, bg)
    {
        (typeof bg == 'undefined')? bg='':bg = 'url('+bg+')';
        this.pages.push({id:id, name:name, bg:bg});
    }
    this.make = function()
    {
        var html = '';
        var tree = core.tree;

        html += '<div class="toc_head_wrap"><ul class="toc_head">';
        for (var i = 0; i < this.pages.length; i++)
        {
            html += '<li'+((i == this.current)?' class="toc_current"':'')+'><a href="javascript://" onclick="toc.setPage('+i+');">'+this.pages[i].name+'</a></li>';
        }
        html += '</ul></div>';

        html += '<div class="toc_body">';
        for (var id in tree)
        {
            if (typeof tree[id].toc != 'undefined' && typeof tree[id].toc.page != 'undefined' && tree[id].toc.page == this.pages[this.current].id)
                html += this.recurent(tree[id], 0);
        }
        html += '</div>';
        $('frameWrap').innerHTML = html;
    };
    this.recurent = function(node, level)
    {
        /* подготовка */
        if (typeof node.toc == 'undefined')
            node.toc = {};
        if (typeof node.toc.disableLink == 'undefined')
            node.toc.disableLink = this.defaults.disableLink;
        if (typeof node.toc.opened == 'undefined')
            node.toc.opened = this.defaults.opened;
        if (typeof node.toc.hidden == 'undefined')
            node.toc.hidden = this.defaults.hidden;
        if (typeof node.toc.name == 'undefined')
            node.toc.name = this.defaults.name;
        if (typeof node.toc.textTransform == 'undefined')
            node.toc.textTransform = this.defaults.textTransform;

	var name = (node.toc.name)?node.toc.name:node.name;
	if (name)
	{
		switch ((node.toc.textTransform+'').toLowerCase())
		{
			case 'upper':
				name = name.toUpperCase();
				break;
			case 'lower':
				name = name.toLowerCase();
				break;
			case 'capitalize':
				name = this.capitalize(name);
				break;
			case 'capitalize2':
				name = this.capitalize2(name);
				break;
			case 'none':
			default:
				break;
		}
	}
	if (node.toc.hidden) return '';

        /* ссылочка */
        var link = '';
        if (node.toc.disableLink)
            link += '<span>'+name+'</span><br />';
        else
            link += '<a href="javascript://" onclick="core.view(\''+node.id+'\');">'+name+'</a><br />';
        /* подразделы */
        var sub = '';
        var subBox = '';
        for (var i in node.sub)
            sub += this.recurent(node.sub[i], level+1);
        /* батарейка */
        var battery =  '<img src="img/toc/progress'+core.status(node.id)+'.gif" class="battery" />';

        /* собираем строчку с линком */
        var html = '<div>';
        html += this.htmlToggler(node.id, sub != '', !node.toc.opened)
        if (sub != '')
            if (node.toc.opened)
                subBox = '<div class="toc_block" id="box_'+node.id+'">'+sub+'</div>';
            else
                subBox = '<div class="toc_block" id="box_'+node.id+'" style="display:none;">'+sub+'</div>';
        html += battery+link;
        html += '</div>'
        html += subBox;

        return html;
    }
    this.setPage = function(id)
    {
        this.current = id;
        this.make();
    }
    this.toggle = function(id)
    {
        var node = core.list[id];
        if (node)
        {
            var box = $('box_'+id);
            var link = $('link_'+id);
            if (node.toc.opened)
                box.style.display = 'none';
            else
                box.style.display = 'block';
            link.innerHTML = this.htmlTogglerImage(node.toc.opened);
            node.toc.opened = !node.toc.opened;
        }
    }
    this.htmlToggler = function(id, show, opened)
    {
        if (!show)
            return '<img class="toc_toggler" height="9" width="9" src="img/spacer.gif" />';
        return '<a id="link_'+id+'" href="javascript: toc.toggle(\''+id+'\');">'+this.htmlTogglerImage(opened)+'</a>';
    }
    this.htmlTogglerImage = function(opened)
    {
        if (opened)
			return '<img class="toc_toggler" src="img/toc/plus.gif" />';
        return '<img class="toc_toggler" src="img/toc/minus.gif" />';
    }
    this.FIRST_START = function FIRST_START()
    {

    }
	this.capitalize = function capitalize(text)
	{
		text = text.split(' ');
		for (var i = 0; i < text.length; i++)
			text[i] = text[i].charAt(0).toUpperCase() + text[i].substr(1).toLowerCase();
		return text.join(' ');
	}
	this.capitalize2 = function capitalize2(text)
	{
		text = text.toLowerCase();
		text = text.split(' ');
		if (typeof text[0] != 'undefined')
			text[0] = this.capitalize(text[0]);
		return text.join(' ');
	}
}
