var firstVisit=(document.cookie.length==0)

/*
This javascript icon code was originally developed by Dmitry Chirkin.
You may use this script free of charge for all legal purposes as long
as you agree not to remove this notice. Some parts of this page are
governed by their own copyright.
Please let me know of your web site if it employs this code.
Copyright 2002 (http://area51.berkeley.edu/~dima/)
*/

// general output interface

var nameCount=0
function newElement(x, y, width, height, bgcol){
  if(bgcol=="") bgcol="transparent"
  var el
  if(document.layers){
    el=new Layer(width)
     el.zIndex=0
     el.visibility="hide"
     el.left=x
     el.top=y
     bgcol=="transparent"?el.bgColor=null:el.bgColor=bgcol
     el.clip.width=width
     el.clip.height=height
  }
  else if(document.all || document.getElementById){
    var divname="iediv"+nameCount; nameCount++
    var html="<div id='"+divname+"' style='position:absolute;display:none;left:"+x+";top:"+y+";width:"+width+";height:"+height+";background-color:"+bgcol+"'><\/div>"
    if(document.all){
      document.body.insertAdjacentHTML("beforeEnd", html)
      el=document.all[divname]
    }
    else if(document.getElementById){
      el=document.createRange()
      el.setStartAfter(document.body.lastChild)
      document.body.appendChild(el.createContextualFragment(html))
      el=document.getElementById(divname)
    }
  }
  return el
}

function writeElement(el, str){
  if(el==null) return
  var width=document.layers?el.clip.width:el.style.width
  var height=document.layers?el.clip.height:el.style.height
  str='<table border=0 width='+width+' height='+height+' cellpadding=0 cellspacing=0><tr><td valign=center align=center>'+str+'</td></tr></table>'
  if(document.layers){
    el.document.write(str); el.document.close()
  }
  else if(document.all || document.getElementById) el.innerHTML=str
}

function showElement(el, show){
  if(el==null) return
  if(document.layers) el.visibility=show?"show":"hide"
  else if(document.all || document.getElementById) el.style.display=show?"inline":"none"
}

function putElement(x, y, width, height, bgcol, str){
  var el=newElement(x, y, width, height, bgcol)
  writeElement(el, str)
  showElement(el, true)
  return el
}

function moveElement(el, dx, dy){
  if(el==null) return
  if(document.layers) el.moveBy(dx, dy)
  else if(document.all || document.getElementById){
    el.style.left=parseInt(el.style.left.substring(0, el.style.left.indexOf("px")))+dx
    el.style.top=parseInt(el.style.top.substring(0, el.style.top.indexOf("px")))+dy
  }
}

function moveElementTo(el, x, y){
  if(el==null) return
  if(document.layers) el.moveTo(x, y)
  else if(document.all || document.getElementById){ el.style.left=x; el.style.top=y }
}

function setZindex(el, z){
  if(el==null) return
  if(document.layers) el.zIndex=z
  else if(document.all || document.getElementById) el.style.zIndex=z
}

// my alert

var alertActive=false
var alertWindow

function xalert(str, icw, ich){
  if(alertActive) return; else alertActive=true
  var html='<table border=2 width='+(icw-4)+' height='+(ich-4)+' cellpadding=0 cellspacing=0><tr><td valign=center align=center><form name="alert" onSubmit="return myalert2()"><font size=+2 style="font-size:18px">'+str+'</font><p><input type="submit" value="ok" name="enter"></form></td></tr></table>'
  alertWindow=putElement(Math.floor((docw-icw)/2), Math.floor((doch-ich)/2), icw, ich, "darkblue", html)
  setZindex(alertWindow, maxZindex-1)
  setTimeout("myalertfocus()", 100)
}

function myalert(str){
  xalert(str, 200, 150)
}

function myalert2(){
  writeElement(alertWindow, "")
  showElement(alertWindow, false)
  setZindex(alertWindow, 0)
  alertActive=false
  return false
}

function myalertfocus(){
  getBody(alertWindow).alert.enter.focus()
}

// some auxiliary functions

var spaceChar=escape(" ")

function showcookies(){
  var position=0
  str=unescape(document.cookie)
  while((aux=(str.substring(position, str.length)).indexOf(";"))!=-1){
    position+=aux
    auxstr=str.substring(position+1, str.length)
    while(auxstr.indexOf(unescape(spaceChar))==0) auxstr=auxstr.substring(1, auxstr.length)
    str=str.substring(0, position)+"\n"+auxstr
    position++
  }
  alert(str)
}

function quit(){
  location.replace("../../")
}

function get_cookie(Name){
  var search=Name+"="
  var returnvalue=""
  var cookie=document.cookie
  if(cookie.length>0){
    offset=cookie.indexOf(search)
    if(offset!=-1){
      offset+=search.length
      end=cookie.indexOf(";", offset)
      if(end==-1) end=cookie.length
      returnvalue=unescape(cookie.substring(offset, end))
    }
  }
  return returnvalue
}

function updatecookies(){
  str=unescape(document.cookie)+";"
  while((aux=str.indexOf(";"))!=-1){
    auxstr=str.substring(0, aux)
    str=str.substring(aux+1, str.length)
    while(auxstr.indexOf(unescape(spaceChar))==0) auxstr=auxstr.substring(1, auxstr.length)
    aux=auxstr.indexOf("="); if(aux<0) aux=0
    auxstr=escape(auxstr.substring(0, aux))+"="+escape(auxstr.substring(aux+1, auxstr.length))
    document.cookie=auxstr+expires
  }
}

function setexpires(when){
  var aux=new Date()
  aux.setTime(aux.getTime()+when*1000*60*60*24*365)
  expires="; expires="+aux.toGMTString()
  return aux
}

function savesettings(remember){
  if(remember){ myalert("Settings will expire on "+setexpires(1).toLocaleString()) }
  else{ setexpires(-1); updatecookies(); myalert("Settings will expire after leaving the page") }
  checkit()
}

var expires=""
setexpires(1)

var settings=new Array("n", "n", "n")
var openresults

function makeopen(){
  if((cookie=get_cookie("settings"))!=""){
    openresults=cookie.split(unescape(spaceChar))
    for(i=0,j=0;i<openresults.length;i++){
      if(!isNaN(openresults[i])) setfolding(openresults[i])
      else{ settings[j]=openresults[i]; j++ }
    }
    setTimeout("showopen()", 100)
  }
}

setTimeout("makeopen()", 500)

if(document.layers){
  document.captureEvents(Event.MOUSEUP)
  document.onmouseup=checkit4ns
}

function checkit4ns(e){
  routeEvent(e)
  setTimeout("checkit()", 100)
}

