//////////////////////////////////////////////////////////
//    Script file for ZM2 Tutorial
//////////////////////////////////////////////////////////

Sequence =
  [
  //basic lessons
  "contents",
  "les1_intro",
  "les1_ui",
  "les1_views",
  "les1_basicedit",
  "les1_objbrowser",
  "les1_axessel",
  "les1_levels",
  "les1_beyond",

  "les2_intro",
  "les2_create",
  "les2_display",
  "les2_modify",
  "les2_conclusion",

  "les3_modelling",
  "les3_properties",
  "les3_images",
  "les3_side",
  "les3_frontrear",
  "les3_bottom",
  "les3_conclusion",

  //advanced lessons
  null,
  "advcontents",
  "les1_manipsffd",
  "les1_splines",
  "les1_textures",
  "les1_uvmapping",
  "les2_shading",
  "les2_normtools",
  "les3_parts",
  "les3_instance",
  "les3_paint",
  "les3_skeletons",
  "appendix_config",
  "appendix_regexp",
  ];

function Next(txt)
{
  for (i = 0; i < Sequence.length; i++)
    if (Sequence[i] == txt && Sequence[i+1])
    {
      document.writeln("<a href=\""+Sequence[i+1]+".html\"><b>| NEXT |</b></a>");
      break;
    }
}


function Prev(txt)
{
  bResult = false;
  for (i = 1; i < Sequence.length; i++)
    if (!Sequence[i])
      bResult = true;
    else
    if (Sequence[i] == txt && Sequence[i-1])
    {
      document.writeln("<a href=\""+Sequence[i-1]+".html\"><b>| PREVIOUS |</b></a>");
      break;
    }
  return bResult;
}

//global. the small image you click on
var link;

function moveImage()
{
  if (!link)
    return;
  var img = document.all.imgFloater;
  var w = img.offsetWidth;
  var h = img.offsetHeight;

  if (w > img.style.pixelWidth) 
  {
    img.style.pixelWidth = w;
    window.setTimeout("moveImage()", 0);
    return;
  }

  var maxw = document.body.clientWidth;
  var maxh = document.body.clientHeight;

  if (h > maxh) 
  {
    if (w < maxw) 
  {
      w = w * 3 / 2;
      img.style.pixelWidth = (w < maxw) ? w : maxw;
      window.setTimeout("moveImage()", 0);
      return;
    }
  }

  var x=0,y=0;

  var linkLeft = link.offsetLeft - document.body.scrollLeft;
  var linkRight = linkLeft + link.offsetWidth;

  var linkTop = link.offsetTop - document.body.scrollTop;
  var linkBottom = linkTop + link.offsetHeight;

  var cxMin = link.offsetWidth - 24;
  if (cxMin < 16)
    cxMin = 16;

  if (linkLeft + cxMin + w <= maxw) 
  {
    x = maxw - w;
    if (x > linkRight + 8)
      x = linkRight + 8;
    y = maxh - h;
    if (y > linkTop)
      y = linkTop;
  }
  else if (linkBottom + h <= maxh) 
  {
    x = maxw - w;
    if (x < 0)
      x = 0;
    y = linkBottom;
  }
  else if (w <= linkRight - cxMin) 
  {
    x = linkLeft - w - 8;
    if (x < 0)
      x = 0;
    y = maxh - h;
    if (y > linkTop)
      y = linkTop;
  }
  else if (h <= linkTop) 
  {
    x = maxw - w;
    if (x < 0)
      x = 0;
    y = linkTop - h;
  }
  else if (w >= maxw) 
  {
    x = 0;
    y = linkBottom;
  }
  else 
  {
    w = w * 3 / 2;
    img.style.pixelWidth = (w < maxw) ? w : maxw;
    window.setTimeout("moveImage()", 0);
    return;
  }
  img.style.left = x + document.body.scrollLeft;
  img.style.top = y + document.body.scrollTop;
  img.style.visibility="visible";
}

//
//
function showImage(theID)
{
  window.event.returnValue = false;
  window.event.cancelBubble = true;
  if (document.all.imgFloater.style.visibility=="visible" &&
      document.all.floaterImage.src == theID.src)
    document.all.imgFloater.style.visibility="hidden";
  else
  {
    document.all.imgFloater.style.visibility="hidden";
    document.all.imgFloater.style.pixelWidth=0;
    document.all.imgFloater.style.pixelHeight=0;
    document.all.floaterImage.src=theID.src;
    moveImage();
  }
}

