var LeftPannel = {
    CurTaskLink: null,
    aLinks: new Array(),
    aTasks: new Array(),
    opt: 0,
    opt2: 0,
    oContainer: null,
    oButtonsDiv: null,
    id: 0,
    
    Init: function(oContainer, aTasks, opt, id)
    {
    	this.id = id;
        this.CurTaskLink = null;
        this.aLinks = new Array();
        this.oButtonsDiv = null;
        this.opt = opt;
        this.opt2 = 1;
        this.aTasks = aTasks;
        this.oContainer = oContainer;
        Rup.get.id('workdv').innerHTML = '';
    },
    
    Show: function()
    {
        if( this.aLinks.lendth == undefined )
        {
            this.aLinks.lendth = 0;
        }
        var oLinkDiv = document.createElement('div');
        oLinkDiv.className = "EduTaskLinks";
        for( var i = 0; i < this.aTasks.length; i++ )
        {
            var oCurLink = CreateLink(this.aTasks[i], this);
            oLinkDiv.appendChild(oCurLink);
            this.aLinks[ this.aLinks.lendth ] = oCurLink;
            this.aLinks.lendth++;
        }
        this.oContainer.appendChild(oLinkDiv);
        
        this.oButtonsDiv = document.createElement('div');
        this.oButtonsDiv.className = "EduTaskButtons";
        this.oContainer.appendChild(this.oButtonsDiv);
        
        var instance = this;
        
        var aButtons = [
            {text: 'Инструкция по выполнению теста', handler: function(){}},
            {text: 'Начать тестирование', handler: function(){ LeftPannel.StartTest(); }}
        ];
        
        if( 2 <= this.opt && this.id )
        {
        	aButtons.unshift({
        	   text: 'Учебные материалы по тесту', 
        	   handler: function(){ Rup.app.task.goWindow({taskId: instance.id}); }
        	});
        }
        
        CreateButtons(aButtons);
    },
    
    StartTest: function()
    {
    	if( this.opt2 )
        {
            this.ShowButtons();
        }
        
        if( this.aLinks.length )
        {
            this.aLinks[0].ShowTask();
            
            for( var i = 0; i < this.aLinks.length; i++ )
            {
                this.aLinks[i].AddHandler();
            }
        }
    },
    
    SetError2: function()
    {
        if( this.CurTaskLink != null )
        {
            this.CurTaskLink.SetError();
        }
    },
    
    SetError3: function()
    {
        for( var i = 0; i < this.aLinks.length; i++ )
        {
            if( !this.aLinks[i].answered )
            {
                this.aLinks[i].SetError();
            }
        }
        
        this.HideButtons();
        
    },
    
    NextTask: function()
    {
        var oCurLink = this.CurTaskLink;
        if( oCurLink == null )
        {
            oCurLink = this.aLinks[0];
        }
        var oNextLink = oCurLink.nextLink;
        while( oNextLink != oCurLink && oNextLink != null )
        {
            if( oNextLink.answered )
            {
                oNextLink = oNextLink.nextLink;
            }
            else
            {
                oNextLink.ShowTask();
                return;
            }
        }
    },
    
    PrevTask: function()
    {
        var oCurLink = this.CurTaskLink;
        if( oCurLink == null )
        {
            oCurLink = this.aLinks[ this.aLinks.length - 1 ];
        }
        var oPrevLink = oCurLink.prevLink;
        while( oPrevLink != oCurLink && oPrevLink != null )
        {
            if( oPrevLink.answered )
            {
                oPrevLink = oPrevLink.prevLink;
            }
            else
            {
                oPrevLink.ShowTask();
                return;
            }
        }
    },
    
    ShowButtons: function()
    {
        var oPrevButton = GetButton(" << ", function(){
            LeftPannel.PrevTask();
        });
        
        var oNextButton = GetButton(" >> ", function(){
            LeftPannel.NextTask();
        });
        
        this.oButtonsDiv.appendChild(oPrevButton);
        this.oButtonsDiv.appendChild(oNextButton);
    },
    
    HideButtons: function()
    {
        this.oButtonsDiv.innerHTML = "";
    },
    
    IsUnansweredLinksExists: function()
    {
        for( var i = 0; i < this.aLinks.length; i++ )
        {
            if( !this.aLinks[i].answered )
            {
                return true;
            }
        }
        this.HideButtons();
        return false;
    }
};