// JavaScript Document

var stdWidth = 111;
var stdHeight = 50;

var wantedWidth = 144; /*222; */
var wantedHeight = 65; /*100; */

var HauptSchritteWidth = 2;
var HauptSchritteHeight = 1;

var MaxButtonNr = 9;


function angleichen(Zahl_1, Zahl_2, Schritt)
{
	var Zahl1 = parseInt(Zahl_1);
	var Zahl2 = parseInt(Zahl_2);
	if (Zahl1 < Zahl2)
	{
		if ( (Zahl1 + Schritt) > Zahl2 )
		{
			return (Zahl2);
		} else {
			return (Zahl1 + Schritt);
		}
	} else
	if (Zahl1 > Zahl2)
	{
		if ( (Zahl1 - Schritt) < Zahl2 )
		{
			return (Zahl2);
		} else {
			return (Zahl1 - Schritt);
		}
	} else {
		return (Zahl2);
	}
}


var MenuInfos = new Array();

function setMainMenuVars()
{

	for (i=1; i<=MaxButtonNr; i++)
	{
		
			var obj = new Object;
			//alert("Setting up "+obj+".");
				obj.wantedWidth = stdWidth;
				obj.wantedHeight = stdHeight;
				obj.currentWidth = stdWidth;
				obj.currentHeight = stdHeight;
			MenuInfos[i] = obj;
	}

}

function workMainMenu()
{
	//alert ("workMainMenu() started");
	for (i=1; i<=MaxButtonNr; i++)
	{
		workMainButton(i);
	}
}

function workMainButton(i)
{
	//alert ("starting work with id="+id);

		var obj = MenuInfos[i];
		if (obj.wantedWidth != obj.currentWidth)
		{
			var newWidth = angleichen(obj.currentWidth, obj.wantedWidth, HauptSchritteWidth);
			setObjWidth(i, newWidth);
		}
		if (obj.wantedHeight != obj.currentHeight)
		{
			var newHeight = angleichen(obj.currentHeight, obj.wantedHeight, HauptSchritteHeight);
			setObjHeight(i, newHeight);
		}
		centerObject(i);

}




function setObjWidth(i, newWidth)
{
	//alert ("setting "+id+" to width:"+newWidth);

		var obj = document.getElementById("ButtonId_"+i);
		var objInfo = MenuInfos[i];
		if (typeof (obj) == "object" )
		{
			obj.style.width = newWidth+"px";
			objInfo.currentWidth = newWidth;
			MenuInfos[i] = objInfo;
		} else {
			alert("set newWidth for i="+i+" not happened: typeof(obj)="+typeof(obj));
		}

}



function setObjHeight(i, newHeight)
{
	//alert ("setting "+id+" to height:"+newHeight);

		var obj = document.getElementById("ButtonId_"+i);
		var objInfo = MenuInfos[i];
		if (typeof (obj) == "object" )
		{
			obj.style.height = newHeight+"px";
			objInfo.currentHeight = newHeight;
			MenuInfos[i] = objInfo;
		} else {
			alert("set newHeight for id="+i+" not happened: typeof(obj)="+typeof(obj));
		}

}

function test1()
{
	var obj = document.getElementById("ButtonId_1_Div");
	alert(obj);
	obj.style.left="-10px";
}

function centerObject(i)
{
	if (document.getElementById)
	{
		var objDiv = document.getElementById("ButtonId_"+i+"_Div");
		var objImg = document.getElementById("ButtonId_"+i);
		if ( (typeof(objDiv) != "undefined") && (typeof(objImg) != "undefined" ) )
		{
			//alert (typeof(objImg));
			if (objImg.complete == true)
			{
				var objInfo = MenuInfos[i];
				var newLeft = (parseInt(objInfo.currentWidth) - stdWidth) / 2 * (-1);
				var newTop = (parseInt(objInfo.currentHeight) - stdHeight) / 2 * (-1);
				if (IE)
				{
					objDiv.style.setAttribute("left", newLeft+"px", true); // tut teilweise bei IE
					objDiv.style.setAttribute("top", newTop+"px", true); // tut teilweise bei IE		
				} else {
					objDiv.style.left = newLeft+"px"; // tut gut bei Firefox
					objDiv.style.top = newTop+"px"; // tut gut bei Firefox
				}
				if (i==1)
				{
					//alert ("centering id="+id+" x="+newLeft+" y="+newTop+"\ncurrentwidth="+obj.currentWidth+"\ncurrentHeight="+obj.currentHeight);
				}
			}
		}
	}
}

function MainMenuButtonOnMouseOver(i)
{
	//alert("mouseover started with id="+id);
	var obj = MenuInfos[i];
	obj.wantedHeight = wantedHeight;
	obj.wantedWidth = wantedWidth;
	MenuInfos[i] = obj;
}

function MainMenuButtonOnMouseOut(i)
{
	//alert("mouseout started with id="+id);
	var obj = MenuInfos[i];
	obj.wantedHeight = stdHeight;
	obj.wantedWidth = stdWidth;
	MenuInfos[i] = obj;
}

setMainMenuVars();

var MainMenuTimer;
function Load()
{
	MainMenuTimer = window.setInterval("workMainMenu()",20);
}






