function lookstep(indexStep){

    for(count = 0; count < ids.length; count++){
     	if(ids[count] == indexStep){
            currentarrayindex = count;
            parent.desk.document.desk.SetVariable("Position", positions[count]);
        }
    }


    if(indexStep != 0)
    {
	    if(oldindex != null)
	    {
	        var oldelement = document.getElementById("id"+oldindex);
	        oldelement.style.color = oldcolor;
	        oldelement.style.background = oldbackground;
	    }

	    var newelement = document.getElementById("id"+indexStep);

	    oldindex = indexStep;
	    oldcolor = newelement.style.color;
	    oldbackground = newelement.style.background;

	    newelement.style.color = "white";
	    newelement.style.background = "red";
	    newelement.scrollIntoView();
    }
}


function looknextstep(){

	var CurrentIerarhy = ierarhy[currentarrayindex];
    var isTrue = 0;

	if(currentarrayindex  < (ids.length - 1))
    {
	    for(count = (currentarrayindex + 1); count < ids.length; count++)
    	{
              if(ierarhy[count] == CurrentIerarhy)
              {
               		lookstep(ids[count]);
                    count = ids.length;
                    isTrue = 1;
              }
	    }
    }

    if(isTrue == 0)
    {
       isplay = 0;
    }
}


function lookpreviousstep(){

    var CurrentIerarhy = ierarhy[currentarrayindex];

    if(currentarrayindex > 0)
    {
	    for(count = (currentarrayindex - 1); count >= 0; count--)
    	{
              if(ierarhy[count] == CurrentIerarhy)
              {
               		lookstep(ids[count]);
                    count = -1;
              }
	    }
	}
}


function looklaststep(){

    var BaseIer = ierarhy[0];
    var LastBaseIndex = 0;

    for(count = 0; count < ids.length; count++)
    {
     	if(ierarhy[count] == BaseIer)
        {
        	LastBaseIndex = ids[count];
            currentarrayindex = count;
        }
    }

	lookstep(LastBaseIndex);
}

function nextblock(){

 	var CurrentIerarhy = ierarhy[currentarrayindex];

	if(currentarrayindex  < (ids.length - 1))
    {
		if(ierarhy[currentarrayindex + 1] != CurrentIerarhy)
        {
	        for(count = (currentarrayindex + 1); count < ids.length; count++)
	        {
	              if(ierarhy[count] == CurrentIerarhy)
	              {
	                    lookstep(ids[count]);
	                    count = ids.length;
	              }

                  if(ierarhy[count] == CurrentIerarhy && count == ids.length - 1)
                  {
	                    lookstep(ids[count]);
	                    count = ids.length;
                  }
	        }
        }
        else
        {
	        for(count = (currentarrayindex + 1); count < ids.length; count++)
	        {
	              if(ierarhy[count] != CurrentIerarhy)
	              {
	                    lookstep(ids[count-1]);
	                    count = ids.length;
	              }

                  if(count == ids.length - 1 && ierarhy[count] == CurrentIerarhy)
                  {
	                    lookstep(ids[count]);
	                    count = ids.length;
                  }
	        }
        }
    }
}


function previousblock(){

 	var CurrentIerarhy = ierarhy[currentarrayindex];

	if(currentarrayindex > 0)
    {
		if(ierarhy[currentarrayindex - 1] != CurrentIerarhy)
        {
	        for(count = (currentarrayindex - 1); count >= 0; count-=1)
	        {
	              if(ierarhy[count] == CurrentIerarhy)
	              {
	                    lookstep(ids[count]);
	                    count = -1;
	              }
                  else if(ierarhy[count] == CurrentIerarhy && count == 0)
                  {
	                    lookstep(ids[count]);
	                    count = -1;
                  }
	        }
        }
        else
        {
	        for(count = (currentarrayindex - 1); count >= 0; count-=1)
	        {
	              if(ierarhy[count] != CurrentIerarhy)
	              {
	                    lookstep(ids[count+1]);
	                    count = -1;
	              }
                  else if(count == 0 && ierarhy[count] == CurrentIerarhy)
                  {
	                    lookstep(ids[count]);
	                    count = -1;
                  }
	        }
        }
    }
}

function playSteps()
{
	if(isplay == 0)
    {
		isplay = 1;
       	parent.desk.document.getElementById("playbutton").src = "b_stop.gif";
        playStepNext();
    }
    else
    {
     	isplay = 0;
        timer0 = null;
       	parent.desk.document.getElementById("playbutton").src = "b_play.gif";
    }
}

function playStepNext()
{
	if(isplay == 1)
    {
		looknextstep();
		timer0=setTimeout("playStepNext()",sec*750)
    }
    else
    {
     	isplay = 0;
        timer0 = null;
       	parent.desk.document.getElementById("playbutton").src = "b_play.gif";
    }
}