

headTimer=200;
bookTimer=50;
onDuty=0;
fadeOutCurr=1;


elements = new Array (	"September 1913 (1914)", 
						"The lake of Innisfree (1893)", 
						"Sailing to Byzantium (1928)",
						"Easter 1916 (1921)", 
						"An Irish Airman Foresees His Death (1919)",
						"The Song of Wandering Aengus (1899)");
	
informations = new Array;
informations['Eng'] = new Array("William Butler Yeats Chronology. An overview of his life", 
							"Enter the library and discover some of the most famous Yeats' poems",
							"Informations regarding this website, contact details and weblinks",
							"Click on the picture to see full view",
							"About this website..., our contact details...",
							"Links to external websites regarding Yeats");

informations['Fr'] = new Array("La chronologie, un aperçu de la vie de W.B. Yeats", 
							"Entrez dans la bibliothèque et découvrez ses plus célèbres poèmes",
							"Informations concernant ce site web, pour nous contacter et liens",
							"Cliquez sur l'image pour agrandir",
							"A propos de ce site web..., pour nous contacter...",
							"Nos liens vers d'autres sites concernant Yeats");							

bulleBackDisplayed=false;

function informationLinkDispo(disp, item){
	if (disp==true){
		document.getElementById("bottomInformationId").innerHTML=informations[document.getElementById("langId").value][item];
		document.getElementById("bottomInformationId").style.visibility='visible';		
	} else{
		document.getElementById("bottomInformationId").style.visibility='hidden';
	}
}

function libraryDispTitle(disp, item){	
	if (disp==true ){						
		document.getElementById("bottomInformationId").style.visibility='visible';
		document.getElementById("bottomInformationId").innerHTML=elements[item];
	}else{		
		document.getElementById("bottomInformationId").style.visibility='hidden';
	}
}


currentInformationDispItem='cadreId';

function informationDisp(disp, item){
	if (disp==true ){
		if (document.getElementById("cadreId").style.visibility=='visible')
			informationDisp(false, 0);	
		document.getElementById("cadreId").style.visibility='visible';
		document.getElementById(item).style.visibility='visible';
		currentInformationDispItem=item;
	}else{		
		document.getElementById("cadreId").style.visibility='hidden';
		document.getElementById(currentInformationDispItem).style.visibility='hidden';
	}
}

currentItem=0;

function libraryDispInfo(disp, item){		
	if (disp==true){		
		
		if (document.getElementById("poeme" + currentItem + "Id").style.visibility=='visible')
			libraryDispInfo(false, 0);
			
		libraryDispTitle(false, currentItem);
		
		document.getElementById("bulleId").style.top=0;
		document.getElementById("bulleBackId").style.visibility='visible';
		document.getElementById("poemeImage" + item + "Id").style.visibility='visible';
		document.getElementById("bulleMenuId").style.visibility='visible';
		document.getElementById("poeme" + item + "Id").style.visibility='visible';
		currentItem=item;
		bulleBackDisplayed=true;
	}else{	
		yPos=0;
		document.getElementById("poeme" + currentItem + "Id").style.visibility='hidden';
		document.getElementById("poemeImage" + currentItem + "Id").style.visibility='hidden';		
		document.getElementById("bulleMenuId").style.visibility='hidden';
		document.getElementById("bulleBackId").style.visibility='hidden';
		bulleBackDisplayed=false;
	}
}

function flickHead(){
	if (document.getElementById("head1Id").style.visibility=='visible'){		
		document.getElementById("head1Id").style.visibility='hidden';
		document.getElementById("head2Id").style.visibility='visible';		
	}else{		
		document.getElementById("head1Id").style.visibility='visible';
		document.getElementById("head2Id").style.visibility='hidden';	
	}
	if (!onDuty)
		timerHead=setTimeout('flickHead()',headTimer);	
	else {
		document.getElementById("head1Id").style.visibility='visible';
		document.getElementById("head2Id").style.visibility='hidden';
	}
}

function rotateHead(rotate){
	if (rotate==true){		
		timerHead=setTimeout('flickHead()',headTimer);		
	}else{
		document.getElementById("head1Id").style.visibility='visible';
		document.getElementById("head2Id").style.visibility='hidden';
		clearTimeout(timerHead);
	}	
}


var opacity=1 
var increase=false;
var decrease=true; 	
var keepFading=false;

function fadeElement(div){
	if (opacity<=1 && increase) opacity+=0.1;
	else{
		increase=false;
		decrease=true;
		if (!keepFading)
			clearTimeOut(timerFadeBook);
	}

	if (opacity>0.2 && decrease && keepFading) opacity-=0.1;
	else{
		increase=true;
		decrease=false;
	}

	document.getElementById(div).style.MozOpacity=opacity;
	document.getElementById(div).style.filter="alpha(opacity="+opacity*100+")";
	if (keepFading || increase) timerFadeBook=setTimeout("fadeElement('" + div + "')", bookTimer);	
}

function initFade(div, fading){
		
	if (fadeOutCurr==1 && fading && !keepFading){		
		 keepFading=true;
		 timerFadeBook=setTimeout("fadeElement('" + div +"')",bookTimer);	
	}else{
		keepFading=false;
		increase=true;
		decrease=false; 	
	}
}

function animStar(starId){
	document.getElementById(starId).style.left=320+Math.floor(Math.random()*80);
	document.getElementById(starId).style.top=130+Math.floor(Math.random()*60);
	document.getElementById(starId).style.opacity=0.2+Math.random()*0.4;	
	document.getElementById(starId).style.filter="alpha(opacity=" + (0.2+Math.random()*0.4 * 100) + ")";			
}

