var openedBloc = false;
var openingCache = false;
var swappingArticle = false;
var lastBloc = null;
var wantedBloc = null;

function articleFadinCheck(x, y, whichlayer) {
	setColor(whichlayer, "#FFFFFF");
	if ((wantedBloc != null) && (wantedBloc != whichlayer)) {
		setTimeout("articlFadout("+x+","+y+",'"+whichlayer+"','"+wantedBloc+"');", 60);
		wantedBloc = null;
	} else {
		swappingArticle = false;
		wantedBloc = null;
	}
}

function articlFadin(x, y, whichlayer) {
	setColor(whichlayer, "#333333");
	showLayer(whichlayer, x, y);	
	setTimeout("setColor('"+whichlayer+"', '#666666');", 60);
	setTimeout("setColor('"+whichlayer+"', '#999999');", 120);
	setTimeout("setColor('"+whichlayer+"', '#CCCCCC');", 180);
	setTimeout("articleFadinCheck("+x+","+y+",'"+whichlayer+"');", 240);
}

function articleFadoutCheck(x, y, whichlayer1, whichlayer2) {
	setVisibility(whichlayer1, 'hidden');
	if ((wantedBloc != null) && (wantedBloc != whichlayer2)) {
		whichlayer2 = wantedBloc;
		wantedBloc = null;
	}
	lastBloc = whichlayer2;
	setTimeout("articlFadin("+x+","+y+",'"+whichlayer2+"');", 60);
}

function articlFadout(x, y, whichlayer1, whichlayer2) {
	swappingArticle = true;
	setColor(whichlayer1, "#CCCCCC");
	setTimeout("setColor('"+whichlayer1+"', '#999999');", 60);
	setTimeout("setColor('"+whichlayer1+"', '#666666');", 120);
	setTimeout("setColor('"+whichlayer1+"', '#333333');", 180);
	setTimeout("articleFadoutCheck("+x+","+y+",'"+whichlayer1+"','"+whichlayer2+"');", 240);
}

function blocFadin(id, x, y, whichLayer) {
	if (id == 1) {
		if (openedBloc == false) {
			openingCache = true;
			openedBloc = true;
			showLayer('cache18', x+1, y+1);
			setColor(whichLayer, "#333333");
			showLayer(whichLayer, x, y);
			id++;
			setTimeout("blocFadin("+id+","+x+","+y+",'"+whichLayer+"');", 60);
		} else {
			articlFadout(x, y, lastBloc, whichLayer);
		}
	} else if (id == 2) {
		setVisibility('cache18', 'hidden');
		showLayer('cache26', x+1, y+1);
		setColor(whichLayer, "#666666");
		id++;
		setTimeout("blocFadin("+id+","+x+","+y+",'"+whichLayer+"');", 60);
	} else if (id == 3)	{
		setVisibility('cache26', 'hidden');
		showLayer('cache34', x+1, y+1);
		setColor(whichLayer, "#999999");
		id++;
		setTimeout("blocFadin("+id+","+x+","+y+",'"+whichLayer+"');", 60);
	} else if (id == 4)	{
		setVisibility('cache34', 'hidden');
		showLayer('cache42', x+1, y+1);
		setColor(whichLayer, "#CCCCCC");
		id++;
		setTimeout("blocFadin("+id+","+x+","+y+",'"+whichLayer+"');", 60);
	} else {
		setVisibility('cache42', 'hidden');
		showLayer('cache50', x+1, y+1);
		setColor(whichLayer, "#FFFFFF");
		openingCache = false;
	}
}


