maxwait=80;
pics=new Array("mps/0.gif","mps/1.gif","mps/2.gif","mps/3.gif");
oldpredone=0,predone=0,preloaded=false,waitcount=0,precount=0;
document.preloadArray=new Array();

posx=new Array(86,190,148,132,140);
posy=new Array(255,94,255,34,150);
csheight=2,csx=0,csy=0,aimx=0,aimy=0;
ofcx=0,ofcy=0,aimnr=0;


function getObjects(){
	if (document.all) {
		objthinkimage = document.all.laymp.document.thinkimage;
		div_cs = document.all.laycs;
		div_shd = document.all.layshd;
		div_menu = document.all.laymenu;
	}
	else {
		objthinkimage = document.getElementsByName("thinkimage")[0];
		div_cs = document.getElementById("laycs");
		div_shd = document.getElementById("layshd");
		div_menu = document.getElementById("laymenu");
	}
}

function csinit(){
 	try{
 		getObjects();
	}
	catch(e){
		return;
	}
	
	objthinkimage.src="images/mps/loading.gif";
	for (var j=0; j<pics.length; j++){
      document.preloadArray[j] = new Image;  
      document.preloadArray[j].src ='images/'+pics[j];
      precount++;
     }
  preload();    
}


function preload(){
	predone=0;
	for (var i=0; i<precount; i++){
		if (document.preloadArray[i].complete==true) predone++;
	}

	//wenn weitere bilder geladen wurden, waitcount wieder auf 0
	if (predone !=oldpredone) {waitcount=0;oldpredone=predone}
	else waitcount++;
    
	if (predone<pics.length && waitcount<maxwait) setTimeout('preload()',25);
	else {
		preloaded=true;
		resize();
		cs_move();
	}
}

function resize(){
	if (!preloaded) return;
	ofcx = parseInt(div_menu.style.left);
	ofcy = parseInt(div_menu.style.top);
	cs_goto(aimnr);
}


function cs_goto(nr){
	if (!preloaded) return;
	aimnr=nr;
	if (aimnr==99){
		objthinkimage.src="images/mps/99.gif";
		aimx=document.body.offsetWidth/2-240;
		aimy=document.body.offsetHeight-75;
 	}
	else {
		objthinkimage.src="images/mps/"+nr+".gif";
		aimx=ofcx + posx[aimnr];
		aimy=ofcy + posy[aimnr];
	}
}


function cs_move(){
	addx=(aimx-csx)/5;
	addy=(aimy-csy)/8;
	csx+=addx;
	csy+=addy;
	
	csheight=(Math.abs(addx)+Math.abs(addy))/1.2;
	div_cs.style.left = csx-0.4*csheight;
	div_cs.style.top 	= csy-0.4*csheight;
	div_shd.style.left	= csx+csheight;
	div_shd.style.top 	= csy+csheight;
	
	setTimeout('cs_move()',25);
}
