<!--

function Navigation()
{
    var obj =
    {
        elementId: null,
        contents: new Array(),
        currentSection: null,
        currentChapter: null,


        addSection: function(name)
        {
            this.contents.push(
                {
                    type: 'section',
                    name: name
                }
            );
        },
        
         addSectionWo: function(name)
        {
            this.contents.push(
                {
                    type: 'sectionwo',
                    name: name
                }
            );
        },

        addChapterInactive: function(name)
        {
            this.contents.push(
                {
                    type: 'chapterInactive',
                    name: name
                }
            );
        },

        addChapter: function(name, section, chapter)
        {
            this.contents.push(
                {
                    type: 'chapter',
                    name: name,
                    section: section,
                    chapter: chapter
                }
            );
        },

        addMeta: function(name, section, chapter)
        {
            this.contents.push(
                {
                    type: 'meta',
                    name: name,
                    section: section,
                    chapter: chapter
                }
            );
        },

        setLocation: function (section, chapter)
        {
            this.currentSection = section;
            this.currentChapter = chapter;
        },

        reRender: function()
        {
            this.render(this.elementId);
        },

        render: function (elementId)
        {
            this.elementId = elementId;

            var element = $(elementId);

            if ( !element ) // if element could not be found:
            {
                return;
            }

            var currentItem = null;
            var navigationContent = '';
            element.innerHTML = '';

            for (var loopCount = 0; loopCount < this.contents.length; loopCount++)
            {
                currentItem = this.contents[loopCount];

                if ( currentItem.type == 'section' )
                {
                    navigationContent = '<div class="navigation_section';

                    if ( loopCount == 0 )
                    {
                        navigationContent += ' navigation_firstelement';
                    }

                    navigationContent += '">' + currentItem.name + '</div>';

                    element.innerHTML += navigationContent;
                    
                } else if ( currentItem.type == 'sectionwo' )
                {
                    navigationContent = '<div class="navigation_sectionwo';

                    if ( loopCount == 0 )
                    {
                        navigationContent += ' navigation_firstelement';
                    }

                    navigationContent += '">' + currentItem.name + '</div>';

                    element.innerHTML += navigationContent;
                }  else if ( currentItem.type == 'chapterInactive' )
                {
                    navigationContent = '<div class="navigation_chapter_inactive';

                    if ( loopCount == 0 )
                    {
                        navigationContent += ' navigation_firstelement';
                    }

                    navigationContent += '">' + currentItem.name + '</div>';

                    element.innerHTML += navigationContent;
                }
                else if ( currentItem.type == 'chapter' )
                {
                    if ( !currentItem.section )
                    {
                        element.innerHTML += '<div class="navigation_chapter">' + currentItem.name + '</div>';
                    }
                    else
                    {
                        navigationContent = '<a href="#" onclick="nav.activate(' + loopCount + '); return false;" id="navigation_' + loopCount + '" class="navigation';


                        if ( this.currentSection == currentItem.section && this.currentChapter == currentItem.chapter )
                        {
                            navigationContent += '_active';
                        }

                        if ( loopCount == 0 )
                        {
                            navigationContent += ' navigation_firstelement';
                        }

                        navigationContent += '" title="' + currentItem.name.replace(/(<([^>]+)>)/ig,"") + '">' + currentItem.name + '</a>';

                        element.innerHTML += navigationContent;

                        $('navigation_' + loopCount).addEvent('click', this.activate.bindWithEvent(this));
                    }
                }

                else if ( currentItem.type == 'meta' )
                {
                    navigationContent = '<a href="#" onclick="nav.activate(' + loopCount + '); return false;" id="navigation_' + loopCount + '" class="meta';

                    if ( loopCount == 0 )
                    {
                        navigationContent += ' navigation_firstelement';
                    }

                    navigationContent += '">' + currentItem.name + '</a>';

                    element.innerHTML += navigationContent;

                    $('navigation_' + loopCount).addEvent('click', this.activate.bindWithEvent(this));
                }
            }
        },

        activate: function(clickId)
        {
            contentManager.changeState(this.contents[clickId].section, this.contents[clickId].chapter);
            this.setLocation(this.contents[clickId].section, this.contents[clickId].chapter);
            this.reRender();
        }
    };

    return obj;
}




//-->