function blocFadout(id, x, y) {
	if (id == 1) {
		if (openedBloc == true) {
			swappingArticle = true;
			openedBloc = false;
			setVisibility('cache50', 'hidden');
			showLayer('cache42', x+1, y+1);
			setColor(lastBloc, "#CCCCCC");
			id++;
			setTimeout("blocFadout("+id+","+x+","+y+");", 60);
		}
	} else if (id == 2) {
		setVisibility('cache42', 'hidden');
		showLayer('cache34', x+1, y+1);
		setColor(lastBloc, "#999999");
		id++;
		setTimeout("blocFadout("+id+","+x+","+y+");", 60);
	} else if (id == 3) {
		setVisibility('cache34', 'hidden');
		showLayer('cache26', x+1, y+1);
		setColor(lastBloc, "#666666");
		id++;
		setTimeout("blocFadout("+id+","+x+","+y+");", 60);
	} else if (id == 4) {
		setVisibility('cache26', 'hidden');
		showLayer('cache18', x+1, y+1);
		setColor(lastBloc, "#333333");
		id++;
		setTimeout("blocFadout("+id+","+x+","+y+");", 60);
	} else {
		setVisibility('cache18', 'hidden');
		setVisibility(lastBloc, 'hidden');
		lastBloc = null;
		swappingArticle = false;
	}
}

/*---------------------------------------------------------------------------*/

function showPagin(whichlayer, width, height, myWidth, myHeight) {
	if ((width >= myWidth) && (height >= myHeight)) {
		top.parent.PageHtmlName.setTextWidth();
		return ;
	}
	if ((width < myWidth) && (height < myHeight)) {
		width += 15;
		height += 15;
	} else if (width < myWidth) {
		width += 15;
	} else {
		height += 15;
	}
	if (width > myWidth) width = myWidth;
	if (height > myHeight) height = myHeight;
	setWidth(whichlayer, width);
	setHeight(whichlayer, height);
	setWidth('PageHtmlId', width);
	setHeight('PageHtmlId', height);
	setTimeout("showPagin('"+whichlayer+"',"+width+","+height+","+myWidth+","+myHeight+");", 5);
}


function showPagout(whichlayer, width, height, myWidth, myHeight) {
	if ((width <= myWidth) && (height <= myHeight)) {
		setVisibility(whichlayer, 'hidden');
	} else {
		if ((width > myWidth) && (height > myHeight)) {
			width -= 15;
			height -= 15;
		} else if (width > myWidth) {
			width -= 15;
		} else {
			height -= 15;
		}
		if (width < myWidth) width = myWidth;
		if (height < myHeight) height = myHeight;
		setWidth(whichlayer, width);
		setHeight(whichlayer, height);
		setWidth('PageHtmlId', width);
		setHeight('PageHtmlId', height);
		setTimeout("showPagout('"+whichlayer+"',"+width+","+height+","+myWidth+","+myHeight+");", 5);
	}
}

/*---------------------------------------------------------------------------*/

function openBloc(element, whichLayer, arrow) {
	var coord = getPageCoordinates(element);
	if (arrow != null) showLayer(arrow, coord.x - 14, coord.y + 2);
	if (openingCache == true) return ;
	if (lastBloc == whichLayer) return ;
	if (swappingArticle == true) {
		wantedBloc = whichLayer;
		return ;
	}
	var coord = getCoord('bloc-rightt');
	blocFadin(1, coord.x, coord.y, whichLayer);
	lastBloc = whichLayer;
}

function closeBloc(whichLayer) {
	setVisibility(whichLayer, 'hidden');
}

function closeAllBloc(cache) {
	if (openingCache == true) return ;
	if (swappingArticle == true) return ;
	if (cache != null) {
		wantedBloc = null;
		var coord = getCoord('bloc-rightt');
		blocFadout(1, coord.x, coord.y);
	}
}

function showPage(url) {
	var size = getWindowSize();
	setWidth('pagehtml', 5);
	setHeight('pagehtml', 5);
	showLayer('pagehtml', 25, 25);
	showPagin('pagehtml', 5, 5, size.w - 50, size.h - 50);
	showLayer('pageClose');
	if (url != null) frames['PageHtmlName'].location.href = url;
}

function closePage() {
	var size = getWindowSize();
	showPagout('pagehtml', size.w - 50, size.h - 50, 5, 5);
	setVisibility('pageClose', 'hidden');
}

function closeIn() {
	setBgimg('pageClose', "url('images/close_o.gif')");
	setCursor('pageClose', 'pointer');
}

function closeOut() {
	setBgimg('pageClose', "url('images/close.gif')");
	setCursor('pageClose', 'default');
}