function miniImage(theID)
{
  document.write("<br><img width=100 id=\"", theID, "\" src=\"images/", theID, ".gif\" style=\"cursor:hand;\" ");
  document.write("onClick=\"link = ",theID,"; showImage(",theID,"); return true;\" alt='Click to expand image' ");
  document.write("onMouseOver=\"document.all.",theID,"_zoom.className='zoomglasslon';\" ");
  document.write("onMouseOut=\"document.all.",theID,"_zoom.className='zoomglassloff';\">");
  document.write("<img id=\"",theID, "_zoom\" class='zoomglassloff' src='images/zoomglass.gif'><br>");
}

function miniImageL(theID)
{
  document.write("<br><img width=100 id=\"", theID, "\" src=\"images/", theID, ".gif\" style=\"cursor:hand;float:left; border:1px solid black;\" ");
  document.write("onClick=\"link = ",theID,"; showImage(",theID,"); return true;\" alt='Click to expand image' ");
  document.write("onMouseOver=\"document.all.",theID,"_zoom.className='zoomglasslon';\" ");
  document.write("onMouseOut=\"document.all.",theID,"_zoom.className='zoomglassloff';\">");
  document.write("<img id=\"",theID, "_zoom\" class='zoomglassloff' src='images/zoomglass.gif'><br>");
}

function miniImageR(theID)
{
  document.write("<br><img width=100 id=\"", theID, "\" src=\"images/", theID, ".gif\" style=\"cursor:hand;float:right; border:1px solid black;\" ");
  document.write("onClick=\"link = ",theID,"; showImage(",theID,"); return true;\" alt='Click to expand image' ");
  document.write("onMouseOver=\"document.all.",theID,"_zoom.className='zoomglassron';\" ");
  document.write("onMouseOut=\"document.all.",theID,"_zoom.className='zoomglassroff';\">");
  document.write("<img id=\"",theID, "_zoom\" class='zoomglassroff' src='images/zoomglass.gif'><br>");
}

function createImageContainer()
{
  document.write("<div id='imgFloater' style='position:absolute; left:0px; top:0px; border:2 outset #ccc; background:#ccc; color:#ccc; padding:0px; cursor:hand; visibility:hidden; z-index:100;' onClick='this.style.visibility=\"hidden\";'><img id='floaterImage' alt='Click to close'></div>");
}

//places previouse/next links using the filename from URL
function placePrevNext()
{
  strURL = document.URL;
  pos1 = 0;
  pos2 = 0;
  for (at = strURL.length; at > 0; at--)
    if (strURL.substring(at, at+1) == "." && pos2 == 0)
      pos2 = at;
    else
    if ((strURL.substring(at, at+1) == "/" || strURL.substring(at, at+1) == "\\") && pos1 == 0)
      pos1 = at+1;
  if (pos1 != 0 && pos2 != 0)
  {
    strFile = strURL.substring(pos1, pos2);
    secondPart = Prev(strFile);
    if (bResult)
      document.write("<a href='advcontents.html'>Table of contents</a>")
    else
      document.write("<a href='contents.html'>Table of contents</a>")
    Next(strFile);
  }
}

function toolDepends(dependStr)
{
  for (at = 0; at < dependStr.length; at++)
  {
    c = dependStr.substring(at, at+1);
    if (c == "a")
      document.write("<span class='tooldepends'>Axes</span>\n");
    else
    if (c == "p")
      document.write("<span class='tooldepends'>Pivot</span>\n");
    else
    if (c == "s")
      document.write("<img src='images/selon.gif'>\n");
    else
    if (c == "d")
      document.write("<img src='images/seloff.gif'>\n");
    else
    if (c == "1")
      document.write("<img src='images/lev1.gif'>\n");
    else
    if (c == "2")
      document.write("<img src='images/lev2.gif'>\n");
    else
    if (c == "3")
      document.write("<img src='images/lev3.gif'>\n");
    else
    if (c == "4")
      document.write("<img src='images/lev4.gif'>\n");
  }
}

function placeCopyright()
{
  document.write("<div class='topline' align=right>Copyritght &copy; Zanoza Software 2005. Last changed: 29st September 2005.</div>");
}

