//modified by Bargavi to be compatible with Flash MX 

var btnptr = null;

var bHeight = blank._height;
var additionalVSpace = 1;
var clickedButton = 0;

var totalSteps = _root.AnswerArray[_root.AnswerArray.length - 1][0].stepnum;

//_root.ShowMe._visible = false;


populateTopic();
menuInitialize();

//making the first step as default
_root.stepnum = 0;
_root.showInstruction(_root.stepnum);
_root.loadImage(_root.stepnum,null); // no previous image
clickedButton = _root.stepnum;


// initialize device select buttons
//initializeDeviceButtons();
function initializeDeviceButtons()
{
    /* Don't run this function since we don't have any more devices to initialize...
    Dont't waste CPU cycles
    device0.deviceName = routerInfoArray[0].hostName;
    device0.deviceNum = 0;
    device0.gotoAndStop(2);

    for (var i=1; i<routerInfoArray.length; i++)
    {
        device0.duplicateMovieClip("device" + i, 6000 + i);
        eval("device" + i).deviceName = routerInfoArray[i].hostName;
        eval("device" + i).deviceNum = i;
        eval("device" + i)._x = device0._x + device0._width * i;
    }
    */
}

// Modified by Dean Wood 2/4/2003 to accomodate new look
function menuInitialize()
{
    var numOfSteps = AnswerArray.length - 1;

//resize
resizeChapter();


    // if we have more than 18 buttons, we have to allow for scroll, otherwise turn it off
   if (totalSteps < 17)
        scrollDisable();

    blank.buttonlist.attachMovie("stepblock","stepblock","8000");

    // miwang
    AnswerArray[0][0].stepnum = 0;
    var j = 0;
    blank.buttonlist.attachMovie("step","step" + j, j);
    blank.buttonlist["step" + j].text = j;
    blank.buttonlist["step" + j].num = 0;
    blank.buttonlist["step" + j]._x = 2;
    blank.buttonlist["step" + j]._y = 2;
    j++;

    for (i = 1; i <= numOfSteps; i++)
    {
        // miwang
        // if step number is different from the previous element's, then add new button
        if (AnswerArray[i][0].stepnum != AnswerArray[i-1][0].stepnum)
        {
            blank.buttonlist.attachMovie("step","step" + j, j);
            blank.buttonlist["step" + j].text = j;
            blank.buttonlist["step" + j].num = i;
            blank.buttonlist["step" + j]._x = 2;
            blank.buttonlist["step" + j]._y = (j * 14) + 2;

            j++;
        }
    }

    _root.coverButton(0);

//resizeStepScroll();

	
}

function scrollDisable()
{
    blank.scrollUp._visible = false;
    blank.scrollDown._visible = false;
    // Commented out by Dean Wood 2/6/2003 slider removed
    //blank.scrollbar._visible = false;
}

// Modified by Dean Wood 2/6/2003
function stepscrollUp()
{
	if (blank.buttonlist._y < 0)
		blank.buttonlist._y = blank.buttonlist._y + 14;
}

// Modified by Dean Wood 2/6/2003
function stepscrollDown()
{
	if(blank.buttonlist._y + blank.buttonlist._height > 235)
		blank.buttonlist._y = blank.buttonlist._y - 14;
}

// Commented out by Dean Wood 2/6/2003 slider removed
/*
function step_setScroll(slider)
{
  //trace("Y = " +slider._y);


  _root.blank.buttonlist._y = (1-(slider._y/450) * (_root.blank.buttonlist._height-271.4));

}

function step_setSlider(buttonlist)
{
  //trace("Y = " +slider._y);
  //trace("buttonlist Y = " + _root.menu.buttonlist._y);

  _root.blank.scrollbar.slider._y = (425 * ((Math.abs(_root.blank.buttonlist._y))/(_root.blank.buttonlist._height-271.4)));
  trace("buttonlist._y = " + _root.blank.buttonlist._y);
  trace("buttonlist._height = " + _root.blank.buttonlist._height);
  trace("scrollbar slider._y = " + _root.blank.scrollbar.slider._y);
  trace("scrollbar._height = " + _root.blank.scrollbar._height);
}
*/