function openAudio(file) {
	window.location.href = file;
}

function openNewPage(url) {
	window.open(url);
}

function animArrowin(id) {
	if ((id == 1) || (id == 5)) {
		document.images.arrow2b.src = 'images/arrow-link1.gif';
		document.images.arrow1b.src = 'images/arrow-link2.gif';
		document.images.arrow0b.src = 'images/arrow-link1.gif';
		id++;
		setTimeout("animArrowin("+id+");", 60);
	} else if ((id == 2) || (id == 6)) {
		document.images.arrow2b.src = 'images/arrow-link.gif';
		document.images.arrow1b.src = 'images/arrow-link1.gif';
		document.images.arrow0b.src = 'images/arrow-link2.gif';
		id++;
		setTimeout("animArrowin("+id+");", 60);
	} else if ((id == 3) || (id == 7)) {
		document.images.arrow2b.src = 'images/arrow-link1.gif';
		document.images.arrow1b.src = 'images/arrow-link.gif';
		document.images.arrow0b.src = 'images/arrow-link1.gif';
		id++;
		setTimeout("animArrowin("+id+");", 60);
	} else if ((id == 4) || (id == 8)) {
		document.images.arrow2b.src = 'images/arrow-link2.gif';
		document.images.arrow1b.src = 'images/arrow-link1.gif';
		document.images.arrow0b.src = 'images/arrow-link.gif';
		id++;
		setTimeout("animArrowin("+id+");", 60);
	}
}


function loader() {
	var winSize = getWindowSize();
	var lx = winSize.w / 2 - 380;
	var ly = winSize.h / 2 - 210;
	setCoord('loader', lx, ly);
	setTimeout("setColor('loader-text', '#BBBBBB');", 60);
	setTimeout("setColor('loader-text', '#888888');", 120);
	setTimeout("setColor('loader-text', '#555555');", 180);
	setTimeout("setVisibility('loader-text', 'hidden');", 240);
	setVisibility('loader', 'visible');
	setTimeout("setBgimg('loader', \"url('images/bg2.gif')\");", 60);
	setTimeout("setBgimg('loader', \"url('images/bg.gif')\");", 120);
	setTimeout("setBgimg('loader', \"url('images/bg0.gif')\");", 180);
	setTimeout("setBgimg('loader', \"url('images/bgz.gif')\");", 240);
	setTimeout("setVisibility('bloc', 'visible');", 241);
	setTimeout("setBgimg('loader', \"url('images/bg0.gif')\");", 300);
	setTimeout("setBgimg('loader', \"url('images/bg.gif')\");", 360);
	setTimeout("setBgimg('loader', \"url('images/bg2.gif')\");", 420);
	setTimeout("setVisibility('loader', 'hidden');", 421);
}


function init() {
	MM_preloadImages('images/bg0.gif', 'images/bg2.gif', 'images/bg.gif', 'images/bgz.gif', 'images/neuron_50.jpg','images/neuron_42.jpg','images/neuron_34.jpg','images/neuron_26.jpg','images/neuron_18.jpg', 'images/close_o.gif')
	var coord = getCoord('loader');
	setCoord('bloc', coord.x, coord.y);
	var coord = getCoord('bloc-rightt');
	var x = coord.x;
	var y = coord.y;
	setCoord('cache18', x, y);
	setCoord('cache26', x, y);
	setCoord('cache34', x, y);
	setCoord('cache42', x, y);
	setCoord('cache50', x, y);
	setCoord('bloc-cmptr', x, y);
	setCoord('bloc-cmpt', x, y);
	setCoord('bloc-news', x, y);
	setCoord('bloc-neurotech', x, y);
	setCoord('bloc-text2speech', x, y);
	setCoord('bloc-evalexp', x, y);
	setCoord('bloc-houghcircle', x, y);
	setCoord('bloc-fah', x, y);
	setCoord('bloc-contact', x, y);
	setCoord('bloc-me', x, y);
	setCoord('bloc-ditesle', x, y);
	setTimeout("loader();", 1000);
}