function checkit(){
  var openones=""
  openones=recdfolded()
  for(i=0;i<settings.length;i++) openones=openones+spaceChar+settings[i]
  if(openones.indexOf(spaceChar)==0) openones=openones.substring(spaceChar.length, openones.length)
  document.cookie="settings"+"="+openones+expires
  for(i=0;i<numicon;i++) document.cookie="picurl"+i+"="+dxicon[i]+spaceChar+dyicon[i]+spaceChar+zindex[i]+spaceChar+escape(icurl[i])+spaceChar+escape(hturl[i])+expires
  document.cookie="picurl"+i+"="+expires
  if(document.getElementById) xlist(); xreset(1)
  document.cookie="url="+selfname+expires
}

// playmidi functions

var midi=new Array("airwolf", "alladin", "animx", "avemar", "axelf", "back", "beetljuc", "bestfrd", "bijou", "blader", "bohem", "bond", "brekfast", "canoni", "cantina", "cheers", "crocket", "dasboot", "dieval", "dontt", "dunbar", "ewokprd", "exodus", "flight", "flintsto", "friends", "fuguei", "fureli", "gbusters", "gilligan", "goodoldl", "goodol", "gymnop", "happyn", "harlmnoc", "hawaii50", "in2001", "isawth", "jazz", "keepta", "killer_q", "killerqn", "killquee", "la", "lamou", "laputa", "liberty", "listen", "luckyl", "madein", "maplel", "materi", "michelle", "misimp", "money", "moonligh", "mrpost", "muppets", "mylife", "mysorgs", "neversay", "ov1812", "overtu", "peanuts", "playgame", "promen", "radioga", "ragtime", "rainman", "reggae", "revoluti", "scissorh", "simpsons", "sleepi", "slow", "starwar", "starwars", "strauss", "theent", "thesta", "tocatt", "trippygaia", "undersea", "vangels", "vivalidi", "wheelo", "wheni", "winter", "xfiles", "youdon")

var midl=new Array(69, 528, 69, 258, 149, 197, 113, 165, 204, 221, 324, 109, 264, 306, 115, 112, 127, 318, 75, 222, 213, 201, 132, 78, 86, 245, 376, 146, 245, 59, 170, 171, 134, 210, 243, 109, 75, 186, 131, 338, 207, 178, 185, 191, 149, 71, 122, 318, 171, 298, 144, 252, 140, 192, 192, 409, 181, 59, 195, 93, 193, 53, 282, 125, 196, 93, 346, 61, 120, 98, 126, 157, 86, 227, 228, 97, 142, 213, 225, 49, 477, 68, 193, 238, 198, 171, 154, 528, 44, 317)

var f=new Array()
var randomized=false
var countMidi=0

var winw=200
var winh=100
var st=0

var winmidi=null

function midiopen(){
  if(!winmidi || winmidi.closed){
    winmidi=window.open('', 'midi', 'width='+winw+',height='+winh)
    if(document.layers) if(winmidi.innerWidth!=winw || winmidi.innerHeight!=winh){
        winmidi=window.open('', 'midi', 'width='+(winw-10)+',height='+(winh+10))
	winmidi.resizeTo(winw, winh)
    }
  }
  playmidi=midi[i=nextMidi()]; duration=midl[i]+5; interval=Math.round((duration-0.5)/0.18)
  winmidi.document.write('<html><head><title>'+playmidi+' &lt;'+duration+' seconds&gt;</title><style> a{text-decoration:none} </style></head><body bgcolor="#000000" text="#00D044" link="#00D044" alink="#00D044" vlink="#00D044" onload="if(document.all) resizeBy('+winw+'-document.body.clientWidth, '+winh+'-document.body.clientHeight); else resizeBy('+winw+'-innerWidth, '+winh+'-innerHeight); str=\'if(opener && !opener.closed) if(opener.midiopenall) opener.midiopenall()\'; '+(document.layers?"":"call=new Function('try{ '+str+' }catch(e){ self.close() }'); str=\'call()\';")+' gof=new Function(\'history.forward(); setTimeout(str, 100)\'); setTimeout(\'gof()\', '+(duration*1000)+'); id=\'bar\'; d=(new Date()).getTime(); px=document.layers?\'\':\'px\'; id=document.layers?document.layers[id].clip:document.all?document.all[id].style:document.getElementById?document.getElementById(id).style:null; more=new Function(\'i=Math.round(((new Date()).getTime()-d)/'+interval+'); if(i>180) i=180; if(id) id.width=i+px; if(i>=180) clearInterval(v)\'); aux=\'more()\'; v=setInterval(aux, '+interval+'); if(!document.layers){ t1=\''+playmidi+' &lt;\'; t2=\'/'+duration+' seconds&gt;\'; time=new Function(\'t=Math.round(((new Date()).getTime()-d)/1000); if(t>'+duration+') t='+duration+'; document.title=t1+t+t2; if(t>='+duration+') clearInterval(r)\'); aux=\'time()\'; r=setInterval(aux, 1000) }">')
  winmidi.document.write((document.layers?'<layer width="180" height="10" top="85" left="10" bgcolor="gray"></layer><layer name="bar" clip="0,10" width="180" height="10" top="85" left="10" bgcolor="blue"></layer>':'<div style="position:absolute;width:180px;height:10px;top:85px;left:10px;background-color:gray"></div><div id="bar" style="position:absolute;width:0px;height:10px;top:85px;left:10px;background-color:blue"></div><div style="position:absolute;width:180px;height:5px;top:95px;left:10px;background-color:black"></div>')+'<center><font size=+3 style="font-size:24px">&nbsp;<br><nobr><b><a href="javascript:history.back()">&lt;-</a></b><a href="javascript:history.go(0)"> '+playmidi+' </a><b><a href="javascript:gof()">-&gt;</a></b></nobr><br></font></center><'+(document.all?'bgsound':'embed hidden="true" loop="false" autostart="true"')+' src="midi/'+playmidi+'.mid"></body></html>')
  winmidi.document.close()
}

midiopenall=document.layers?midiopen:new Function("do{ flag=false; try{ midiopen() }catch(e){ if(winmidi && !winmidi.closed) winmidi.close(); flag=true } }while(flag)")

function openmidi(){
  switch(st){
    case 0: st=1; document.layers?document.bgColor="darkblue":parent.moveBy(5,10); setTimeout("openmidi()", 100); break
    case 1: st=2; document.layers?document.bgColor="black":parent.moveBy(-5,-10); setTimeout("openmidi()", 100); break
    case 2: st=3; midiopenall(); setTimeout("openmidi()", 100); break
    default: st=0
  }
  return false
}

