// +------------------------------------------------------------+
// | Puzzle OnSite(loader)           Version 2.4                |
// | Created 07/03/2002              Last Modified 07/03/2002   |
// | Web Site:                       http://yx.webprovider.com  |
// | eMail:                          m_yangxin@hotmail.com      |
// +------------------------------------------------------------+
// | Copyright 2002  Xin Yang        All Rights Reserved.       |
// +------------------------------------------------------------+

var isIE=(navigator.appName=="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Mac")<0)?true:false;
var isNN=(navigator.appName=="Netscape" && navigator.appVersion.substring(0,1)=="4")?true:false;
var isN6=(navigator.appName=="Netscape" && navigator.userAgent.indexOf("Gecko")!=-1)?true:false;

var puzzle_window = null;
var puzzle_page = "puzzle24.html";

function setPage(page) {
  puzzle_page = page;
}

function puzzleOBJ(puzzle_name,image_source,image_width,image_height,grip_x,grip_y,table_gap,win_width,win_height,x_align,y_align) {
  this.name = puzzle_name;
  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.win_width = win_width;
  this.win_height = win_height;
  this.x_align = x_align;
  this.y_align = y_align;
}; var puzzlePool = new Array();


function addPuzzle(puzzle_name,image_source,image_width,image_height,grip_x,grip_y,table_gap,win_width,win_height,x_align,y_align) {
  puzzlePool[puzzlePool.length] = new puzzleOBJ(puzzle_name,image_source,image_width,image_height,grip_x,grip_y,table_gap,win_width,win_height,x_align,y_align);
}

function findPuzzle(puzzle_name) {
  for (var i=0; i<puzzlePool.length; i++) {
    if (puzzlePool[i].name == puzzle_name)
      return puzzlePool[i];
  }

  if (puzzlePool.length > 0)
    return puzzlePool[0]
  else
    return null;
}

function loadPuzzle(puzzle_name) {
  var puzzle = findPuzzle(puzzle_name);

  if (puzzle != null) {
    var window_para = "width=" + puzzle.win_width +",height=" + puzzle.win_height + ",titlebar=1";
    var page_para = puzzle_page + "?" + puzzle.source + "," + puzzle.width + "," + puzzle.height + "," + puzzle.grip_x + "," + puzzle.grip_y + "," + puzzle.table_gap + "," + puzzle.x_align + "," + puzzle.y_align;

    if (isIE || isNN || isN6) {
      if (puzzle_window != null) {
        if (!puzzle_window.closed) {
          puzzle_window.close();
        }
      }

      puzzle_window = window.open(page_para, "Puzzle", window_para);
    }
  }  
  else {
    alert("Puzzle Not Found.");
  }
}

