function popup(src,width,height) {
  var options = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no,'
              + 'width=' + width + ','
              + 'height=' + height;
  var my_popup = window.open(src,'popup',options);
  if (!my_popup.opener) {
     my_popup.opener = window;
  }
}

function embed(name) {
  if (window.name!='main' && window.name!='booker_' && (window.innerHeight!=0 || window.innerWidth!=0)) {
    var b = location.pathname.lastIndexOf('/') + 1;
    var l = location.pathname.length;
    var n = location.pathname.substring(b,l-5);
    if (location.search.length > 1)
      n += '@' + location.search.substring(1);
    parent.location.replace("frames.html?"+n);
  }
}

var pix = new Array;

function pic(name,tw,th,pw,ph,title) {
  pix[name] = this;
  this.name = name;
  this.thumb_width = tw;
  this.thumb_height = th;
  this.pic_width = pw;
  this.pic_height = ph;
  this.title = title;

  this.show_thumb = function() {
    document.write("<a onClick=\"open_viewer('"+this.name+"'); return false;\" href=\";\">");
    document.write("<img src=\"pix/thumbs/"+this.name+".jpg\" alt=\""+this.title+"\" width="+this.thumb_width+" height="+this.thumb_height+">");
    document.write("</a>");
  }

  this.show_title = function() {
    document.write("<center><h2>"+this.title+"</h2></center>");
  }

  this.show_pic = function() {
    document.write("<center><img src=\"pix/"+this.name+".jpg\" alt=\"\" width="+this.pic_width+" height="+this.pic_height+"></center>");
  }
}

function open_viewer(name) {
  var wndw = top.frames["redirectionframe"];
  if (wndw == null) wndw = top
  wndw.location.href = "viewer.html?"+name;
}

function set() {
  this.names = set.arguments;
  
  this.show = function() {
    var i;
    
    var max_col_size = 0;
    var this_col_size = -20;
    
    for (i = 0; i < this.names.length; i++) {
      if (this.names[i] != 0)
        this_col_size += 20 + pix[this.names[i]].thumb_width;
      else if (this_col_size > max_col_size)
        max_col_size = this_col_size;
    }
    if (this_col_size > max_col_size)
    max_col_size = this_col_size;
    
    var border;
    var start_of_row = true;
    
    for (i = 0; i < this.names.length; i++) {
      if (this.names[i] != 0) {
	if (start_of_row) {
          var needed = -20;
	  for (j = i; j < this.names.length && this.names[j] != 0; j++) {
	    var pic = pix[this.names[j]];
	    needed += 20 + pic.thumb_width;
	  }
	  var border = Math.round((max_col_size - needed) / 2);
          if (i)
            document.write("<p>");
          document.write("<center><table><tr>");
	  if (border)
            document.write("<td width="+border+"></td>");
	  start_of_row = false;
	}
	else 
	  document.write("<td width=20></td>");
        document.write("<td>"); pix[this.names[i]].show_thumb(); document.write("</td>");
      }
      else if (!start_of_row) {
	if (border)
          document.write("<td width="+border+"></td>");
	document.write("</tr></table></center>");
	start_of_row = true;
      }
    }
    if (!start_of_row) {
      if (border)
      document.write("<td width="+border+"></td>");
      document.write("</tr></table></center>");
    }
  }
}

function linkpics() {
  var prev;
  var i,j;

  for (i = 0; i < linkpics.arguments.length; i++) {
    var set = linkpics.arguments[i];

        for (j = 0; j < set.names.length; j++) {
          if (set.names[j] != 0) { 
            var pic = pix[set.names[j]];
            if (prev) {
                  prev.next_pic = pic;
              pic.prev_pic = prev;
                }
                prev = pic;
          }
        }
  }
}

var menus = new Array;
var idx = 0;

function menu(title,href) {
  if (href) {
    menus[href] = this;
  }
  menus[idx++] = this;
  this.title = title;
  this.href = href;
  this.parent = null;
  if (menu.arguments.length > 2) {
    this.opened = false;
    this.submenus = new Array;
    var i;
    for (i = 2; i < menu.arguments.length; i++) {
      this.submenus[i-2] = menu.arguments[i];
      this.submenus[i-2].parent = this;
    }
  }
}

function menu_break(size) {
  menus[idx++] = this;
  this.size = (size == null ? 1 : size);
  this.parent = null;
}

function draw_menu(current) {
  var i;
  document.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">");
  for (i = 0; i < idx; i++) {
    var m = menus[i];
    if (m.parent == null) {
      if (m.size == null) {
        document.write("<tr><td align=\"left\">");
        var href = (m.href ? m.href : m.submenus[0].href);
        document.write(" <a href=\"menu.html?"+href+"\">"+m.title+"</a>");
        if (m.opened) {
          var j;
          for (j = 0; j < m.submenus.length; j++) {
            var s = m.submenus[j];
            document.write("<tr><td align=\"right\">");
            document.write(" <a href=\"menu.html?"+s.href+"\">"+s.title+"</a>");
          }
        }
      }
      else {
        document.write("<tr><td>");
        for (j = 0; j < m.size; j++)
          document.write("&nbsp;<br>");
      }
    }
  }
  document.write("</table>");
}

function mgo(href) {
  parent.frames["left"].location.href = "menu.html?"+href;
}