function randomizeMidi(){
  var max=midi.length
  var a=new Array()
  for(i=0;i<max;i++){
    num=Math.floor(Math.random()*(max-i))
    for(k=0;k<i;k++) if(num>=a[k]) num++
    f[i]=a[i]=num
    for(k=0;k<=i;k++) for(n=k+1;n<=i;n++) if(a[n]<a[k]){ aux=a[k]; a[k]=a[n]; a[n]=aux }
  }
  randomized=true
  myalert("Done randomizing midi")
}

function nextMidi(){
  if(randomized){
    aux=f[countMidi]
    countMidi++
    if(countMidi==midi.length) countMidi=0
    return aux
  }
  else return Math.floor(Math.random()*midi.length)
}

// load all pictures

var docw=document.all?document.body.clientWidth:innerWidth
var doch=document.all?document.body.clientHeight:innerHeight

function picfailed(picEl){
if(document.getElementById) return picEl.height==0
return picEl.height==0 || !picEl.complete
}

xflag=document.layers?false:true
xpres=xflag
var pics=new Array("fount", "gears", "gearh", "lamp", "spin", "world", "earthcool", "explorglobe", "ganimearth", "globecloudy", "odie", "madmouse", "musicnotes")
var xpics=pics.length
var over=new Array("grab", "homer")
var flat=new Array("mouse", "feet", "biplane")

if((cookie=get_cookie("xsets"))!=""){
  cookie=cookie.split(unescape(spaceChar))
  xflag=parseInt(cookie[0])>0?true:false
  xpics=parseInt(cookie[1])
  xpres=parseInt(cookie[2])>0?true:false
}

var mainpic="pics/"+pics[xpics<pics.length?xpics:firstVisit?5:Math.floor(Math.random()*pics.length)]+".gif"
var overpic="pics/"+over[firstVisit?1:Math.floor(Math.random()*over.length)]+".gif"
var flatpic="pics/"+flat[firstVisit?1:Math.floor(Math.random()*flat.length)]+".gif"

function putpic1(){
  if(pic1.onload!=null){ pic1.onload=null; setTimeout("putpic1()", 500) }
  else if(!picfailed(pic1)){
    pic1el=putElement(Math.floor((docw-pic1.width)/2), 30, pic1.width, pic1.height, "", "<img src="+pic1.src+" border=0>")
    setZindex(pic1el, 0)
  }
}

function putpic2(){
  if(pic2.onload!=null){ pic2.onload=null; setTimeout("putpic2()", 1000) }
  else if(!picfailed(pic2)){
    pic2el=putElement(Math.floor((docw-pic2.width)/2), 40, pic2.width, pic2.height, "", "<img src="+pic2.src+" border=0>")
    setZindex(pic2el, 0)
  }
}

function putpic3(){
  if(pic3.onload!=null){ pic3.onload=null; setTimeout("putpic3()", 1000) }
  else if(!picfailed(pic3)){
    pic3el=putElement(docw-(pic3.width+20), 10, pic3.width, pic3.height, "", "<img src="+pic3.src+" border=0>")
    setZindex(pic3el, 0)
  }
}

function putpic4(){
  if(pic4.onload!=null){ pic4.onload=null; setTimeout("putpic4()", 1200) }
  else if(!picfailed(pic4)){
    pic4el=putElement(Math.floor((docw-pic4.width)/2), doch-(pic4.height+20), pic4.width, pic4.height, "", "<img src="+pic4.src+" border=0>")
    setZindex(pic4el, maxZindex-4)
    simpson(settings[0]=="y"?true:false)
  }
}

function putpic5(){
  if(pic5.onload!=null){ pic5.onload=null; setTimeout("putpic5()", 2000) }
  else if(!picfailed(pic5)){
    pic5el=putElement(docw-(pic5.width+20), doch-(pic5.height+20), pic5.width, pic5.height, "", "<img src="+pic5.src+" border=0>")
    setZindex(pic5el, maxZindex-3)
    pirate(settings[1]=="y"?true:false)
  }
}

function putpic6(){
  if(pic6.onload!=null){ pic6.onload=null; setTimeout("putpic6()", 1000) }
  else if(!picfailed(pic6)){
    pic6el=putElement(Math.floor(docw-(pic6.width+20)), doch-(pic6.height+20), pic6.width, pic6.height, "", "<a href='../../' onClick='return openmidi()' onmouseover='moveElement(pic6el, 1, 2)' onmouseout='moveElement(pic6el, -1, -2)'><img src="+pic6.src+" border=0></a>")
    setZindex(pic6el, maxZindex-2)
  }
}

var pic1el=null; var pic1=new Image(); pic1.onload=putpic1; pic1.src=overpic
if(!firstVisit && Math.random()<0.1){ var pic2el=null; var pic2=new Image(); pic2.onload=putpic2; pic2.src=flatpic }
if(!firstVisit && Math.random()<0.1){ var pic3el=null; var pic3=new Image(); pic3.onload=putpic3; pic3.src="pics/ornament.gif" }
var pic4el=null; var pic4=new Image(); pic4.onload=putpic4; pic4.src="pics/simpson.gif"
var pic5el=null; var pic5=new Image(); pic5.onload=putpic5; pic5.src="pics/pirate.gif"
var pic6el=null; var pic6=new Image(); pic6.onload=putpic6; pic6.src=mainpic

function movepirate(){
  if(picfailed(pic5) || picfailed(pic6)) setTimeout("putpic5()", 1000)
  else moveElement(pic5el, -(pic6.width+20), 0)
}

setTimeout("movepirate()", 5000)

// simpson and pirate

var simpsonTimeout=600000
var pirateTimeout=1000000
var simpsE=false
var piratE=false
var simps
var pirat

function simpson(show){
  settings[0]=show?"y":"n"
  simpsE=!show
  clearTimeout(simps)
  if(!show) simps=setTimeout("simpson2()", simpsonTimeout)
  showElement(pic4el, show)
}

function pirate(show){
  settings[1]=show?"y":"n"
  piratE=!show
  clearTimeout(pirat)
  if(!show) pirat=setTimeout("pirate2()", pirateTimeout)
  showElement(pic5el, show)
}

function simpson2(){
  showElement(pic4el, true)
}

function pirate2(){
  showElement(pic5el, true)
}

function working(){
  if(simpsE){
    showElement(pic4el, false)
    clearTimeout(simps)
    simps=setTimeout("simpson2()", simpsonTimeout)
  }
  if(piratE){
    showElement(pic5el, false)
    clearTimeout(pirat)
    pirat=setTimeout("pirate2()", pirateTimeout)
  }
}

