function getElement(id) { //get element 
if (document.getElementById) {
element = document.getElementById(id);
return element;
}
if (document.all) {
element = document.all[id];
return element;
}
if (document.layers) {
element = document.layers[id];
return element;
}
if (document[id]) {
element = document[id];
return element;
}
return false;
}

function eventHandler(e) { //get event
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
}

function getBrowser() { //get browser
var browserName = navigator.appName;
var browserLongVer = navigator.appVersion;
var browserVer = browserLongVer.substring(0,1);
if (((browserName == "Microsoft Internet Explorer") && (browserVer >= 4)) || ((browserName == "Netscape") && (browserVer >= 5)) || ((browserName == "Opera") && (browserVer >= 5))) {
return true;
}
else {
return false;
}
}

function getScroll() { // get window scroll
var scrOfX = 0, scrOfY = 0;
if (typeof(window.pageYOffset) == 'number') {//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} 
else if (document.body && (document.body.scrollLeft || document.body.scrollTop )) {//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
} 
else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop )) {//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}
return [scrOfX, scrOfY];
}

function getWinSize() { //get window size
var winWidth = 0, winHeight = 0;
if (typeof(window.innerWidth) == 'number') {//Non-IE
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} 
else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight )) {//IE 6+ in 'standards compliant mode'
winWidth = document.documentElement.clientWidth;
winHeight = document.documentElement.clientHeight;
} 
else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {//IE 4 compatible
winWidth = document.body.clientWidth;
winHeight = document.body.clientHeight;
}
return [winWidth, winHeight];
}

var topics = new Array('home','about', 'astro', 'hist', 'liter', 'soc',  'rock', 'links', 'map', 'write'); // all the main topics
var noPx = document.childNodes ? 'px' : 0;

function showMenu(obj, posobj) { // show the menu
if (getElement(obj) && getBrowser()) {
var object = getElement(obj); // the menu item to show
var offx = -2; // offset menu items im x direction
var offy = -7; // offset menu items in y direction
var i = 0;
for (i=0; i<=topics.length-1; i++) {
if (posobj == topics[i]) { // if the parent item menu is a main item then change the offset in x direction
offx = 100; // length of the image of a main menu item
offy = 0; // the offset in y-direction 
}
}
object.style.visibility='visible';
var a = getPos(posobj); // get position of the parent item
object.style.left = parseInt(a[0]+offx)+noPx; // derive the position of the left side
object.style.top = parseInt(a[1]+offy)+noPx; // derive the position of the top side
}
else { // the browser does not match
return false;
}
}

function hideMenu(obj) { // hide menu item
if (getElement(obj) && getBrowser()) {
var object = getElement(obj);
object.style.visibility='hidden';
}
else {
return false;
}
}

function getPos(obj)
{
var posobject = getElement(obj);
var xoff;
var yoff;
if (posobject.offsetParent) { // DOM compatible
for (xoff=0, yoff=0; posobject.offsetParent; posobject = posobject.offsetParent) {
xoff += posobject.offsetLeft;
yoff += posobject.offsetTop;
}
return [xoff, yoff];
} 
else { // Netscape compatible
return [oLink.x, oLink.y];
}
}

//colors
var viol = 'f900fc';
var green = '27ff73';
var blue = '3333ff';
var lgreen = '46ea7a';

function chColorOver(obj) { // change an item color when the mouse over
if (getElement(obj) && getBrowser()) {
var objtr = obj+'tr'; // the name of the triangle
var coloverobject = getElement(obj);
var colovertrobject = getElement(objtr);
coloverobject.style.color=viol;
coloverobject.style.background=green;
coloverobject.style.backgroundColor=green;
coloverobject.style.bgColor=green;
colovertrobject.style.color=viol;
colovertrobject.style.background=green;
colovertrobject.style.backgroundColor=green;
colovertrobject.style.bgColor=green;
}
else {
return false;
}
}

function chColorOut(obj) { // change an item color when the mouse out
if (getElement(obj) && getBrowser()) {
var objtr = obj+'tr';
var coloutobject = getElement(obj);
var colouttrobject = getElement(objtr);
coloutobject.style.color=blue;
coloutobject.style.background=lgreen;
coloutobject.style.backgroundColor=lgreen;
coloutobject.style.bgColor=lgreen;
colouttrobject.style.color=blue;
colouttrobject.style.background=lgreen;
colouttrobject.style.backgroundColor=lgreen;
colouttrobject.style.bgColor=lgreen;
}
else {
return false;
}
}

var offmenux = 38; // offset menu from the top of window (the heigth of the site menu image+some offset)
var offmenuy = 3; // offset menu from the left side of window (the senter the image)
function showSiteMenu() { // show site menu 
var object1 = getElement('smenu');
if (object1.style.position == 'absolute') {
var object2 = getElement('sitemenu');
object2.style.position = 'absolute';
var a = getScroll();
object2.style.top = parseInt(a[1]+offmenux)+noPx;
object2.style.left = parseInt(offmenuy)+noPx;
return object2.style.position;
}
}

var menuheight = 520; // to define when the menu is out of the browser window
function makeStatic() {
sm = new Image();
sm1 = new Image();
sm.src = "pictures/images/sitemenu.gif";
sm1.src = "pictures/images/sitemenu1.gif";
var object1 = getElement('smenu');
var object2 = getElement('sitemenu');
var a = getScroll();
var b = getPos('sitemenu');
var c = getPos('smenu');
var diffpos = Math.abs(b[1]-c[1]); // the difference between the picture and site menu
var delta = 7; // the clearance allowed not to hide the menu
var diffpos1 = Math.abs(diffpos-offmenux);
if (diffpos1 > delta) {
object2.style.position = 'static';
}
if (a[1] > menuheight) {
object1.style.position = 'absolute';
object1.style.top = parseInt(((a[1]-c[1])/2)+c[1])+noPx;
object1.style.left = parseInt(offmenuy)+noPx;
if (object2.style.position == 'static') { // changing the image source to show the picture with or without a cursor
document.images['imgsm'].src = sm1.src;
}
}
else {
object1.style.position = 'static';
object2.style.position = 'static';
document.images['imgsm'].src = sm.src;
}
if (getBrowser()) {
tid = window.setTimeout("makeStatic()", 100);
}
}
