// all code Copyright 2004 Scott Dejmal
// if you use anything here, please leave this somewhere in the code

var aryScreenShots = new Array();
var aryNavItems = new Array();
var iCurrentSs = 0;
var aryFaqItems = new Array();


function _addFaqItem(eleFaqDiv, faqItem) {

  eleNewQ = document.createElement("span");
  eleNewQ.className = "faqQ";
  eleNewQ.innerHTML = faqItem.q + "<br>";

  eleNewA = document.createElement("span");
  eleNewA.className = "faqA";
  eleNewA.innerHTML = faqItem.a + "<br><br>";

  eleFaqDiv.appendChild(eleNewQ);
  eleFaqDiv.appendChild(eleNewA);
  
}

function _keypress() {
  //could use
  //http://developer.irt.org/script/1425.htm
  if (isIe()) {
    //alert(window.event.keyCode);
    iKey = window.event.keyCode;
    if (iKey == 60 || iKey == 44 || iKey == 112) {
      _prevScreenshot();
    }
    if (iKey == 62 || iKey == 46 || iKey == 110) {
      _nextScreenshot();
    }
    if (iKey == 102) {
      _fade_in_divs();
    }
  }
}

function _loadScreenshots() {
	_loadScreenshotData();
  _load_div(aryScreenShots[iCurrentSs]);
}

function _setTitle(newTitle) {
  //document.title = newTitle;
  eleSpan = document.getElementById("title1");
  eleSpan.innerHTML = newTitle;
}

function _prevScreenshot() {
  iCurrentSs += aryScreenShots.length - 1; //same as --, except no prob with % op
  iCurrentSs %= aryScreenShots.length;
  _load_div(aryScreenShots[iCurrentSs]);
}

function _nextScreenshot() {
  iCurrentSs++;
  iCurrentSs %= aryScreenShots.length;
   //= (iCurrentSs + 1) % aryScreenShots.length;
  _load_div(aryScreenShots[iCurrentSs]);
}

function _load_div(screenshot) {
  _setTitle((iCurrentSs + 1) + " of " + aryScreenShots.length);
  
  holderEle = document.getElementById("holder");
  
  newimg = document.createElement("img");
  newimg.src = screenshot.imgPath;

//alert(holderEle.childNodes);

  while (holderEle.childNodes.length > 0) {
    holderEle.removeChild(holderEle.firstChild);
  }

/*
  while (holderEle.children.length > 0) {
    oChild=holderEle.children(0);	
    holderEle.removeChild(oChild);
  }
  */
  holderEle.appendChild(newimg);
  for (i in screenshot.captions) {
    cap1 = screenshot.captions[i];
    place_info_box(holderEle, cap1.offsetX, cap1.offsetY, cap1.text, cap1.width);
  }
}

function ScreenShot(imgPath) {
  //preload image
  x = new Image();
  x.src = imgPath;
  var captions = new Array();
  this.imgPath = imgPath;
  this.captions = captions;
}

function Caption(offsetX, offsetY, text, optionalWidth) {
  this.offsetX = offsetX;
  this.offsetY = offsetY;
  this.text = text;
  this.width = optionalWidth;
}

function _ScreenShot_addCaption(Caption) {
  //this.captions.push(Caption);
  this.captions[this.captions.length] = Caption;

}
ScreenShot.prototype.addCaption = _ScreenShot_addCaption;

function isIe() {
  return(navigator.appVersion.indexOf("MSIE") != -1);
}


var q;
//var b;
function _on_tick() {
  //b -= 0.13;
  q += 0.02;
  //if (q < 1 || b > 0) {
  if (q < 1) {
//    if (b<0) { b=0 }
//    if (q>1) { q=1 }
    eles = document.getElementsByName("infobox");
    for (i=0; i<eles.length; i++) {
      ele = eles[i];
      ele.filters.item("DXImageTransform.Microsoft.BasicImage").Opacity = q;
      //ele.filters.item("DXImageTransform.Microsoft.Blur").Pixelradius = b;
      //ele.filters.item("DXImageTransform.Microsoft.MotionBlur").Strength=b;
    }
    window.setTimeout(_on_tick, 30);
  }
}

function _fade_in_divs(screenshot) {
  q = 0;
  b = 5;
  window.setTimeout(_on_tick, 30);
}

function place_info_box(ele, offsetX, offsetY, text, optionalWidth) {
  // could do upleft, upright, downleft, downright
  eleDiv = document.createElement("div");
  //eleDiv.innerText=text;
  eleDiv.innerHTML=text;
  eleDiv.style.position = "absolute";
  eleDiv.style.top = offsetY;
  eleDiv.style.left = offsetX;
  eleDiv.id = "infobox";
  if (optionalWidth != undefined) {
    eleDiv.style.width = optionalWidth;
  }
  eleDiv.className = "featureDesc";
  ele.appendChild(eleDiv);
}

