// ------ this function is all you need to modify in this script ------

function defineImages() {
  picPool[0] = new picPara("images/puzzle1.jpg",252,380,6,5,5,"Monte Cristallo, 254x380, 6x5, 33kb");
  picPool[1] = new picPara("images/puzzle7.jpg",435,290,5,5,5,"Veduta dal Monte Cristallo, 435x290, 4x5, 35kb");
  picPool[2] = new picPara("images/puzzle2.jpg",250,380,5,4,5,"Lago di Braies, 251x380, 5x4, 40kb");
  picPool[3] = new picPara("images/puzzle8.jpg",380,250,5,5,5,"Le Tre Cime di Lavaredo, 380x253, 5x5, 30kb");
  picPool[4] = new picPara("images/puzzle3.jpg",260,380,5,4,5,"San Candido, 259x380, 5x4, 14kb");
  picPool[5] = new picPara("images/puzzle9.jpg",500,312,5,4,5,"Le Tofane, 500x312, 5x4, 39kb");
  picPool[6] = new picPara("images/puzzle4.jpg",252,380,4,5,5,"Praterpizza, 253x380, 4x5, 43kb");
  picPool[7] = new picPara("images/puzzle10.jpg",400,280,5,5,5,"Vienna Stephansplatz, 400x280, 5x5, 18kb");
  picPool[8] = new picPara("images/puzzle5.jpg",250,380,5,4,5,"Vienna Reflections, 250x380, 5x4, 20kb");
  picPool[9] = new picPara("images/puzzle11.jpg",400,260,5,5,5,"Vienna Wagnerhaus, 400x260, 5x5, 34kb");
  picPool[10] = new picPara("images/puzzle6.jpg",260,380,4,5,5,"Vienna Prater, 260x380, 4x5, 37kb");
  picPool[11] = new picPara("images/puzzle12.jpg",380,270,5,6,10,"Vienna Karlsplatz, 380x270, 5x6, 42kb");
}

//------ you don't need to care about the following codes ------

var isIE4 = false; isNN4 = false;

var picPool = new Array();
var pic_image_source = "";
var pic_image_width = 0;
var pic_image_height = 0;
var pic_grip_x = 1;
var pic_grip_y = 1;
var pic_table_gap = 0;

var puzzle_window = null;

function mouseHover() {
  window.status = picPool[this.index].info;
  return true;
}

function mouseGone() {
  window.status = window.defaultStatus;
  return true;
}

function mouseClick() {
  goPuzzleX(this.index);
  return false;
}

function picPara(image_source,image_width,image_height,grip_x,grip_y,table_gap,image_info) {
  this.source = image_source;
  this.width = image_width;
  this.height = image_height;
  this.grip_x = grip_x;
  this.grip_y = grip_y;
  this.table_gap = table_gap;
  this.info = image_info;
}

function setupImages() {
  isIE4 = (document.all)?true:false; isNN4 = (document.layers)?true:false;

  defineImages();

  var linksCount = document.links.length, hashIndex = -1, puzzleIndex = -1, hashTag = "puzzlex";
  for (var i = 0; i < linksCount; i++) {
    hashIndex = document.links[i].hash.indexOf(hashTag);
    if (hashIndex != -1) {
      puzzleIndex = parseInt(document.links[i].hash.substring(hashIndex+7));
      document.links[i].index = puzzleIndex;
      document.links[i].onmouseover = mouseHover;
      document.links[i].onmouseout = mouseGone;
      document.links[i].onclick = mouseClick;
    }
  }
}

function Build_Puzzle() {
  var window_para = "width=" + (pic_image_width + pic_table_gap * 6) +",height=" + (pic_image_height + pic_table_gap * 6) + ",titlebar=1";

  if (isIE4 || isNN4) {
    if (puzzle_window != null)
      if (!puzzle_window.closed)
        puzzle_window.close();

    puzzle_window = window.open("puzzlex.html", "Puzzle_Window", window_para); }
  else {
    alert("Sorry !\nYou need a version 4 or above browser.");
  }
}

function goPuzzleX(pic_index) {
  pic_image_source = picPool[pic_index].source;
  pic_image_width = picPool[pic_index].width;
  pic_image_height = picPool[pic_index].height;
  pic_grip_x = picPool[pic_index].grip_x;
  pic_grip_y = picPool[pic_index].grip_y;
  pic_table_gap = picPool[pic_index].table_gap;

  Build_Puzzle();
}
