// JavaScript Document

function show_info_box()  {
  var arrayPageSize = getPageSize();
  var arrayPageScroll = getPageScroll();
  var infoboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
  var infoboxLeft = arrayPageScroll[0] + (arrayPageSize[2] / 15);
  document.getElementById("div_info_box").style.height = arrayPageSize[1] +"px";
  document.getElementById("div_info_box_container").style.top =  infoboxTop +"px";
  //document.getElementById("div_info_box_container").style.left =  infoboxLeft +"px";
  document.getElementById("div_info_box_container").style.maxWidth =  (arrayPageSize[2]*.80) +"px";
  document.getElementById("div_info_box_container").style.maxHeight = (arrayPageSize[3]*.80) +"px";
  document.getElementById("div_info_box_container").innerHTML = document.getElementById("div_info_box_contents").innerHTML
  document.getElementById("div_info_box").style.display = "inline";
	hideSelectBoxes();
}

function close_info_box()  {
  document.getElementById("div_info_box").style.display = "none";
  showSelectBoxes();
}

function show_add2cart()  {
  var arrayPageSize = getPageSize();
  var arrayPageScroll = getPageScroll();
  var infoboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
  var infoboxLeft = arrayPageScroll[0] + (arrayPageSize[2] / 15);
  document.getElementById("div_add2cart").style.height = arrayPageSize[1] +"px";
  document.getElementById("div_add2cart_container").style.top =  infoboxTop +"px";
  //document.getElementById("div_info_box_container").style.left =  infoboxLeft +"px";
  //document.getElementById("div_add2cart_container").style.maxWidth =  (arrayPageSize[2]*.80) +"px";
  //document.getElementById("div_add2cart_container").style.maxHeight = (arrayPageSize[3]*.80) +"px";
  document.getElementById("div_add2cart_container").innerHTML = document.getElementById("div_add2cart_contents").innerHTML
  document.getElementById("div_add2cart").style.display = "inline";
	hideSelectBoxes();
}

function close_add2cart()  {
  document.getElementById("div_add2cart").style.display = "none";
	document.getElementById('div_product_added').style.display = "none";
  showSelectBoxes();
}



// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

  var yScroll;

  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){   // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
  }

  arrayPageScroll = new Array('',yScroll)
  return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

  var xScroll, yScroll;

  if (window.innerHeight && window.scrollMaxY) {
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) {  // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }

  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
    pageHeight = windowHeight;
  } else {
    pageHeight = yScroll;
  }

  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }


  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  return arrayPageSize;
}

// -----------------------------------------------------------------------------------

//
// getKey(key)
// Gets keycode. If 'x' is pressed then it hides the lightbox.
//
function getKey(e){
  if (e == null) { // ie
    keycode = event.keyCode;
  } else { // mozilla
    keycode = e.which;
  }
  key = String.fromCharCode(keycode).toLowerCase();

  if(key == 'x'){
  }
}

// -----------------------------------------------------------------------------------

//
// listenKey()
//
function listenKey () {  document.onkeypress = getKey; }

// ---------------------------------------------------

function showSelectBoxes(){
  selects = document.getElementsByTagName("select");
  for (i = 0; i != selects.length; i++) {
    selects[i].style.visibility = "visible";
  }
}

// ---------------------------------------------------

function hideSelectBoxes(){
  selects = document.getElementsByTagName("select");
  for (i = 0; i != selects.length; i++) {
    selects[i].style.visibility = "hidden";
  }
}

// ---------------------------------------------------
