function initRollovers() {
	var images=document.getElementById("fries").getElementsByTagName("img");
	for (var imageid in images) {
		var image=images[imageid];

		if (image && image.src && image.getAttribute("rollover",0)) {
			var cacheImage=new Image();
			cacheImage.src=image.src.replace(/\/normal/,"/over");
			image.onmouseout=function() {
				this.src=this.src.replace(/\/over/,"/normal");
			};
			image.onmouseover=function() {
				this.src=this.src.replace(/\/normal/,"/over");
			};
		}
	}
}

flashTargetWidth=0;
flashTargetHeight=0;
flashTargetX=0;
flashTargetY=0;
flashSteps=20;

var flashSpeedMS = 20;


var finishFlashOpen=false;
function openFlash() {

var fakeFlash=document.getElementById("fakeFlash");
	var pageCoords=getOffset('outerspace');
	flashTargetX=pageCoords.x;

var realFlash=document.getElementById("realFlash");
fakeFlash.style.display="none";
realFlash.style.display="";
	if (mapZoom) 		window.clearTimeout(mapZoom);

var flash=document.getElementById("flashkarte");
flash.style.zIndex=1002;
	flashTargetWidth=800;
	flashTargetHeight=500;
	flashTargetX=0;
	flashTargetY=0;

	setFlashStartValues();

	mapZoom=window.setTimeout(zoomMap,flashSpeedMS);
}

function setFlashStartValues() {
	var flash=document.getElementById("flashkarte");

	startFlashX = parseInt(flash.style.left);
	startFlashY = parseInt(flash.style.top);
	startFlashW = parseInt(flash.style.width);
	startFlashH = parseInt(flash.style.height);
	flashSteps = parseInt(Math.abs(startFlashW-flashTargetWidth)/20);
	flashActStep = flashSteps;
}

var finishFlashClose=false;

var flashPosition=[];
function initFlash() {
var flash=document.getElementById("flashkarte");

  flashPosition[0]=parseInt(flash.style.width);
  flashPosition[1]=parseInt(flash.style.height);
  flashPosition[2]=parseInt(flash.style.left);
  flashPosition[3]=parseInt(flash.style.top);
}

function closeFlash() {


	if (mapZoom) window.clearTimeout(mapZoom);

	flashTargetWidth=flashPosition[0];
	flashTargetHeight=flashPosition[1];
	flashTargetX=flashPosition[2];
	flashTargetY=flashPosition[3];

	setFlashStartValues();

 finishFlashClose=true;

	mapZoom=window.setTimeout(zoomMap,flashSpeedMS);
}

function finishClose() {
var flash=document.getElementById("flashkarte");
flash.style.zIndex= null;
finishFlashClose=false;

var fakeFlash=document.getElementById("fakeFlash");
var realFlash=document.getElementById("realFlash");
fakeFlash.style.display="";
realFlash.style.display="none";


}

var mapZoom=false;

function zoomMap() {
	var flash=document.getElementById("flashkarte");

	if (mapZoom) {
		window.clearTimeout(mapZoom);
		mapZoom=false;
	}


	if (flashActStep--) {
		var scale=flashActStep/flashSteps;
		var w=flashTargetWidth+parseInt((startFlashW-flashTargetWidth)*scale);
		var h=flashTargetHeight+parseInt((startFlashH-flashTargetHeight)*scale);
		var x=flashTargetX+parseInt((startFlashX-flashTargetX)*scale);
		var y=flashTargetY+parseInt((startFlashY-flashTargetY)*scale);

		flash.style.width=w+"px";
		flash.style.height=h+"px";
		flash.style.left=x+"px";
		flash.style.top=y+"px"; 
		
		mapZoom=window.setTimeout(zoomMap,50);

	} else {
		flash.style.width=flashTargetWidth+"px";
		flash.style.height=flashTargetHeight+"px";
		flash.style.left= flashTargetX+"px";
		flash.style.top= flashTargetY+"px"; 
if (finishFlashClose) finishClose();
if (finishFlashOpen) finishOpen();
	}


}

function initPage() {
  initRollovers();
  initFlash();
}

function getOffset(me) {
	me=document.getElementById(me);
		if (me) {
			var x = me.offsetLeft;
		   var y = me.offsetTop + me.offsetHeight ;

		   // deal with elements inside tables and such
		   var parent = me;
		   while (parent.offsetParent) {
		            parent = parent.offsetParent;
		            x += parent.offsetLeft;
		            y += parent.offsetTop ;
		   };
		};
		return {x: x, y: y};
}

window.onload=initPage;