function changeDivSet(divSet, action, actionValue){
	var Div = new Array();
	switch (divSet){
	case 'mainElements': Div = ["mainId"]; break; //["bookId", "head1Id", "bodyId", "aboutMyLifeId", "myWorkId", "mainIntroId"]; break;	
    case 'chronologyElements': Div = ["chronologyId","chronologyMenuId", "chronologyTitleId"]; break;
	case 'myWorkElements': Div= ["workId","workMenuId","workTitleId"]; break;
	case 'informationElements': Div= ["informationTitleId","informationMenuId"]; break;	
	}

	for(i=0; i< Div.length; i++){
		switch (action){
		case 'visibility': document.getElementById(Div[i]).style.visibility=actionValue; break;
		case 'opacity': 
			document.getElementById(Div[i]).style.MozOpacity=actionValue; 
			document.getElementById(Div[i]).style.filter="alpha(opacity="+actionValue*100+")";
		break;
		}
	}
}

step = 0.08;

function fadeIn(divSet){
	fadeOutCurr+=step;
	if (fadeOutCurr<1){
		changeDivSet(divSet,'visibility','visible');
		changeDivSet(divSet,'opacity', fadeOutCurr);		
	}

	if (fadeOutCurr>=1){
		clearInterval(timerfade);
		onDuty=0;
		fadeOutCurr=1;
	}
}

function fadeOut(divSet1, divSet2){	
	fadeOutCurr-=step;
	changeDivSet(divSet1,'opacity', fadeOutCurr);
	
	if (fadeOutCurr<=0) {
		clearInterval(timerfade);
		changeDivSet(divSet1,'visibility','hidden');		
		timerfade=setInterval("fadeIn('" + divSet2 + "');", 10);		
	}
}


function rollUpLustre(direction, speed) {
	if	(direction==true) {
		with (document.getElementById("lustreId").style) {
			top = parseInt(top) - speed;
			if (parseInt(top) > -20) rollUpLustreTimer=setTimeout("rollUpLustre(true, " + speed + ")" , 20);
		}
	}else{
		 with (document.getElementById("lustreId").style) {
			top = parseInt(top) + speed;
			if (parseInt(top) < 90) rollUpLustreTimer=setTimeout("rollUpLustre(false, " + speed + ")" , 20);
		}
	}
	return 0;
}

function callSpecial(divSet1, divSet2){
	switch (divSet1){
		case 'mainElements':
			rollUpLustre(true, 10);
			break;
	}
	
	switch (divSet2){
		case 'mainElements':
			rollUpLustre(false, 10);
			break;
		case 'myWorkElements':
			libraryDispInfo(false, 0);
			
			break;
		case 'chronologyElements':
			document.getElementById("chronoContentId").style.left=0;
			xPos=0;
			break;
		case 'informationElements':
			informationDisp(false, 0);
			break;
	}
}

function hideShow(divSet1, divSet2){	
	libraryDispTitle(false, 0);
	if (onDuty==0){		
	    if(rollUpLustreTimer) clearTimeout(rollUpLustreTimer);
		callSpecial(divSet1, divSet2);
		timerfade=setInterval("fadeOut('" + divSet1 + "','" + divSet2 + "');",20);
		onDuty=1;
	}
}

xPos=0;
function scroll(direction){
	if (direction=="left" && xPos!=-2400){
		xPos-=50;
	}else if (xPos<=-50)xPos+=50;

	document.getElementById("chronoContentId").style.left=xPos;
	timerScroll=setTimeout("scroll('" + direction + "')",200);
}

function stopScrolling(){
	clearTimeout(timerScroll);
}

function imgChrono(element, show){
	if (show==true){
		document.getElementById(element).style.opacity=1;
		document.getElementById(element).style.filter="alpha(opacity="+1*100+")";
	}else{
		document.getElementById(element).style.opacity=0.2;
		document.getElementById(element).style.filter="alpha(opacity="+0.2*100+")";
	}
}


var spd=50;
var obj;

function mov(p) {
	with(obj[p].style) {
		y = parseInt(top) / 1.2;
		top = 50 + y;
		if(y<0)window.setTimeout("mov("+p+")",16);
		else top=10;
	}
}

function dropText() {
	T = document.getElementById("hash").innerHTML.split(" ");
	for(i=0;i<T.length;i++){
		o=document.createElement("span");
		document.getElementById("workId").appendChild(o);				
		o.innerHTML=T[i]+" ";
		o.style.top=-document.getElementById("workId").offsetHeight*2;
		window.setTimeout("mov("+i+")",1000+i*spd);
	}
	obj=document.getElementsByTagName("span");
}

yPos=0;

function scrollTexte(direction){
	if (direction=="down" && yPos!=-1000){
		yPos-=10;
	}else if (yPos!=0)yPos+=10;

	document.getElementById("bulleId").style.top=yPos;
	timerScroll=setTimeout("scrollTexte('" + direction + "')",100);
}

xNuages=0;

function scrollNuages(direction){
	if (direction=='left' && xNuages>=-1300)
		xNuages-=2;
	else 
		xNuages+=2;
		
	document.getElementById("nuagesId").style.left=xNuages;
	if (xNuages<=-1300) direction='right';
	if (xNuages>=0) direction='left';
	
	nuagesScroll=setTimeout("scrollNuages('" + direction + "')",100);
}

onload=function(){
	rollUpLustre(false, 5);
	scrollNuages('left');	
}
