var loaded = 0;

var child = new Array;

////////////////////////////////////////////////////////////////////////////////////////////

function getObject(id, parent) {
  var obj = (
    document.getElementById 
      ? document.getElementById(id)
      : document.all 
          ? document.all[id]
          : eval((parent ? 'parent.' : '') + 'document.' + id)
  );
  if (!obj.style) obj.style = obj;

  return obj;
}

function getImage(id, parent) {
  var obj = 
    document.getElementById 
      ? document.getElementById(id)
      : document.all 
          ? document.all[id] : obj;

  if (!obj) {
    if (parent) { parent = getObject(parent); }
    obj = eval((parent ? 'parent.' : '') + 'document.' + id);
  }
  if (!obj.style) obj.style = obj;

  return obj;
}

////////////////////////////////////////////////////////////////////////////////////////////

var precontent, content, postcontent, contentscrolling = 0, contentpos=0, contentmaxpos, precontentheight, contentheight, contentpgsize, scrolltimer = 0;

function contentscroll() {
  scrolltimer = 0;
  if (contentscrolling != 0) {
    contentpos += contentscrolling;
    if (contentpos < -precontentheight) {contentpos = -precontentheight; }
    if (contentpos > contentmaxpos) {contentpos = contentmaxpos; }
    precontent.style.top = -precontentheight-contentpos;
    content.style.top = -contentpos;
    postcontent.style.top = contentheight-contentpos;
    scrolltimer = setTimeout('contentscroll()', 50);
  }  
}

function getHeight(obj) {
  return obj.offsetHeight ? obj.offsetHeight : obj.clip.height;
}

function contentinitscrolling() {
  var contentsbound = getObject('contentbound');
  precontent = getObject('precontent', contentsbound);
  precontentheight = getHeight(precontent);
  if (precontentheight < 8) precontentheight = 0;
  content = getObject('content', contentsbound);
  contentheight = getHeight(content);
  postcontent = getObject('postcontent', contentsbound);
  contentpgsize = getHeight(contentsbound);
  contentmaxpos = getHeight(postcontent) + contentheight - getHeight(contentsbound);
  if (contentmaxpos < -precontentheight) contentmaxpos = -precontentheight;
  if (contentpos > contentmaxpos) {contentpos = contentmaxpos; }
  precontent.style.top = -precontentheight-contentpos;
  content.style.top = -contentpos;
  postcontent.style.top = contentheight-contentpos;
  precontent.style.visibility = 'visible';
  postcontent.style.visibility = 'visible';
}

function contentscrollup() {
  if (!loaded) return;
  contentscrolling = -8;
  if (! scrolltimer) contentscroll();
}
function contentscrolldown() {
  if (!loaded) return;
  contentscrolling = 8;
  if (! scrolltimer) contentscroll();
}
function contentstopscrolling() {
  if (!loaded) return;
  contentscrolling = 0;
  if (scrolltimer) {
    clearTimeout(scrolltimer);
    scrolltimer = 0;
  }
  document.cookie='contentpos=' + String(contentpos);
}
function contentpgup() {
  if (!loaded) return;
  contentstopscrolling();
  contentscrolling = -(contentpgsize-20);
  contentscroll();
  contentstopscrolling();
}
function contentpgdn() {
  if (!loaded) return;
  contentstopscrolling();
  contentscrolling = contentpgsize-20;
  contentscroll();
  contentstopscrolling();
}

function contentpre() {
  if (!loaded) return;
  contentstopscrolling();
  contentscrolling = -precontentheight-contentpos;
  contentscroll();
  contentstopscrolling();
}

function contentpost() {
  if (!loaded) return;
  contentstopscrolling();
  contentscrolling = contentheight-contentpos;
  contentscroll();
  contentstopscrolling();
}


var menuiem, menuTimer = 0;

function menu_init() {
  menuitem = new Array;

  for(i=1; i<=5; i++) {
//    imginit('menuimg' + String(i), 'images/menu' + String(i) + '_over.gif');
    menuitem[i] = getObject('menu' + String(i));
    if (!menuitem[i].style) { menuitem[i].style = menuitem[i]; }
    menuitem[i].savedVisibility = menuitem[i].style.visibility;
  }
}

function menu_enter(idx) {
  if (!loaded) return;
//  mouseover('menuimg' + String(idx));
  if (menuTimer) {
    clearTimeout(menuTimer);
    menuTimer = 0;
  }
  for(i = 1; i<menuitem.length; i++) {
    menuitem[i].style.visibility = (i == idx ? 'visible':'hidden');
  }
}

function menu_restore() {
  for(i = 1; i<menuitem.length; i++) {
    menuitem[i].style.visibility = menuitem[i].savedVisibility;
  }
}

function menu_exit(idx) {
  if (!loaded) return;
//  mouseout('menuimg' + String(idx));
  if (menuTimer) {
    clearTimeout(menuTimer);
  }
  menuTimer = setTimeout(menu_restore, 1000);
}

function mouseover(img, parent) {
  if (!loaded) return;
  img = getImage(img, parent);
  img.src = img.imgOver.src;
}

function mouseout(img, parent) {
  if (!loaded) return;
  img = getImage(img, parent);
  img.src = img.savedImg;
}

function imginit(img, over, parent) {
  img = getImage(img, parent);
  img.imgOver = new Image();
  img.imgOver.src = over;
  img.savedImg = img.src;
}

function load() {
  
  menu_init();
//  contentinitscrolling();
  loaded = 1;
}