function setwakeup(wakeup){
  if(wakeup){
    if(document.layers) document.captureEvents(Event.MOUSEDOWN | Event.KEYDOWN)
    document.onmousedown=working
    document.onkeydown=working
    working()
  }
  else{
    clearTimeout(simps)
    clearTimeout(pirat)
    if(document.layers) document.releaseEvents(Event.MOUSEDOWN | Event.KEYDOWN)
    document.onmousedown=null
    document.onkeydown=null
  }
}

setwakeup(true)

// clock functions

var showtime=null
var holdtime=null

function startclock(){
  settings[2]="y"
  if(holdtime==null){
    if(showtime==null) showtime=newElement(docw-120, 50, 100, 30, "")
    showElement(showtime, true)
    runclock()
  }
}

function runclock(){
  var d=new Date()
  str=((aux=d.getHours())<10?"0"+aux:aux)+":"+((aux=d.getMinutes())<10?"0"+aux:aux)+":"+((aux=d.getSeconds())<10?"0"+aux:aux)
  str="<font size=+2 style='font-size:18px' color='orange'>"+str+"</font>"
  writeElement(showtime, str)
  holdtime=setTimeout("runclock()", 1000)
}

function stopclock(){
  settings[2]="n"
  if(holdtime!=null){
    clearTimeout(holdtime)
    holdtime=null
    showElement(showtime, false)
  }
}

function toggleclock(){
  if(holdtime==null) startclock()
  else stopclock()
}

setTimeout("if(settings[2]=='y') startclock()", 1000)

// add an icon

var dialog, dialog2
var dialogActive=false
var numicon=0
var newicon=new Array()
var picicon=new Array()
var hturl=new Array()
var icurl=new Array()
var allref=new Array()
var allstt=new Array()
var allicons=0
var dxicon=new Array()
var dyicon=new Array()
var zindex=new Array()

function addicon(){
  var icw=200
  var ich=150
  if(dialogActive) return; else dialogActive=true
  var html='<table border=2 width='+(icw-4)+' height='+(ich-4)+' cellpadding=0 cellspacing=0><tr><td valign=center align=center><form name="form" onSubmit="return addicon2()"><font size=+2 style="font-size:18px">Enter new url:</font><p><input type="text" size="20" maxlength="200" name="url"></form></td></tr></table>'
  dialog=putElement(Math.floor((docw-icw)/2), Math.floor((doch-ich)/2), icw, ich, "darkblue", html)
  setZindex(dialog, maxZindex-1)
  setTimeout("addiconfocus()", 100)
}

function getBody(el){
  if(document.layers) return el.document; else return document
}

function addiconfocus(){
  getBody(dialog).form.url.focus()
  getBody(dialog).form.url.onkeydown="if((event.which && event.which==13) || (event.keyCode && event.keyCode==13)){ getBody(dialog).form.submit(); return false }"
}

function addicon2(){
  var icw=250
  var ich=130
  hturl[numicon]=getBody(dialog).form.url.value
  dialog2=dialog
  getBody(dialog2).form.url.blur()
  writeElement(dialog2, "")
  var html='<table border=2 width='+(icw-4)+' height='+(ich-4)+' cellpadding=0 cellspacing=0><tr><td valign=center align=center><form name="form" onSubmit="return addicon3()"><font size=+2 style="font-size:18px">Url of the icon:</font><p><input type="text" size="20" maxlength="200" name="url"></form></td></tr></table>'
  dialog=putElement(Math.floor((docw-icw)/2), Math.floor((doch-ich)/2), icw, ich, "darkblue", html)
  setZindex(dialog, maxZindex-1)
  setTimeout("addiconfocus()", 100)
  return false
}

function addicon3(){
  var icw=250
  var ich=130
  icurl[numicon]=getBody(dialog).form.url.value
  getBody(dialog).form.url.blur()
  showElement(dialog, false)
  writeElement(dialog, "")
  setZindex(dialog, 0)
  showElement(dialog2, false)
  setZindex(dialog2, 0)
  if(icurl[numicon].length==0 || icurl[numicon]=="http://"){ myalert("Image url is not valid"); dialogActive=false }
  else{
    picicon[numicon]=new Image()
    picicon[numicon].onload=addicon4; picicon[numicon].onerror=adderror
    picicon[numicon].src=icurl[numicon]
  }
  return false
}

function addicon4(){
  if(picicon[numicon].onload!=null && loaded){ picicon[numicon].onload=null; setTimeout("addicon4()", 100) }
  else if(picfailed(picicon[numicon])){ myalert("Cannot get the image"); dialogActive=false }
  else{
    for(i=0,j=0;i<numicon;i++) j+=picicon[i].height
    var html=sethtml(allicons, numicon)
    if(loaded){ dxicon[numicon]=0; dyicon[numicon]=0 }
    newicon[numicon]=putElement(docw-picicon[numicon].width-20+dxicon[numicon], j+100+dyicon[numicon], picicon[numicon].width, picicon[numicon].height, "", html)
    allref[allicons]=numicon
    allstt[allicons]=false
    allicons++; numicon++
    if(loaded) addZindex(numicon-1)
    dialogActive=false
    if(document.layers) setTimeout("checkit()", 100)
  }
}

var numfailed=0

function adderror(){
  numfailed++
  if(loaded) myalert("Image not found"); dialogActive=false
}

function sethtml(allk, pick){
  return "<a href="+(document.layers?"javascript:location=":"")+"'"+((hturl[numicon].indexOf("javascript:")==0 || hturl[numicon].indexOf("mailto:")==0)?"../../":hturl[numicon])+"' onClick='return openlink(\""+hturl[numicon]+"\", "+allk+")' onmouseover='return elementDown("+allk+")' onmouseout='return elementUp("+allk+")' onmousedown='return elementOn("+allk+")' onmouseup='return elementOff()'><img src="+picicon[pick].src+" border=0></a>"
}

// get those cookies

function readallpics(){
  for(i=0;;i++){
    if((cookie=get_cookie("picurl"+i))!=""){
      cookie=cookie.split(unescape(spaceChar))
      dxicon[i]=(cookie.length>0?parseInt(cookie[0]):0)
      dyicon[i]=(cookie.length>1?parseInt(cookie[1]):0)
      zindex[i]=(cookie.length>2?parseInt(cookie[2]):0)
      icurl[i]=(cookie.length>3?cookie[3]:"")
      hturl[i]=(cookie.length>4?cookie[4]:"")
      picicon[i]=new Image()
      picicon[i].onerror=adderror
      picicon[i].src=icurl[i]
    }
    else{
      numicon=i; break
    }
  }
  setTimeout("loadallpics()", 1000)
}

