var _popUpImages = {
  "anansi" : ["Anansi's Maze", 240, 134, 800, 447],
  "triskelion" : ["Gamesters of Triskelion", 240, 187, 800, 624],
  "czech" : ["Star Czech", 300, 215, 800, 600],
  "czech2" : ["Star Czech", 240, 219, 800, 731],
  "octamaze" : ["Octamaze", 240, 149, 800, 497],
  "planks" : ["Six Tabbed Planks", 240, 225, 700, 656],
  "ooo-tray" : ["Ooo Tray", 240, 180, 800, 600],
  "ooo-tray-2" : ["Ooo Tray", 240, 164, 800, 546],
  "ooo-tray-cherry" : ["Ooo Tray", 240, 174, 800, 579],
  "ooo-tray-mahogany" : ["Ooo Tray", 240, 171, 800, 570],
  "ooo-tray-maple" : ["Ooo Tray", 240, 169, 800, 562],
  "dominoes" : ["Easter Island Dominoes", 240, 199, 723, 600],
  "perkinson" : ['The "Perkinson Guest Bathroom Tile" Puzzle', 240, 142, 800, 475],
  "sleazier" : ["Sleazier", 215, 240, 628, 700],
  "doven" : ["The Devil's Half Doven", 200, 244, 492, 600],
  "vizier-front" : ["The Grand Vizier - front", 240, 192, 800, 639],
  "vizier-back" : ["The Grand Vizier - back", 240, 182, 800, 605],
  "flag" : ["Hinomaru: The Japanese Flag Puzzle", 240, 157, 800, 522],
  "flag-paper" : ["Hinomaru: The Japanese Flag Puzzle - paper version", 240, 151, 800, 503],
  "nothing" : "nothing"
};

var _productDetails = {
  "anansi" : ["Anansi's Maze", "4.25 by 4.25 inches, Lucite", 30],
  "czech" : ["Star Czech", "12 pieces, about 2.4 inches across, Lucite", 20],
  "triskelion" : ["Gamesters of Triskelion", "Eight 2-inch pieces plus a 5-inch tablet", 20],
  "octamaze" : ["Octamaze", "Eight pieces, 2 inches on a side", 15],
  "planks" : ["Six Tabbed Planks", "2 inches cubed, Lucite", 15],
  "ooo-tray": ["Ooo Tray", "4.7 by 4.25 inches, wood", 30],
  "dominoes" : ["Easter Island Dominoes", "6.75 by 5 inches, Lucite", 30],
  "perkinson" : ["The 'Perkinson Guest Bathroom Tile' Puzzle", '5.25 by 4.75 inches, Lucite', 30],
  "sleazier" : ["Sleazier", "4.25 by 4.25 inches, Lucite", 25],
  "doven" : ["Devil's Half Doven", "Seven pieces, 0.75 by 3 inches, walnut", 25],
  "vizier" : ["The Grand Vizier", "7 by 10 inches, white masonite", 35],
  "flag" : ["Hinomaru: the Japanese Flag Puzzle", "7 by 5 inches, Lucite and paper", 25],
  "flag-paper" : ["Hinomaru: the Japanese Flag Puzzle (paper version)", "Twelve 1 by 2 inch paper cards", 5],
  "nothing" : "nothing"
};

var _productOptions = {
  "ooo-tray" : ["Wood", [ "Maple", "Cherry (CURRENTLY SOLD OUT)"]],
  "nothing" : []
};

var _soldOut = { "doven" : true };

function PopUpProduct(id)
{
  var a = _popUpImages[id];
  PopUpImage(a[0], id, a[1], a[2], a[3], a[4]);
}

