var menuWidth = 138;
var maxwidth = 965;
var maxalpha = 100;
var minalpha = 100;
var startLeft = 0;
var doTimer = 0;
var stap = 0;
var stapen = 20;
var active = false;
var hactive = false;
var ttOn = new Array();
var newLeft = 0;
var ajax = new sack();

function showMenu(where) {
	if(play) {
		if(hactive !== false) {
			//h = document.getElementById("img" + hactive);
			//h.style.opacity = 0;
			//h.style.filter = "alpha(opacity=0)";
			hactive = false;
		}
		o = document.getElementById("img" + where);
		
		o.style.display = "block";
		o.style.width = menuWidth + "px";
		o.style.marginLeft = (menuWidth * where) + "px";
		o.style.backgroundPosition = " -" + (menuWidth * where) + "px top";
		
		if(undefined == o.style.opacity) {
			o.style.opacity = 0;
			o.style.filter = "alpha(opacity=0)";
		}
		
		clearTimeout(ttOn[where]);
		ttOn[where] = setTimeout("fade(" + where + ", 1)", 39);
		
		hactive = where;
	}
}
function hideMenu(where) {
	if(play) {
		clearTimeout(ttOn[where]);
		ttOn[where] = setTimeout("fade(" + where + ", 0)", 39);
	}
}
function fade(where, what) {
	o = document.getElementById("img" + where);
	
	malpha = parseInt(o.style.opacity * 100);
	
	if(what) {
		malpha = malpha + 15;
	} else {
		malpha = malpha - 5;
	}
	
	
	malpha = malpha < 0 ? 0 : malpha;
	malpha = malpha > minalpha ? minalpha : malpha;
	
	o.style.opacity = (malpha / 100);
	o.style.filter = "alpha(opacity=" + malpha + ")";
	
	if(malpha < minalpha && malpha > 0) {
		ttOn[where] = setTimeout("fade(" + where + ", " + what + ")", 39);
	}
}
function clickMenu(where) {
	if(play) {
		startLeft = (menuWidth * where);
		if(active !== false) {
			document.getElementById("menu_" + active).className = "";
		}
		active = where;
		doTimer = setInterval("playMovie(" + where + ")", 50);
		document.getElementById("menu_" + where).className = "active";
		play = false;
	}
	return false;
}
function playMovie(where) {
	stap = stap + 1;
	
	overimg = document.getElementById("img" + where);
	
	malpha = Math.ceil(100 - ((100 - minalpha) / stap));
	
	overimg.style.opacity = (malpha / 100);
	overimg.style.filter = "alpha(opacity=" + malpha + ")";
	
	w = (maxwidth - menuWidth);
	t = ((w / stapen) * stap);
	dw = Math.ceil(menuWidth + t);
	overimg.style.width = dw + "px";
	
	newLeft = Math.floor(startLeft - ((startLeft / stapen) * stap));
	if((dw + newLeft) > maxwidth) {
		newLeft = maxwidth - dw;
	}
	overimg.style.marginLeft = (newLeft) + "px";
	overimg.style.backgroundPosition = " -" + (newLeft) + "px top";
	
	if(stap >= stapen) {
		clearInterval(doTimer);
		document.getElementById("mainimg").style.backgroundImage = overimg.style.backgroundImage;
		//mainimg.src = "gfx/head" + active + ".jpg";
		stap = 0;
		
		ajax.requestFile = document.getElementById("menu_" + where).href + "&xml=1";
		ajax.onCompletion = parsePage;
		ajax.runAJAX();
		play = true;
	}
}
function parsePage() {
	
	document.getElementById("text").innerHTML = ajax.response;
}

var overimg = false;
var mainimg = false;
var play = false;
window.onload = function() {
	overimg = document.getElementById("overimg");
	mainimg = document.getElementById("mainimg");
	play = true;
}

function debug(txt) {
	document.getElementById("debug").innerHTML = txt;
}
var imagecount = 0, imagearr = new Array();
function hideImages() {
	imgs = document.getElementById("images");
	lin = imgs.getElementsByTagName("A");
	imagecount = lin.length;
	for(i=0;i<imagecount;i++) {
		lin[i].style.opacity = 0;
		lin[i].style.filter = "alpha(opacity=0)";
		imagearr[i] = "image" + i;
		
	}
	setTimeout("imageFade()", 100);
}
var activeIm = 0;
var activeImage = false;
function imageFade() {
	if(!activeImage) {
		activeImage = document.getElementById(imagearr[activeIm]);
	}
	o = parseInt(activeImage.style.opacity * 100);
	o = o + 10;
	activeImage.style.opacity = o / 100;
	activeImage.style.filter = "alpha(opacity=" + o + ")";
	if(o >= 100) {
		activeIm++;
		if(imagearr[activeIm]) {
			activeImage = false;
		} else {
			return;
		}
	}
	setTimeout("imageFade()", 50);
}