var loaded=false
readallpics()

function loadallpics(){
  var numfailedhere=0
  for(i=0;i<numicon;i++) if(picfailed(picicon[i])) numfailedhere++
  if(numfailed<numfailedhere){ setTimeout("loadallpics()", 1000); return }
  var savenumicon=numicon
  for(i=0;i<savenumicon;i++){
    numicon=i; addicon4(); if(numicon==i){
      i--; savenumicon--
      for(j=i+1;j<savenumicon;j++){
        newicon[j]=newicon[j+1]
        picicon[j]=picicon[j+1]
        dxicon[j]=dxicon[j+1]
        dyicon[j]=dyicon[j+1]
        zindex[j]=zindex[j+1]
        icurl[j]=icurl[j+1]
        hturl[j]=hturl[j+1]
      }
    }
  }
  numicon=savenumicon
  resetZindex()
  loaded=true
}

var rZa=new Array()

function resetZindex(){
  for(i=0;i<numicon;i++) rZa[i]=zindex[i]
  for(i=0;i<numicon;i++) for(j=i+1;j<numicon;j++) if(rZa[j]<rZa[i]){ aux=rZa[j]; rZa[j]=rZa[i]; rZa[i]=aux }
  for(i=0;i<numicon;i++){ for(j=0;j<numicon;j++) if(rZa[j]==zindex[i]) break; zindex[i]=j+1 }
  for(i=0;i<numicon;i++) setZindex(newicon[i], zindex[i]+maxZindex)
}

function addZindex(j){
  zindex[j]=numicon+1; resetZindex()
}

// delete an icon

var noop=new Function("")

var prevmove=noop
var deleteon=false
var cursel=null; var curs=new Image(); curs.onload=putcurs; curs.src="pics/curs.gif"

function deleteicon(){
  deleteon=true
  if(document.layers) document.captureEvents(Event.MOUSEMOVE)
  if(prevmove==noop) prevmove=document.onmousemove
  document.onmousemove=movecurs
  showElement(cursel, true)
}

function donotdeleteicon(){
  if(!moveon){
    if(document.layers) document.releaseEvents(Event.MOUSEMOVE)
    if(document.onmousemove==movecurs) document.onmousemove=prevmove
  }
  showElement(cursel, false)
  deleteon=false
}

function putcurs(){
  if(curs.onload!=null){ curs.onload=null; setTimeout("putcurs()", 500) }
  else if(curs.height!=0){
    cursel=putElement(-curs.width, -curs.height, curs.width, curs.height, "", "<img src="+curs.src+" border=0>")
    setZindex(cursel, maxZdelt)
    showElement(cursel, false)
  }
}

// move an icon

function movecurs(e){
  if(moveon){ if(movetoggle) moveElementTo(moveref, (document.all?event.clientX+document.body.scrollLeft:e.pageX)-x_off, (document.all?event.clientY+document.body.scrollTop:e.pageY)-y_off) }
  if(deleteon) moveElementTo(cursel, (document.all?event.clientX+document.body.scrollLeft:e.pageX)-curs.width, (document.all?event.clientY+document.body.scrollTop:e.pageY)-curs.height)
  if(prevmove) prevmove(e)
  if(document.all) return false
}

var moveon=false
var movetoggle=false
var moveindex
var moveref
var movesrc

function moveicon(){
  moveon=true
  setwakeup(false)
  movetoggle=false
  if(document.layers) document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN)
  if(prevmove==noop) prevmove=document.onmousemove
  document.onmousemove=movecurs
  if(!document.all) document.onmousedown=setstate
}

function donotmoveicon(){
  if(document.layers) document.releaseEvents(Event.MOUSEDOWN)
  if(!document.all) document.onmousedown=null
  if(!deleteon){
    if(document.layers) document.releaseEvents(Event.MOUSEMOVE)
    if(document.onmousemove==movecurs) document.onmousemove=prevmove
  }
  movetoggle=false
  setwakeup(true)
  moveon=false
}

var x_off=0
var y_off=0
var dx_move=0
var dy_move=0

function setstate(e){
  routeEvent(e)
  if(movetoggle){
    dx_move=(document.layers?moveref.left:parseInt(moveref.style.left.substring(0, moveref.style.left.indexOf("px"))))
    dy_move=(document.layers?moveref.top:parseInt(moveref.style.top.substring(0, moveref.style.top.indexOf("px"))))
    x_off=e.pageX-dx_move
    y_off=e.pageY-dy_move
  }
}

function elementOn(ref){
  if(moveon){
    if(movetoggle) elementOff()
    else{
      if(allref[ref]!=-1){
        moveindex=allref[ref]
        moveref=newicon[moveindex]
        movesrc=picicon[moveindex]
        addZindex(moveindex)
        movetoggle=true
        if(document.all){
          dx_move=parseInt(moveref.style.left.substring(0, moveref.style.left.indexOf("px")))
          dy_move=parseInt(moveref.style.top.substring(0, moveref.style.top.indexOf("px")))
          x_off=event.clientX+document.body.scrollLeft-dx_move
          y_off=event.clientY+document.body.scrollTop-dy_move
        }
      }
    }
    return false
  }
  else return true
}

function elementOff(){
  if(moveon){
    if(movetoggle){
      dxicon[moveindex]+=(document.layers?moveref.left:parseInt(moveref.style.left.substring(0, moveref.style.left.indexOf("px"))))-dx_move
      dyicon[moveindex]+=(document.layers?moveref.top:parseInt(moveref.style.top.substring(0, moveref.style.top.indexOf("px"))))-dy_move
      movetoggle=false
    }
    return false
  }
  return true
}

// define xwindows

xcounter=0
xileft=20
xitop=50
xdleft=10
xdtop=20
xleft=xileft
xtop=xitop
xwidth=Math.floor(docw/1.2)
xheight=Math.floor(doch/1.5)

function xminimize(){
  this.onload=null
  this.minimize()
}

function mypopup(link, xleft, xtop, xwidth, xheight, show){
  var cid="x"+xcounter
  new popUp(xleft, xtop, xwidth, xheight, cid, link, "white", "#00385c", "16pt serif", link, "#00385c", "white", "lightgrey", "#00568c", "black", true, true, true, true, true, false)
  if(!show) if(document.getElementById){
    fr=document.getElementById(cid+"_ifrm"); fr.cid=cid; fr.minimize=minimize
    if(document.all) fr.minimize(); else{ fr.xminimize=xminimize; fr.onload=xminimize }
  }
  xcounter++
}

