﻿var curMnJwl = 1;
var curJwl = 10;
var boolJwl = 0;
var aJwl = new Array();
var imgCount = 0;
var txtNodeTitle;


// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function startDisplay() {
  jewelDefLoad();
  setPage0();
  displayImg(1);
}
// END
// -------------------------------------------------------------------------------------------------


// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function mnJewelsDef() {
  this.bgClr     = "#000000";
  this.txtClr    = "#000000";
  this.name      = "x";
  this.imgStart  = "x";
  this.jwlCount  = 0;
  this.jwl     = new Array();
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function jewelDef() {
  this.title     = "x";
  this.text      = "x";
  this.textHL    = "x";
  this.material  = "x";
  this.mnImg     = new imageDef();
  this.aImg      = new Array();
  this.imgCount  = 0;
  this.imgLarge  = 0;
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function imageDef() {
  this.sName   = "x";
  this.sExt    = ".jpg";
  this.iPos    = 0;
  this.row     = 0;
  this.col     = 0;
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: calls hdrMouseOut and change another image to active
// -------------------------------------------------------------------------------------------------
function hdrMouseOver(nr) {
  hdrMouseOut();
  document.getElementById("imgHdr" + nr).src="pics/hdr_fg_0" + (nr) + ".gif";
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: Sets all aImg in the header to default image except the one of the active mn page
// -------------------------------------------------------------------------------------------------
function hdrMouseOut() {
  var i;
  for (i=1;i<=9;i++) {
   document.getElementById("imgHdr" + i).src="pics/hdr_bg_0" + (i) + ".gif";
  }
  document.getElementById("imgHdr" + (curMnJwl+1) ).src="pics/hdr_fg_0" + (curMnJwl+1) + ".gif";
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: Sets all aImg in the header to default image except the one of the active mn page
// -------------------------------------------------------------------------------------------------
function hdrClick(nr) {
  boolJwl = 0;
  displayImg(nr);
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: Changes one image
// -------------------------------------------------------------------------------------------------
function imgMouseOver(imgId) {
  if (boolJwl == 0) {
    var sName;
    var sExt;
    var str;
    var strArray;
    var obj;
    obj = document.getElementById(imgId);
    str = obj.getAttribute('src');
    strArray = str.split("/");
    str = strArray[strArray.length -1];
    strArray = str.split(".");
    sName = strArray[0];
    sExt  = strArray[1];
    obj.setAttribute('src', "pics/" + sName + "_mo." + sExt);
  }
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: Sets all aImg on the mn page to default image
// -------------------------------------------------------------------------------------------------
function imgMouseOut() {
  var strImgId;
  var iImgStart;
  if (curMnJwl == 0 || curMnJwl == 7) {
    strImgId  = "img_w";
    iImgStart = 1;
  } else {
    strImgId = "img";
    iImgStart = 0;
  }

  if (boolJwl == 0) {
    for (i=iImgStart;i<aJwl[curMnJwl].jwlCount;i++) {
      if (aJwl[curMnJwl].jwl[i].mnImg.row > -1 && aJwl[curMnJwl].jwl[i].mnImg.row < 5) {
        obj = document.getElementById(strImgId + aJwl[curMnJwl].jwl[i].mnImg.row.toString() + aJwl[curMnJwl].jwl[i].mnImg.col.toString());
        obj.setAttribute('src', "pics/" + aJwl[curMnJwl].jwl[i].mnImg.sName);
        obj.style.posWidth  = 139;
        obj.style.posHeight = 99;
        obj.width  = 139;
        obj.height = 99;
      }
    }
  }
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function imgClick(imgNr) {
  var i;
  if (boolJwl == 0) {
    boolJwl = 1;
    for (i=0;i<aJwl[curMnJwl].jwlCount;i++) {
      if (aJwl[curMnJwl].jwl[i].mnImg.iPos == imgNr) {
        curJwl = i;
      }
    }
    displayImg(curJwl+100)
    displayLarge(imgNr);
  } else {
    displayLarge(imgNr); 
  }
}
// END
// -------------------------------------------------------------------------------------------------


// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function jewelDefLoad() {
  var i;
  var j;
  var k;

  for (i=0;i<9;i++) {
    aJwl[i] = new mnJewelsDef();
    for (j=0;j<30;j++) {
      aJwl[i].jwl[j] = new jewelDef();
      for (k=0;k<30;k++) {
        aJwl[i].jwl[j].aImg[k] = new imageDef();
        aJwl[i].jwl[j].aImg[k].iPos = 0;
      }
    }
  }        

// Loads all the jewel page information from the external Javascript files
  loadJwls_01ik();
  loadJwls_02kj();
  loadJwls_03bj();
  loadJwls_04hj();
  loadJwls_05fd();
  loadJwls_06br();
  loadJwls_07or();
  loadJwls_08cv();
  loadJwls_09io();

// Puts all the loaded data in the right format in the right places in the aJwl array
  var str;
  for (i=0;i<aJwl.length;i++) {
    for (j=0;j<aJwl[i].jwlCount;j++) {
      if (aJwl[i].jwl[j].mnImg.iPos > 0) {
        if (aJwl[i].jwl[j].mnImg.iPos < 10) {
          aJwl[i].jwl[j].mnImg.sName = aJwl[i].imgStart + "0" + aJwl[i].jwl[j].mnImg.iPos.toString();
        } else {
          aJwl[i].jwl[j].mnImg.sName = aJwl[i].imgStart + aJwl[i].jwl[j].mnImg.iPos.toString();
        }
        aJwl[i].jwl[j].mnImg.iPos--;
        aJwl[i].jwl[j].mnImg.row = Math.floor(aJwl[i].jwl[j].mnImg.iPos/6);
        aJwl[i].jwl[j].mnImg.col = aJwl[i].jwl[j].mnImg.iPos - aJwl[i].jwl[j].mnImg.row*6;
        for (k=0;k<10;k++) {
          if (aJwl[i].jwl[j].aImg[k].iPos > 0) {
            aJwl[i].jwl[j].imgCount++;
            if (aJwl[i].jwl[j].aImg[k].iPos < 10) {
              aJwl[i].jwl[j].aImg[k].sName = aJwl[i].jwl[j].mnImg.sName + "_0" + aJwl[i].jwl[j].aImg[k].iPos.toString();
            } else {
              aJwl[i].jwl[j].aImg[k].sName = aJwl[i].jwl[j].mnImg.sName + "_" + aJwl[i].jwl[j].aImg[k].iPos.toString();
            }
            aJwl[i].jwl[j].aImg[k].sName = aJwl[i].jwl[j].aImg[k].sName + aJwl[i].jwl[j].aImg[k].sExt;
            aJwl[i].jwl[j].aImg[k].iPos--;
            aJwl[i].jwl[j].aImg[k].row = Math.floor(aJwl[i].jwl[j].aImg[k].iPos/6);
            aJwl[i].jwl[j].aImg[k].col = aJwl[i].jwl[j].aImg[k].iPos - aJwl[i].jwl[j].aImg[k].row*6;
          }
        }
        aJwl[i].jwl[j].mnImg.sName = aJwl[i].jwl[j].mnImg.sName + aJwl[i].jwl[j].mnImg.sExt;
      }
    }
  }
}
// END
// -------------------------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function displayImg(nr) {
  var obj;
  var objBg;
  var objBgWelcom;
  var objTxt;
  var objTxtWelcom;
  var strImgId;
  var iImgStart;

  if (boolJwl == 0) {
    curMnJwl=nr-1;
  }

  // set the correct div for the bg (welcom of general)
  objBg  = document.getElementById("divBg");
  objBgWelcom  = document.getElementById("divBgWelcom");
  if (curMnJwl == 0 || curMnJwl == 7) {
    iImgStart = 1;
    strImgId = "img_w";
    objBgWelcom.style.display = "";
    objBgWelcom.style.backgroundColor = aJwl[curMnJwl].bgClr;
    objBg.style.display = "none";
  } else {
    iImgStart = 0;
    strImgId = "img"
    objBg.style.display = "";
    objBg.style.backgroundColor = aJwl[curMnJwl].bgClr;
    objBgWelcom.style.display = "none";
  }

  // make all images small
  for (i=0;i<5;i++) {
    for (j=0;j<6;j++) {
      obj = document.getElementById(strImgId + i.toString() + j.toString());
      obj.setAttribute('src', "pics/dummy.gif");
      obj.style.posWidth  = 0;
      obj.style.posHeight = 0;
      obj.width  = 0;
      obj.height = 0;
    }
  }
  obj = document.getElementById("divImgCV");
  obj.style.display = "none";
  if (curMnJwl == 7) obj.style.display = "";

  // Make txt disappear
  objTxt = document.getElementById("divTxt");
  objTxtWelcom = document.getElementById("divTxtWelcom");
  objTxt.style.display = "none";
  objTxtWelcom.style.display = "none";
  if (curMnJwl == 0) objTxtWelcom.style.display = "";

  if (boolJwl == 0) {
    hdrMouseOver(nr);

    // Make large image disappear
    obj = document.getElementById("divImgLarge");
    obj.style.display = "none";

    // load all small images in background colour starting with image 1 (0=welcom text)
    for (i=iImgStart;i<aJwl[curMnJwl].jwlCount;i++) {
      if (aJwl[curMnJwl].jwl[i].mnImg.row > -1 && aJwl[curMnJwl].jwl[i].mnImg.row < 5) {
        obj = document.getElementById(strImgId + aJwl[curMnJwl].jwl[i].mnImg.row.toString() + aJwl[curMnJwl].jwl[i].mnImg.col.toString());
        obj.setAttribute('src', "pics/" + aJwl[curMnJwl].jwl[i].mnImg.sName);
      }
    }
  } else {
    // Make txt appear
    objTxt.style.display = "";

    // Make ImgLarge appear
    obj = document.getElementById("divImgLarge");
    obj.style.display = "";

    // set text for large image page
    nr = nr - 100;
    obj = document.getElementById("txtTitle");
    obj.firstChild.nodeValue = aJwl[curMnJwl].jwl[nr].title;
    obj.style.color = aJwl[curMnJwl].txtClr;
    obj = document.getElementById("txtText");
    obj.firstChild.nodeValue = aJwl[curMnJwl].jwl[nr].text;
    obj.style.color = aJwl[curMnJwl].txtClr;
    obj = document.getElementById("txtMaterial");
    obj.firstChild.nodeValue = aJwl[curMnJwl].jwl[nr].material;
    obj.style.color = aJwl[curMnJwl].txtClr;
    // load all small images into a large image page
    for (i=iImgStart;i<aJwl[curMnJwl].jwl[nr].imgCount;i++) {
      if (aJwl[curMnJwl].jwl[nr].aImg[i].row > -1 && aJwl[curMnJwl].jwl[nr].aImg[i].row < 5) {
        obj = document.getElementById("img" + aJwl[curMnJwl].jwl[nr].aImg[i].row.toString() + aJwl[curMnJwl].jwl[nr].aImg[i].col.toString());
        obj.setAttribute('src', "pics/" + aJwl[curMnJwl].jwl[nr].aImg[i].sName);
      }
    }
  }

  if (boolJwl == 0) {
    // resize all small images to correct size
    for (i=iImgStart;i<aJwl[curMnJwl].jwlCount;i++) {
      if (aJwl[curMnJwl].jwl[i].mnImg.row > -1 && aJwl[curMnJwl].jwl[i].mnImg.row < 5) {
        obj = document.getElementById(strImgId + aJwl[curMnJwl].jwl[i].mnImg.row.toString() + aJwl[curMnJwl].jwl[i].mnImg.col.toString());
        obj.style.posWidth  = 139;
        obj.style.posHeight = 99;
        obj.width  = 139;
        obj.height = 99;
      }
    }
  } else {
    // resize all small images to correct size
    for (i=iImgStart;i<aJwl[curMnJwl].jwl[nr].imgCount;i++) {
      if (aJwl[curMnJwl].jwl[nr].aImg[i].row > -1 && aJwl[curMnJwl].jwl[nr].aImg[i].row < 5) {
        obj = document.getElementById(strImgId + aJwl[curMnJwl].jwl[nr].aImg[i].row.toString() + aJwl[curMnJwl].jwl[nr].aImg[i].col.toString());
        obj.style.posWidth  = 139;
        obj.style.posHeight = 99;
        obj.width  = 139;
        obj.height = 99;
      }
    }
    displayLarge(aJwl[curMnJwl].jwl[nr].aImg[aJwl[curMnJwl].jwl[nr].imgLarge].iPos);
  }
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function displayLarge(imgNr) {
  var i;
  for (i=0;i<aJwl[curMnJwl].jwl[curJwl].imgCount;i++) {
    if (aJwl[curMnJwl].jwl[curJwl].aImg[i].iPos == imgNr) {
      //alert("aJwl=" + curMnJwl + "  jwl=" + curJwl + "  large=" + i + "  nr=" + imgNr);
      aJwl[curMnJwl].jwl[curJwl].imgLarge = i;
      obj = document.getElementById("imgLarge");
      obj.setAttribute('src', "pics/" + aJwl[curMnJwl].jwl[curJwl].aImg[i].sName);
      obj.style.posWidth  = 416;
      obj.style.posHeight = 297;
      obj.width  = 416;
      obj.height = 297;
    }
  }
}
// END
// -------------------------------------------------------------------------------------------------



// -------------------------------------------------------------------------------------------------
// FUNCTION: 
// -------------------------------------------------------------------------------------------------
function setPage0() {
  var obj;
  var newAElement
  
  // set the text for the welcom page
  obj = document.getElementById("txt0Title");
  obj.firstChild.nodeValue = aJwl[0].jwl[0].title;
  obj.style.color = aJwl[0].txtClr;
  obj = document.getElementById("txt0Text");
  obj.firstChild.nodeValue = aJwl[0].jwl[0].text;
  obj.style.color = aJwl[0].txtClr;
  obj = document.getElementById("txt0TextHL");
  obj.firstChild.nodeValue = aJwl[0].jwl[0].textHL;
  obj.style.color = "#000000";
  obj = document.getElementById("aMail");
  obj.setAttribute('href', 'mailto:h.knapen9@chello.nl');
  obj.firstChild.nodeValue = aJwl[0].jwl[0].material;
  obj.style.color = aJwl[0].txtClr;
}
// END
// -------------------------------------------------------------------------------------------------