function stepClick(text)
{
    // reset the matrix check array
    matrix = null;
    var prevStep = _root.stepnum; // THIS is important for remembering the previous step.

    //check to see if he has clicked on the same step
    i = Number(text);
    if (_root.stepnum == i)
    {
        matrix = null;
        _root.showInstruction(_root.stepnum);
        return;
    }
    clickedButton = i;
    _root.stepnum = i;

    //begin loading the images is done here
    _root.loadImage(_root.stepnum, prevStep);
    //end loading the images is done here

    //check to see if the answer button is clicked if so then display the answer
    if (showAns == true)
       {
        showAnswer(i);
          }
    else
    {
        _root.goToNextStep(_root.stepnum, prevStep);

        //add for step 0
        _root.showInstruction(_root.stepnum);
        if (_root.stepnum == 0  )
        {
		trace(_root.menu.toolbar.button_topology._visible);
		//if (_root.menu.toolbar.button_topology._visible==true)
		//Bargavi for modifying the topology button for different cases
		if (graphicArray[0] != "")
		{
			if (_root.menu.toolbar.current == "topology") 
			{
				_root.Topology._visible = true;
				_root.menu.toolbar.marker_topology._visible=true;
				_root.menu.toolbar.marker_type._visible=false;
				_root.menu.toolbar.marker_help._visible=false;
				return;
			}
		}
		//End Bargavi		
	_root.exitRouter();

        }
        else
        {
            var rptr = eval("_root.r" + _root.VISIBLE_ROUTER);
            rptr.lineIndexCounter = 0;

            _root.commandline_setMode(_root.stepModeArray[_root.stepnum], _root.active_router);
            output_write("\n");
            _root.commandline_changeProcess("commandline_processCommandLine");
            _root.commandline_commandLine();
        }
    }
}

function coverButton(step)
{
    blank.buttonlist.stepblock._visible = true;
    blank.buttonlist.stepblock._x = eval("blank.buttonlist.step" + step)._x;
    blank.buttonlist.stepblock._y = eval("blank.buttonlist.step" + step)._y;
    blank.buttonlist.stepblock.text = step;
}

function stepRollOver()
{
/*
  x = _xmouse;
  y = _ymouse;

  for (i = 0; i <= totalSteps; i++)
  {
    found = eval("blank.buttonlist.step" + i).hitTest (x, y, false);
    if (found)
    {
      eval("blank.buttonlist.step" + i).gotoAndStop(2);
    }
  }
  */
}

function stepRollOut()
{
/*
  x = _xmouse;
  y = _ymouse;

  for (i = 0; i <= totalSteps; i++)
  {
    found = eval("blank.buttonlist.step" + i).hitTest (x, y, false);
    if (!found)
    {
      if (i != clickedButton)
        eval("blank.buttonlist.step" + i).gotoAndStop(1);
    }
  }
  */
}


function exitRouter()
{
    // normal exit
    var r = eval("_root.r" + _root.active_router);
    output_write("\n");
    r.userHistory = new Array();
    r.configHistory = new Array();
    _root.commandline_changeProcess("router_startup_processStartUp");
   // begin modifying to flash MX compatibility by Bargavi 
    with (eval("_root.r" + _root.active_router )) 
      {
	router_startup = false;
      } // forcing to be restarted 
   //end of modification to flash MX by Bargavi 
    router_startup_checkStartUp();
    _root.disableAllSteps();//commented by Bargavi
    
}


function disableAllButtons()
{
  blank.buttonlist.stepblock._visible = false;
}


function populateTopic()
{
    _root.menu.topicCovered.text = _root.chapterCovered ;
//  Commented out by Dean Wood 2/4/2003
//  Changing the step image to be viewed as the topology.
//  if (_root.wantShowTopology == false)
//      _root.menu.TopologyButton._visible = false;

}


function resizeChapter()
{
	_root.menu.topicCovered.autosize = true;
	var difference = _root.menu.background.chapterBackground._height;
	_root.menu.background.chapterBackground._height = _root.menu.topicCovered._height;
	

	difference =  _root.menu.background.chapterBackground._height - difference;

	_root.blank._y = _root.menu.background.chapterBackground._y + _root.menu.background.chapterBackground._height ;
	_root.menu.ScrollBar._y = _root.menu.background.chapterBackground._y + _root.menu.background.chapterBackground._height;

	_root.menu.ScrollBar._height = _root.menu.ScrollBar._height - difference;
	_root.menu.instr._y = _root.menu.background.chapterBackground._y + _root.menu.background.chapterBackground._height ;
	_root.menu.instr._height = _root.menu.instr._height - difference ;
	_root.blank._height = _root.blank._height - difference ;
	
}

function resizeStepScroll()
{
	/*var lengthofChapter = String(_root.menu.topicCovered).length;
	if ( lengthofChapter < 25)
	{
		if (totalSteps < 18)
		    scrollDisable();
	}
	*/
	
}