function xpopup(link, xwidth, xheight){
  mypopup(link, xleft, xtop, xwidth, xheight, true)
  xleft+=xdleft; if(xleft+xwidth+xdleft>docw) xleft=xileft
  xtop+=xdtop; if(xtop+xheight+xdtop>doch) xtop=xitop
}

function zpopup(link){
  xpopup(link, xwidth, xheight)
}

function opensite(){
  var icw=200
  var ich=150
  if(dialogActive) return; else dialogActive=true
  var html='<table border=2 width='+(icw-4)+' height='+(ich-4)+' cellpadding=0 cellspacing=0><tr><td valign=center align=center><form name="form" onSubmit="return opensite2()"><font size=+2 style="font-size:18px">Enter new url:</font><p><input type="text" size="20" maxlength="200" name="url"></form></td></tr></table>'
  dialog=putElement(Math.floor((docw-icw)/2), Math.floor((doch-ich)/2), icw, ich, "darkblue", html)
  setZindex(dialog, maxZindex-1)
  setTimeout("addiconfocus()", 100)
}

function opensite2(){
  var url=getBody(dialog).form.url.value
  getBody(dialog).form.url.blur()
  showElement(dialog, false)
  writeElement(dialog, "")
  setZindex(dialog, 0)
  dialogActive=false
  if(url.length==0 || url=="http://") myalert("No address specified"); else zpopup(url)
  return false
}

xcookie = new Array()
xzindex = new Array()

function xlist(){
  iaux=0
  for(i=0;i<xcounter;i++){
    dv=document.getElementById("x"+i+"_b").style
    if(dv.display!="none"){
      fr=document.getElementById("x"+i+"_ifrm")
      xcookie[iaux]=escape(fr.src)+
        spaceChar+dv.left.substring(0, dv.left.indexOf("px"))+
        spaceChar+dv.top.substring(0, dv.top.indexOf("px"))+
        spaceChar+dv.width.substring(0, dv.width.indexOf("px"))+
        spaceChar+document.getElementById("x"+i+"_max").h+
        spaceChar+(document.getElementById("x"+i+"_c").style.display=="none"?0:1)
      xzindex[iaux]=parseInt(dv.zIndex)
      iaux++
    }
  }
  for(k=0;k<iaux;k++) for(n=k+1;n<iaux;n++) if(xzindex[n]<xzindex[k]){
    aux=xzindex[k]; xzindex[k]=xzindex[n]; xzindex[n]=aux
    aux=xcookie[k]; xcookie[k]=xcookie[n]; xcookie[n]=aux
  }
  for(i=0;i<iaux;i++) document.cookie="winurl"+i+"="+xcookie[i]+expires
  document.cookie="winurl"+iaux+"="+expires
}

function readallwins(){
  for(i=0;;i++){
    if((cookie=get_cookie("winurl"+i))!=""){
      cookie=cookie.split(unescape(spaceChar))
      mypopup(cookie[0], parseInt(cookie[1]), parseInt(cookie[2]), parseInt(cookie[3]), parseInt(cookie[4]), parseInt(cookie[5])!=0)
    }
    else break
  }
}

setTimeout("readallwins()", 2000)

function showinds(){
  for(i=0;i<xcounter;i++){
    dv=document.getElementById("x"+i+"_b").style
    if(dv.display=="none"){
      fadeboxin("x"+i)
      break
    }
  }
}

function hidewins(){
  for(i=xcounter-1;i>=0;i--){
    dv=document.getElementById("x"+i+"_b").style
    if(dv.display!="none"){
      fadeboxout("x"+i)
      break
    }
  }
}

// hidden settings window

function xreset(i){
  switch(i){
    case 1: break
    case 2: mainpic="pics/"+pics[xpics<pics.length?xpics:firstVisit?4:Math.floor(Math.random()*pics.length)]+".gif"
            showElement(pic6el, false); moveElement(pic5el, (pic6.width+20), 0)
            pic6el=null; pic6=new Image(); pic6.onload=putpic6; pic6.src=mainpic
            setTimeout("movepirate()", 1000); break
    default:
  }
  if(document.getElementById) xpres=(document.getElementById("presets_b").style.display!="none"); else xpres=false
  document.cookie="xsets="+(xflag?1:0)+spaceChar+xpics+spaceChar+(xpres?1:0)+expires
}

function xsettings(){
  str1='<table><tr><td colspan="2" valign=center align=center>use iframes</td></tr><tr><td valign=center align=center><input type="radio" name="x1" onclick="xflag=true;xreset(1)"'+(xflag?' checked':'')+'></td><td valign=center align=center><input type="radio" name="x1" onclick="xflag=false;xreset(1)"'+(xflag?'':' checked')+'></td></tr><tr><td valign=center align=center>on</td><td valign=center align=center>off</td></tr></table>'
  str2='<table><tr><td valign=center align=center>midi icon</td></tr><tr><td valign=center align=center><select name="x2" onChange="xpics=selectedIndex;xreset(2)">'
  for(i=0;i<pics.length;i++) str2+='<option value="'+i+'"'+(xpics==i?' selected':'')+'>'+pics[i]
  str2+='<option value="'+i+'"'+(xpics>=i?' selected':'')+'>random</select></td></tr></table>'
  str='<table border=1><tr><td valign=center align=center>'+str1+'</td></tr><tr><td valign=center align=center>'+str2+'</td></tr></table>'
  xalert(str, 250, 250)
}

// icon action on click

function openlink(link, ref){
  if(moveon) ;
  else if(deleteon){
    var cur=allref[ref]
    allref[ref]=-1
    dy=picicon[cur].height
    showElement(newicon[cur], false)
    dxicon[cur]=0
    dyicon[cur]=0
    numicon--
    for(i=cur;i<numicon;i++){
      newicon[i]=newicon[i+1]
      picicon[i]=picicon[i+1]
      dxicon[i]=dxicon[i+1]
      dyicon[i]=dyicon[i+1]
      icurl[i]=icurl[i+1]
      hturl[i]=hturl[i+1]
      if(dxicon[i]==0 && dyicon[i]==0) moveElement(newicon[i], 0, -dy); else dyicon[i]+=dy
    }
    for(i=0;i<allicons;i++) if(allref[i]>cur) allref[i]=allref[i]-1
    resetZindex()
  }
  else if(link!=""){
    if(!xflag || link.indexOf("javascript:")==0 || link.indexOf("mailto:")==0) location=link
    else zpopup(link)
  }
  return false
}

function elementDown(ref){
  if(!moveon) if(allref[ref]!=-1) if(!allstt[ref]){ moveElement(newicon[allref[ref]], 1, 2); allstt[ref]=true }
  return true
}

