var pageName = window.location.pathname.substring( window.location.pathname.lastIndexOf( '/' ) + 1 );
var currStep = parseInt( pageName.substring( 4, pageName.lastIndexOf( '.' )));

function mok3_tutorialInit()
{
	document.write( '<style>\n' );

	var s = "";
	var s2 = "";
	for ( var i = 1; i <= numSlides[currStep-1] ; ++i )
	{
		if ( i > 1 )
		{
			s += ",";
			s2 += ",";
		}
		s += "#slide" + i;
		s2 += ".slide" + i + " #slide" + i;
	}
	
	document.write( s  + ' { display: none; }\n' );
	document.write( s2 + ' { display: block; }\n' );
	document.write( '</style>' );
	
	
		
	dhtmlHistory.initialize();
  dhtmlHistory.addListener(mok3_slideChange);
  
  // if this is the first time we have
  // loaded the page...
  if (dhtmlHistory.isFirstLoad())
  {
  }
	
	mok3_updateSlide( mok3_getCurrSlide());
	mok3_updateSlideControls( mok3_getCurrSlide());

}

function prevslide()
{
	var hashString = window.location.hash.substring(1);
	var currSlide = mok3_getCurrSlide();

	if ( currSlide == 1 )
	{
		window.location = 'step' + (currStep-1) + '.html#' + numSlides[currStep-2];
		mok3_updateSlideControls(numSlides[currStep-2]);
	}
	else
	{
		--currSlide;
		dhtmlHistory.add( currSlide, null );
		mok3_updateSlide( currSlide );
		mok3_updateSlideControls( currSlide );
	}
}

function nextslide()
{
	var hashString = window.location.hash.substring(1);
	var currSlide = mok3_getCurrSlide();
	
	if ( currSlide == numSlides[currStep-1] )
	{
		window.location = 'step' + (currStep+1) + '.html#1';
	}
	else
	{
		dhtmlHistory.add(currSlide+1, null);
		mok3_updateSlide( currSlide+1 );
		mok3_updateSlideControls( currSlide+1 );
	}
}

function mok3_getCurrSlide()
{	
	var hashString = window.location.hash.substring(1);
	var currSlide;
	if ( hashString == "" )
		return 1;
	else
		return parseInt(window.location.hash.substring(1));
}

function mok3_slideChange(newLocation, historyData)
{
	if ( newLocation == "" || newLocation == null )
	{
		newLocation = 1;
	}
	mok3_updateSlide( newLocation );
	mok3_updateSlideControls( newLocation );
}

function mok3_updateSlide( slide )
{
	document.getElementById( 'slides' ).className = 'slide' + slide;
}

function mok3_updateSlideControls( slide )
{
	if ( slide == 1 && currStep == 1 )
		document.getElementById( 'slide_prev' ).innerHTML = '<div class="disabled" title="Beginning of slides"></div>';
	else
	{
		var prevHref = "#" + (slide-1);
		if ( slide == 1 )
			prevHref = 'step' + (currStep - 1) + '.html#' + numSlides[currStep-2];
		document.getElementById( 'slide_prev' ).innerHTML = '<a href="' + prevHref + '" title="Previous slide" onclick="prevslide();" ondblclick="prevslide();"> </a>';
	}
	if ( currStep == numSlides.length && slide == numSlides[ currStep-1 ] )
		document.getElementById( 'slide_next' ).innerHTML = '<div class="disabled" title="End of slides"></div>';
	else
	{
		var nextHref = "#" + (slide+1);
		if ( slide == numSlides[currStep-1] )
			nextHref = 'step' + (currStep + 1) + '.html#1';
		document.getElementById( 'slide_next' ).innerHTML = '<a href="' + nextHref + '" title="Next slide" onclick="nextslide();" ondblclick="nextslide();"> </a>';
	}
}

