function CreateLink(oTask, oPannel)
{
    var oLink = document.createElement('a');
    
    oLink.pannel = oPannel;
    
    if( oPannel.aLinks.length )
    {
        oLink.prevLink = oPannel.aLinks[ oPannel.aLinks.length - 1 ];
        oPannel.aLinks[ oPannel.aLinks.length - 1 ].nextLink = oLink;
        oLink.nextLink = oPannel.aLinks[ 0 ];
        oPannel.aLinks[ 0 ].prevLink = oLink;
    }
    else
    {
        oLink.prevLink = oLink;
        oLink.nextLink = oLink;
    }
    
    oLink.answered = false;
    
    oLink.innerHTML = oTask.title;
    oLink.href = "#";
    
    oLink.task = {
        id: oTask.id,
        type: oTask.type
    };
    
    oLink.ShowTask = function()
    {
        if( this.pannel.CurTaskLink != null )
        {
            if( !this.pannel.CurTaskLink.answered )
            {
                this.pannel.CurTaskLink.SetUnanswered();
                this.pannel.CurTaskLink.AddHandler();
            }
        }
        this.pannel.CurTaskLink = this;
        this.SetCurrent();
        
        TaskId = this.task.id;
        
        var iType = parseInt(this.task.type);
        switch( iType )
        {
        case 1:
            MakeDataRequest(Handler1, 1, this);
            break;
        case 2:
            MakeDataRequest(Handler2, 2, this);
            break;
        case 3:
            MakeDataRequest(Handler3, 3, this);
            break;
        case 4:
            MakeDataRequest(Handler4, 4, this);
            break;
        }
        return false;
    }
    
    oLink.Void = function()
    {
        return false;
    }
    
    oLink.SetUnanswered = function()
    {
        this.className = LinkClassNames.unanswered;
        this.answered = false;
    }
    
    oLink.AddHandler = function()
    {
    	if( this.pannel.opt2 )
        {
            this.onclick = this.ShowTask;
        }
        else
        {
            this.onclick = this.Void;
        }
    }
    
    oLink.RemoveHandler = function()
    {
        this.onclick = this.Void;
    }
    
    oLink.SetCurrent = function()
    {
        this.className = LinkClassNames.current;
        this.RemoveHandler();
        this.answered = false;
    }
    
    oLink.SetError = function()
    {
        this.className = LinkClassNames.error;
        this.RemoveHandler();
        this.answered = true;
    }
    
    oLink.SetAnswered = function()
    {
        this.className = LinkClassNames.answered;
        this.RemoveHandler();
        this.answered = true;
    }
    
    oLink.SetCorrect = function( level )
    {
        this.SetAnswered();
        if( 2 <= this.pannel.opt )
        {
            var oSpan = Rup.create('span');
            oSpan.innerHTML = level;
            this.appendChild(oSpan);
            oSpan.className = StylesOfMastery.getStyleName(level);
        }
    }
    
    oLink.SetUnanswered();
    return oLink;
}

var LinkClassNames = {
    unanswered: "unanswered",
    answered: "answered",
    current: "current",
    correct: "correct",
    incorrect: "incorrect",
    error: "error"
};