function PopUpImage(name, fileName, thumbWidth, thumbHeight, imageWidth, imageHeight)
{
  var imageURL = 'http://www.pavelspuzzles.com/images/' + fileName + '.jpg';
  var thumbURL = 'http://www.pavelspuzzles.com/images/' + fileName + '-thumb.jpg';
  var popupWidth = imageWidth + 36;
  var popupHeight = imageHeight + 30;
  var openOptions = 'width=' + popupWidth + ',height=' + popupHeight + ',resizable';
  var onClickJS = "window.open('" + imageURL + "', '_blank', '" + openOptions + "')";

  document.write('<a href="javascript:void" ');
  document.write('     onclick="' + onClickJS + '"');
  document.write('     title="' + name + '">');
  document.write('  <img src="' + thumbURL + '" alt="' + name + '"');
  document.write('          class="pop-up-image"');
  document.write('          height="' + thumbHeight + '" width="' + thumbWidth + '">');
  document.write('</a>');
}

function AddToCart(id)
{
  var a = _productDetails[id];
  AddToCartButton(id, a[0], a[1], a[2]);
}

function AddToCartButton(id, name, composition, price)
{
  document.write('<DIV CLASS="add-to-cart"><P>');
  document.write('<B>' + name + '</B><BR>');
  document.write(composition + '<BR>');
  document.write('$' + price + ' each<BR>');
  if (_soldOut[id]) {
    document.write('<FONT COLOR="red">Currently sold out!</FONT>');
  } else {
    document.write('<FORM ACTION="https://www.paypal.com/cgi-bin/webscr" METHOD=POST');
    document.write('       TARGET="paypal" ONSUBMIT="return OnAddToCart()">');
    document.write('<INPUT TYPE=hidden NAME="cmd" VALUE="_cart">');
    document.write('<INPUT TYPE=hidden NAME="add" VALUE="1">');
    document.write('<INPUT TYPE=hidden NAME="business" VALUE="pavel@keltis.us">');
    document.write('<INPUT TYPE=hidden NAME="currency_code" VALUE="USD">');
    // Setting no_shipping=2 means to *require* a shipping address...
    document.write('<INPUT TYPE=hidden NAME="no_shipping" VALUE="2">');

    document.write('<INPUT TYPE=hidden NAME="item_name" VALUE="' + name + '">');
    document.write('<INPUT TYPE=hidden NAME="amount" VALUE="' + price + '">');
    document.write('<INPUT TYPE=hidden NAME="shopping_url" VALUE="' + location.href + '">');

    var optionRecord = _productOptions[id];

    if (optionRecord) {
      var optionName = optionRecord[0];
      var options = optionRecord[1];

      document.write('<INPUT TYPE=hidden NAME="on0" VALUE="' + optionName + '">');
      document.write('<SELECT NAME="os0">');
      for (var i in options) {
        var opt = options[i];

        document.write('<OPTION VALUE="' + opt + '">' + opt);
      }
      document.write('</SELECT><BR>');
    }

    document.write('<INPUT TYPE="image" SRC="http://images.paypal.com/images/x-click-but22.gif"');
    document.write('       BORDER="0" NAME="submit"');
    document.write('       ALT="Add to Cart at PayPal">');
    document.write('</FORM>');
  }
  document.write('</P></DIV>');
}

function OnAddToCart()
{
//  alert("Got here!");
  return true;
}

function ViewCartButton()
{
  document.write('<FORM ACTION="https://www.paypal.com/cgi-bin/webscr" METHOD=POST');
  document.write('       TARGET="PayPal">');
  document.write('<INPUT TYPE=hidden NAME="cmd" VALUE="_cart">');
  document.write('<INPUT TYPE=hidden NAME="display" VALUE="1">');
  document.write('<INPUT TYPE=hidden NAME="business" VALUE="pavel@keltis.us">');
  // Setting no_shipping=2 means to *require* a shipping address...
  document.write('<INPUT TYPE=hidden NAME="no_shipping" VALUE="2">');

  document.write('<INPUT TYPE="image" SRC="https://www.paypal.com/en_US/i/btn/view_cart_02.gif"');
  document.write('       BORDER="0" NAME="submit"');
  document.write('       ALT="View Cart at PayPal">');
  document.write('</FORM>');
}
