/***********************************************************************************
Nikodemus Animation Script

Want more Infos? 
- for technical stuff write to jack@darkzone.org
- for graphics and design write to stephan@art.darkzone.org
***********************************************************************************/

var IMG_LOCATION	= "/templates/nikodemusallerley/img/anim/"		// The adress of the image directory
var IMG_NAME 		= "Nikodemus"						// The name of the image to animate (HTML)
var MIN_SLEEP 		= 5000;							// Minimum time to wait between animations
var MAX_SLEEP 		= 30000;						// Maximum time to wait between animations
var COUNT 		= 4;							// Number of animations

var ANIM = new Array();

ANIM["Name"] 	= new Array();
ANIM["Folder"] 	= new Array();
ANIM["Pics"] 	= new Array();
ANIM["Speed"] 	= new Array();

ANIM["Name"][0] 	= "Fuss tappen";					// Just the name of the Animation
ANIM["Folder"][0] 	= "fuss_tappen";					// The subfolder of the Animation
ANIM["Pics"][0] 	=  new Array("fuss_hoch.gif","fuss_unten.gif","fuss_hoch.gif","fuss_unten.gif","fuss_hoch.gif","fuss_unten.gif","fuss_hoch.gif","fuss_unten.gif","fuss_hoch.gif","fuss_unten.gif");
ANIM["Speed"][0]	= 200;						// The speed of the animation

ANIM["Name"][1] 	= "Hände reiben";
ANIM["Folder"][1] 	= "haende_reiben";
ANIM["Pics"][1] 	=  new Array("haendehinten_kopfnormal.gif","haendevorn_kopfgerade.gif","haendehinten_kopfgesenkt.gif","haendevorn_kopfgerade.gif","haendehinten_kopfnormal.gif","haendevorn_kopfnormal.gif","haendehinten_kopfnormal.gif","haendevorn_kopfnormal_augenlinks.gif","haendehinten_kopfnormal.gif","haendevorn_kopfnormal.gif");
ANIM["Speed"][1] 	= 300;

ANIM["Name"][2] 	= "Mantel öffnen";
ANIM["Folder"][2] 	= "mantel_oeffnen";
ANIM["Pics"][2] 	=  new Array("mantel1.gif","mantel2.gif","mantel3.gif","mantel4.gif","mantel5.gif","mantel6.gif","mantel6.gif","mantel6.gif","mantel6.gif","mantel5.gif","mantel4.gif","mantel3.gif","mantel1.gif");
ANIM["Speed"][2] 	= 200;

ANIM["Name"][3] 	= "Schauen";
ANIM["Folder"][3] 	= "schauen";
ANIM["Pics"][3] 	=  new Array("haendevorn_kopflinks_augenlinks.gif","haendevorn_kopfgerade.gif","haendevorn_kopfrechts.gif","haendevorn_kopfgerade.gif","haendevorn_kopflinks_augenlinks.gif");
ANIM["Speed"][3] 	= 300;

/***********************************************************************************
	END OF CONFIGURATION PART! DO NOT EDIT ANYTHING BELOW THIS LINE!!!
***********************************************************************************/

// First lets load all needed images
ANIM["Objects"] = new Array();
for(var key in ANIM["Name"]) {
	ANIM["Objects"][key] = new Array();
	for(var ptr in ANIM["Pics"][key]) {
		ANIM["Objects"][key][ptr] = new Image();
		ANIM["Objects"][key][ptr].src = IMG_LOCATION + ANIM["Folder"][key] + "/" + ANIM["Pics"][key][ptr];
	}
}
var IMAGE;
var IMAGE_SRC;
var Active=-1,Index,Animation;

// this function has to be placed into <body onload="">
function init_animation() {
	var allLoaded = true;

	//eval("IMAGE = document." + IMG_NAME + ";");
	IMAGE = document.getElementById('Nikodemus');
	IMAGE_SRC = IMAGE.src;

	for(var key in ANIM["Objects"]) {
        	for(var ptr in ANIM["Objects"][key]) {
                	allLoaded =  allLoaded && ANIM["Objects"][key][ptr].complete; 
        	}
	}

	if(!allLoaded) {
		window.setTimeout("init_animation()",1000);
	} else {
		start_animation(Math.round(Math.random() * (COUNT-1)));
	}
}

function start_animation(AnimNr) {
	if(Active > -1) {
		window.clearTimeout(Active);
		Active = -1;
	}
	Animation = AnimNr;
	Index = 0;
	play_animation();
}

function play_animation() {
	if(Index < ANIM["Objects"][Animation].length) {
		IMAGE.src = ANIM["Objects"][Animation][Index].src;
		Index++;
		Active = window.setTimeout("play_animation()",ANIM["Speed"][Animation]);
	} else {
		var newAnim = Math.round(Math.random() * (COUNT-1));
		while(newAnim == Animation) {
			newAnim = Math.round(Math.random() * (COUNT-1));
		}
		IMAGE.src = IMAGE_SRC;
		Active = window.setTimeout("start_animation(" + newAnim + ")", Math.round(Math.random() * (MAX_SLEEP - MIN_SLEEP)) + MIN_SLEEP);
	}
}

window.onload = init_animation();