function elementUp(ref){
  if(!moveon) if(allref[ref]!=-1) if(allstt[ref]){ moveElement(newicon[allref[ref]], -1, -2); allstt[ref]=false }
  return true
}

// reset icon positions

function iconsreset(){
  for(i=0;i<numicon;i++) if(dxicon[i]!=0 || dyicon[i]!=0){
    moveElement(newicon[i], -dxicon[i], -dyicon[i])
    dxicon[i]=0; dyicon[i]=0
  }
}

// apply themes

var winssh

function ssh(){
  sshw=200
  sshh=100
  if(document.layers) (window.open('', 'ssh', 'width='+(sshw-10)+',height='+(sshh+10))).resizeTo(sshw, sshh)
  winssh=window.open('', 'ssh', 'width='+sshw+',height='+sshh)
  winssh.document.write('<html><head><title>ssh</title><script> function init(){ if(document.all) resizeBy('+sshw+'-document.body.clientWidth, '+sshh+'-document.body.clientHeight); else resizeBy('+sshw+'-innerWidth, '+sshh+'-innerHeight) } onload=init </script></head><body bgcolor="#000000"><p></body></html>')
  winssh.document.close()
  setTimeout("loadssh()", 500)
}

function loadssh(){
  winssh.location.replace("../frontpage/ssh/ssh.html")
}

var wincal

function calculator(){
  if(document.layers){
    calw=250;
    calh=350;
    (window.open('', 'cal', 'width='+(calw-10)+',height='+(calh+10))).resizeTo(calw, calh)
    wincal=window.open('', 'cal', 'width='+calw+',height='+calh)
    wincal.document.write('<html><head><title>cal</title><script> function init(){ if(document.all) resizeBy('+calw+'-document.body.clientWidth, '+calh+'-document.body.clientHeight); else resizeBy('+calw+'-innerWidth, '+calh+'-innerHeight) } onload=init </script></head><body bgcolor="#000000"><p></body></html>')
    wincal.document.close()
    setTimeout("loadcal()", 500)
  }
  else{
    calw=270;
    calh=385;
    mypopup("games/calculator/jcalc98.html?bgcolor=408080", 50, (doch-calh)/2, calw, calh, true)
  }
}

function loadcal(){
  wincal.location.replace("games/calculator/jcalc98.html?bgcolor=408080")
}

function applytheme(theme){
  loaded=false
  numfailed=0
  for(i=0;i<numicon;i++) showElement(newicon[i], false)
  numicon=0
  allicons=0
  if(theme=="icons"){
    document.cookie="picurl0="+escape("0 0 1 themes/work.gif ../../work/")
    document.cookie="picurl1="+escape("0 0 2 themes/langs.gif ../dict/")
    document.cookie="picurl2="+escape("0 0 3 themes/photos.gif ../misc/pictures/misc/pictures/")
    document.cookie="picurl3="+escape("0 0 4 themes/clock.gif javascript:toggleclock()")
    document.cookie="picurl4="+escape("0 0 5 themes/music.gif javascript:randomizeMidi()")
    document.cookie="picurl5="+escape("0 0 6 themes/home.gif ../../")
    document.cookie="picurl6="+escape("0 0 7 themes/email.gif mailto:dima@icecube.wisc.edu")
    document.cookie="picurl7="+escape("0 0 8 themes/calculator.gif games/")
    document.cookie="picurl8="+escape("0 0 9 themes/ssh.gif javascript:ssh()")
    document.cookie="picurl9="
  }
  else if(theme=="flags"){
    document.cookie="picurl0="+escape("0 0 1 themes/ru.gif ../rus/")
    document.cookie="picurl1="+escape("-90 -10 2 themes/hand.gif ../multi/")
    document.cookie="picurl2="+escape("-35 45 7 themes/worm.gif ../misc/stories/bush.html")
    document.cookie="picurl3="+escape("-45 -35 4 themes/manwalkingleft.gif ../misc/")
    document.cookie="picurl4="+escape("-160 10 5 themes/faepipe.gif ../ic/")
    document.cookie="picurl5="+escape("-5 100 6 themes/calc98.gif javascript:calculator()")
    document.cookie="picurl6="+escape("-5 -100 3 themes/icecube.gif ../../work/BKP/DCS/LONDON05/co/jpg/icecube_eng.swf")
    document.cookie="picurl7="
  }
  else if(theme=="space"){
    document.cookie="picurl0="+escape("-40 10 1 themes/blinkstar.gif http://chandra.harvard.edu/")
    document.cookie="picurl1="+escape("-120 10 2 themes/earthmoon.jpg http://icecube.wisc.edu/")
    document.cookie="picurl2="+escape("-70 120 3 themes/majii.gif http://www.sno.phy.queensu.ca/")
    document.cookie="picurl3="+escape("-85 70 4 themes/manwalking.gif http://www.sno.phy.queensu.ca/sno/sno2.html")
    document.cookie="picurl4="+escape("-270 -220 5 themes/starship.gif http://www.shuttlepresskit.com/ISS_OVR/assembly2_overview.htm")
    document.cookie="picurl5="
  }
  else if(theme=="flame"){
    document.cookie="picurl0="+escape("-40 25 1 themes/molecule.gif http://icecube.berkeley.edu/manuscripts/")
    document.cookie="picurl1="+escape("-170 10 2 themes/nuclear.gif http://www.lib.berkeley.edu/PHYS/")
    document.cookie="picurl2="+escape("-145 -50 3 themes/burnflame.gif http://arxiv.org/")
    document.cookie="picurl3="+escape("-110 35 4 themes/msgadget.gif http://amanda.wisc.edu/Docs/")
    document.cookie="picurl4="
  }
  else if(theme=="cartn"){
    document.cookie="picurl0="+escape("0 0 1 themes/elbart.gif http://www.snpp.com/")
    document.cookie="picurl1="+escape("-200 -100 2 themes/homer.gif http://www.beavis-butthead.ru/")
    document.cookie="picurl2="+escape("-80 -50 3 themes/ghoul.gif http://www.mult.ru/")
    document.cookie="picurl3="
  }
  else if(theme=="birds"){
    document.cookie="picurl0="+escape("-190 211 4 themes/bluebird.gif ../rus/")
    document.cookie="picurl1="+escape("-154 -111 3 themes/blackbird.gif ../multi/")
    document.cookie="picurl2="+escape("7 -221 2 themes/bluebtrfly.gif ../misc/pictures/misc/pictures/")
    document.cookie="picurl3="+escape("-453 -556 1 themes/orangebtrfly.gif ../../work/MUONPR/")
    document.cookie="picurl4="
  }
  else if(theme=="clear"){
    document.cookie="picurl0="
  }
  else myalert("Unknown theme")
  readallpics()
  if(document.layers) setTimeout("checkit()", 100)
}

