var _popUpImages = {
  "icicle" : ["Icicle Jam", 240, 224, 800, 748, 120, 112],
  "icicle2" : ["Icicle Jam, with pieces", 240, 184, 800, 613, 120, 92],
  "icicle3" : ["Icicle Jam, with Pavel's hand, for scale", 240, 238, 800, 793, 120, 119],
  "trominoes2" : ["Tromino Trails, 6x6 configuration", 240, 212, 800, 739, 120, 106],
  "trominoes3" : ["Tromino Trails, 8x9 configuration", 240, 189, 800, 631, 120, 95],
  "edgewise2" : ["Edgewise", 240, 185, 800, 616, 120, 93],
  "eights-easy" : ["Easy Eight", 240, 216, 800, 721, 120, 108],
  "eights-hard" : ["Hard Eight", 240, 198, 800, 661, 120, 99],
  "get-a-clue" : ["Get A Clue!", 240, 227, 800, 757, 120, 114],
  "calibron" : ["The Calibron 12-Block Puzzle", 240, 192, 800, 642, 120, 96],
  "calibron-ad-1935" : ["Calibron Puzzle Advertisement, 1935", 150, 68, 370, 169],
  "calibron-perspective-ad-1932": ["Calibron Paper Advertisement, 1932", 150, 260, 333, 579],
  "square-dance" : ["Square Dance", 240, 182, 800, 605, 120, 91],
  "anansi" : ["Anansi's Maze", 240, 134, 800, 447],
  "triskelion" : ["Gamesters of Triskelion", 240, 187, 800, 624],
  "crystal" : ["Crystal Ball", 240, 219, 800, 731],
  "crystal-2" : ["Crystal Ball", 240, 206, 800, 688],
  "octamaze" : ["Octamaze", 240, 149, 800, 497],
  "finnish" : ["The Finnish Cross", 240, 225, 700, 656],
  "ooo-tray" : ["Ooo Tray", 240, 180, 800, 600],
  "ooo-tray-2" : ["Ooo Tray", 240, 164, 800, 546],
  "ooo-tray-3" : ["Ooo Tray", 240, 219, 800, 731],
  "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 _popUpPDFs = {
  "cruciatus" : ["The Cruciatus Curse", 240, 238],
  "SpellingHex" : ["The Spelling Hex", 240, 211],
  "holiday-2010" : ["Holiday Puzzle 2010", 216, 240, 108, 120],
  "holiday-2011" : ["Holiday Puzzle 2011", 200, 144, 120, 86],
  "nothing" : "nothing"
};

var _productDetails = {
  "icicle" : ["Icicle Jam", "Six pieces, each about 6.5 by 3.5 inches", 30],
  "trominoes" : ["Tromino Trails", "6.3 by 5.3 inches, acrylic", 30],
  "edgewise" : ["Edgewise", "25 pieces, each about 2.3 inches square", 30],
  "get-a-clue" : ["Get a Clue!", "3.5 by 6 inches, acrylic", 30],
  "eights" : ["Easy Eight / Hard Eight", "4 by 4.25 inches, acrylic", 30],
  "calibron" : ["The Calibron 12-Block Puzzle", "12 pieces, about 6.5 inches square altogether", 30],
  "square-dance" : ["Square Dance", "5.25 by 5.25 inches, acrylic", 30],
  "anansi" : ["Anansi's Maze", "4.25 by 4.25 inches, Lucite", 30],
  "crystal" : ["Crystal Ball", "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],
  "finnish" : ["The Finnish Cross", "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, "perkinson" : true };

function PopUpProduct(id)
{
  var a = _popUpImages[id];
  PopUpFile(a[0], id, ".jpg", "thumb", a[1], a[2], a[3] + 36, a[4] + 30);
}

function PopUpTiny(id)
{
  var a = _popUpImages[id];
  PopUpFile(a[0], id, ".jpg", "tiny", a[5], a[6], a[3] + 36, a[4] + 30);
}

function PopUpPDF(id)
{
  var a = _popUpPDFs[id];
  PopUpFile(a[0], id, ".pdf", "thumb", a[1], a[2], 800, 600);
}

function PopUpFile(name, fileName, extension, thumbSuffix, thumbWidth, thumbHeight, popupWidth, popupHeight)
{
  var fileURL = 'http://www.pavelspuzzles.com/images/' + fileName + extension;
  var thumbURL = 'http://www.pavelspuzzles.com/images/' + fileName + '-' + thumbSuffix + '.jpg';
  var openOptions = 'width=' + popupWidth + ',height=' + popupHeight + ',resizable';
  var onClickJS = "window.open('" + fileURL + "', '_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>');
}

