var isNav4, isNav6, isIE;
var coll = "";
var styleObj = "";
var preloadFlag = false;
var layFlag, currentLayer;

// browser detection
if (parseInt(navigator.appVersion) >= 4) {
	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) {
		isNav4 = true;
	} else {
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) > 4) {
			isNav6 = true;
			styleObj = ".style";
		} else { 
			isIE = true;
			coll = "all.";
			styleObj = ".style";
		}
	}	
}

function hideStatus() {
	window.status = '';
	return true;
}

// returns valid object reference
function getObject(obj) {
	var theObj;
	if (isNav4) {
		theObj = eval("document." + obj);
	} else {
		if (isNav6) {
			theObj = eval("document.getElementById(" + "\"" + obj + "\"" + ")" + styleObj);
		} else {
			theObj = eval("document." + coll + obj + styleObj);
		}
	}
	return theObj;
}

// show layer
function layerOn(obj) {
	var theObj = getObject(obj);
	theObj.visibility = "visible";
	window.status='';
}

// hide layer
function layerOff(obj) {
	var theObj = getObject(obj);
	theObj.visibility = "hidden";
	window.status='';
}

// positions layer
function shiftTo(obj, x, y) {
	if (isNav4) {
		var theObj = getObject(obj)
		theObj.moveTo(x, y)
	}
	if (isNav6) {
		var theObj = eval("document.getElementById(" + "\"" + obj + "\"" + ")" + styleObj)
		theObj.left = x
		theObj.top = y
	}
	if (isIE) {
		var theObj = getObject(obj)
		theObj.pixelLeft = x
		theObj.pixelTop = y
	}
}

// opens menus
function menuOn(ID) {
	layerOff('menuapre');
	layerOn('menuchiude');
	layerOn('menulayer');
	layerOn('menuvelina');
	goTop();
	var divs = document.getElementsByTagName("div");
		for (i=0; i < divs.length; i++) {
		if(divs[i].getAttribute("id") != ID) {
			if(divs[i].getAttribute("id") && divs[i].getAttribute("id").search("menusub")!= -1) divs[i].style.display = "none"
		} else {
		if (ID == null) {
			divs[i].style.display = "none"
		} else {
			divs[i].style.display = "block"
			}
		}
	}
}

// closes menus
function menuOff() {
	layerOn('menuapre');
	layerOff('menuchiude');
	layerOff('menulayer');
	layerOff('menuvelina');
}

// manages submenus
function mmenu(ID) {
	var divs = document.getElementsByTagName("div");
	for (i=0;i<divs.length;i++) {
		if(divs[i].getAttribute("id") != ID) {
		if(divs[i].getAttribute("id") && divs[i].getAttribute("id").search("menusub")!= -1) divs[i].style.display = "none";
		}
	}
	var menu = document.getElementById(ID);
	var display = menu.style.display;
	menu.style.display = (display == "block") ? "none" : "block";
}

// initialise menu
function initMenu() {
	var divs = document.getElementsByTagName("div");
	for (i=0;i<divs.length;i++) {
	if(divs[i].getAttribute("class")=="menusub")divs[i].style.display = "none";
	if(divs[i].getAttribute("id") && divs[i].getAttribute("id").search("menusub")!= -1) divs[i].style.display = "none";
	}
}

// image swap
function swap(num,imgname,message) {
	if (preloadFlag) {
		imgname.src = im[num].src;
		window.status = message;
	}
}

// manages menu layers
function popLayer(theLayer) {
	layerList = new Array ("menu0", "menu1", "menu2", "menu3", "menu4");
	for (var i = 0; i < layerList.length; i++) {
		if (i == theLayer) {
			layerOn(layerList[i]);
		} else {
			layerOff(layerList[i]);
		}
	}
}

// manages homemenu layers
function pophomeLayer(theLayer) {
	layerList = new Array ("laybirre", "laymicro", "layart", "laydove", "laygall");
	if ((layFlag == 1) && (currentLayer == theLayer)) {
		layerOff(theLayer);
		layFlag = 0;
		currentLayer = "";
	} else {
		for (var i = 0; i < layerList.length; i++) {
			if (layerList[i] == theLayer) {
				layerOn(layerList[i]);
			} else {
				layerOff(layerList[i]);
			}
		}
		layFlag = 1;
		currentLayer = theLayer;
	}
}

function preloadprod() {
	imag = new Array()
	imag[0] = "../../img/art_prod_malt.gif"
	imag[1] = "../../img/art_prod_malt_on.gif"
	imag[2] = "../../img/art_prod_prep.gif"
	imag[3] = "../../img/art_prod_prep_on.gif"
	imag[4] = "../../img/art_prod_filt.gif"
	imag[5] = "../../img/art_prod_filt_on.gif"
	imag[6] = "../../img/art_prod_cent.gif"
	imag[7] = "../../img/art_prod_cent_on.gif"
	imag[8] = "../../img/art_prod_raff.gif"
	imag[9] = "../../img/art_prod_raff_on.gif"
	imag[10] = "../../img/art_prod_ferm.gif"
	imag[11] = "../../img/art_prod_ferm_on.gif"
	imag[12] = "../../img/art_prod_matu.gif"
	imag[13] = "../../img/art_prod_matu_on.gif"
	imag[14] = "../../img/art_prod_bott.gif"
	imag[15] = "../../img/art_prod_bott_on.gif"
	imag[16] = "../../img/art_prod_intr.gif"
	imag[17] = "../../img/art_prod_intr_on.gif"
	
	im = new Array()
	for (var i = 0; i < imag.length; i++) {
		im[i] = new Image();
		im[i].src = imag[i];
	}
	preloadFlag = true;
}

var time = 0;
var duration = 10;
var begin;
var finish = 0;
var setScrollStart = true;
var scrll = "";

function goTop() {
	scrll = setTimeout("goTop()", 10);
	if (setScrollStart) {
		if (isNav4) {
			begin = top.pageYOffset;
		} else {
			if (isNav6) {
				begin = top.scrollY;
			} else {
				begin = top.document.body.scrollTop;
			}
		}
		setScrollStart = false;
	}
	// calculate the new position
	if (time < duration) {
		change = finish - begin;
		daScrollPos = scrollPos(time++, begin, change, duration);		
	} else {
		// call the function to end the scroll
		endScroll();
		daScrollPos = 0;
	}
	// scroll the page
	if (isNav4) {
		top.scrollTo(0, daScrollPos);
	} else {
		if (isNav6) {
			top.scrollTo(0, daScrollPos);
		} else {
			top.document.body.scrollTop = daScrollPos;
		}
	}
}

// ends the scroll and resets the variables to their starting positions
function endScroll() {
	clearTimeout(scrll);
	time = 0;
	setScrollStart = true;
}
// generates scroll coordinate
function scrollPos(t, b, c, d) {
	return -c*t*t/(d*d) + 2*c*t/d + b;
}

function openBioWin() {
	biowin=window.open("bio_kuaska.htm","bio","toolbar=0,status=0,directories=0,scrollbars=0,location=0,resizable=0 menubar=0,width=460,height=550")
}
function credOn() {
	win=window.open("0703/cred/credit.htm","credit","toolbar=0,status=0,directories=0,scrollbars=0,location=0,resizable=0 menubar=0,width=300,height=150")
}