function openwindows(theme){
  if(document.getElementById) for(i=0;i<xcounter;i++) if(document.getElementById("x"+i+"_b").styledisplay!="none") hidebox("x"+i)
  if(theme=="news"){
    document.cookie="winurl0="+escape("http://www.pravda.ru/ 15 60 600 600 0")
    document.cookie="winurl1="+escape("http://news.yahoo.com/ 20 70 600 600 0")
    document.cookie="winurl2="+escape("http://www.lenta.ru/ 25 80 600 600 1")
    document.cookie="winurl3="
  }
  else if(theme=="search"){
    document.cookie="winurl0="+escape("http://groups.google.com/googlegroups/deja_announcement.html 15 60 600 600 0")
    document.cookie="winurl1="+escape("http://www.google.com/ 20 70 600 600 1")
    document.cookie="winurl2="+escape("http://www.yahoo.com/ 25 80 600 600 1")
    document.cookie="winurl3="
  }
  else if(theme=="clock"){
    document.cookie="winurl0="+escape("games/calculator/ 140 114 420 360 1")
    document.cookie="winurl1="+escape("games/calendar/ 5 415 410 260 1")
    document.cookie="winurl2="+escape("games/clock/ 365 510 270 140 1")
    document.cookie="winurl3="
  }
  else if(theme=="games"){
    document.cookie="winurl0="+escape("games/clock/ 365 510 270 140 1")
    document.cookie="winurl1="+escape("games/tictactoe/ 235 85 380 440 1")
    document.cookie="winurl2="+escape("games/minesweeper/ 5 300 390 350 1")
    if(document.all){
      document.cookie="winurl3="+escape("games/tetris/ 120 130 380 440 1")
      document.cookie="winurl4="+escape("games/jschess/ 140 160 330 380 1")
      document.cookie="winurl5="
    }
    else if(document.getElementById){
      document.cookie="winurl3="+escape("games/jschess/ 140 160 330 380 1")
      document.cookie="winurl4="
    }
    else if(document.layers){
      document.cookie="winurl3="+escape("games/tetris/ 120 130 380 440 1")
      document.cookie="winurl4="
    }
    else document.cookie="winurl3="
  }
  else if(theme=="none"){
    document.cookie="winurl0="
  }
  else myalert("Unknown choice")
  readallwins()
  if(document.layers) setTimeout("checkit()", 100)
}

// construct presets

function presets(i){
  switch(i){
    case 1: applytheme("icons"); openwindows("none")
            document.cookie="settings="+escape("0 2 5 6 n n y")+expires
            break
    case 2: applytheme("flags"); openwindows("news")
            document.cookie="settings="+escape("2 3 4 9 n n n")+expires
            break
    case 3: applytheme("clear"); openwindows("games")
            document.cookie="settings="+escape("7 9 n n n")+expires
            break
    default:
  }
  closeall(); makeopen()
  simpson(settings[0]=="y"); pirate(settings[1]=="y")
  setTimeout(settings[2]=="y"?"startclock()":"stopclock()", 1000)
}

prew=250
preh=250

new popUp(Math.floor((docw-prew)/2), Math.floor((doch-preh)/2), prew, preh, "presets", "<h3><center>Presets</center></h3>The following <i>presets</i> are available:<br><ul><li><a href='javascript:presets(1)'>standard</a></li><li><a href='javascript:presets(2)'>news</a></li><li><a href='javascript:presets(3)'>games</a></li></ul>To change your settings go to the system option of the menu above", "white", "#00385c", "16pt serif", "Presets", "#00385c", "white", "lightgrey", "#00568c", "black", true, true, true, false, false, false)
if(!xpres) hidebox("presets")

// Context menu Script continues

// set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar
var display_url=0

var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all
if(ie5||ns6) var menuobj=document.getElementById("ie5menu")

function showmenuie5(e){
  // Find out how close the mouse is to the corner of the window
  var rightedge=ie5?document.body.clientWidth-event.clientX:window.innerWidth-e.clientX
  var bottomedge=ie5?document.body.clientHeight-event.clientY:window.innerHeight-e.clientY

  // if the horizontal distance isn't enough to accommodate the width of the context menu
  // move the horizontal position of the menu to the left by it's width
  if(rightedge<menuobj.offsetWidth)
  menuobj.style.left=ie5?document.body.scrollLeft+event.clientX-menuobj.offsetWidth:window.pageXOffset+e.clientX-menuobj.offsetWidth
  // position the horizontal position of the menu where the mouse was clicked
  else menuobj.style.left=ie5?document.body.scrollLeft+event.clientX:window.pageXOffset+e.clientX

  // same concept with the vertical position
  if(bottomedge<menuobj.offsetHeight)
  menuobj.style.top=ie5?document.body.scrollTop+event.clientY-menuobj.offsetHeight:window.pageYOffset+e.clientY-menuobj.offsetHeight
  else menuobj.style.top=ie5?document.body.scrollTop+event.clientY:window.pageYOffset+e.clientY

  menuobj.style.visibility="visible"
  return false
}

function hidemenuie5(e){
  checkcontained(e)
  menuobj.style.visibility="hidden"
}

function highlightie5(e){
  var firingobj=ie5?event.srcElement:e.target
  if(firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
    if(ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode // up one node
    firingobj.style.backgroundColor="highlight"
    firingobj.style.color="white"
    if(display_url==1) window.status=event.srcElement.url
  }
}

function lowlightie5(e){
  var firingobj=ie5?event.srcElement:e.target
  if(firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
    if(ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode // up one node
    firingobj.style.backgroundColor=""
    firingobj.style.color="black"
    window.status=''
  }
}

function jumptoie5(e){
  var firingobj=ie5?event.srcElement:e.target
  if(firingobj.className=="menuitems"||ns6&&firingobj.parentNode.className=="menuitems"){
    if(ns6&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode
    if(firingobj.getAttribute("target"))
    window.open(firingobj.getAttribute("url"),firingobj.getAttribute("target"))
    else window.location=firingobj.getAttribute("url")
  }
}

function enablecontext(){
  if(ie5||ns6){
    menuobj.style.display=''
    document.oncontextmenu=showmenuie5
    document.onclick=hidemenuie5
  }
  else myalert("Not available in this browser")
}

function restorecontext(){
  document.oncontextmenu=null
  document.onclick=checkcontained
  menuobj.style.visibility="hidden"
}
