var menuItemTr = new Array();
var menuItemTaTr= new Array();
for (i=0;i<6;i++) menuItemTr[i] = 0;
for (i=0;i<6;i++) menuItemTaTr[i] = 0;

var  imageOpacity = Array();

function setOpacity(element,opacity)
{
	if (opacity>1) opacity = 1;
	if (opacity<0) opacity = 0;
	element.style.opacity = opacity;
	element.style.filter = "alpha(opacity="+(opacity*100)+")";
}

function gebi(id)
{
	return document.getElementById(id);
}

function modifyAJAXState(variable,value)
{
	
	variable = variable + "";
	value = value + "";
	variable = variable.replace("%","%37").replace(" ","%20").replace("?","%63").replace("&","%38").replace("#","%23")
	value = value.replace("%","%37").replace(" ","%20").replace("?","%63").replace("&","%38").replace("#","%23")
	
	hash = location.hash.replace("?","&");
	writeDebug("[h] Changing ajax state: "+variable+" to "+value);
	if (hash.indexOf("&"+variable+"=")!=-1)
	{
		writeDebug("[h] AJAX variable already present");
		start = hash.indexOf("&"+variable+"=")+1;
		end = hash.indexOf("&",start);
		if (end==-1) end = hash.length;
		newHash = hash.substring(0,start)+variable+"="+value+hash.substring(end);
	}
	else if (hash.length > 2)
	{
		writeDebug("[h] AJAX variable not already present");
		newHash = hash + "&" + variable+"="+value;
	}
	else
	{
		writeDebug("[h] No AJAX variables not already present");
		newHash = "#/?" + variable+"="+value;
	}
	
	newHash = newHash.replace("#/&","#/?");
	
	location.hash = newHash;
	
}

function getAJAXVariable(variable)
{
	
	variable = variable + "";
	variable = variable.replace("%","%37").replace(" ","%20").replace("?","%63").replace("&","%38").replace("#","%23")
	
	hash = location.hash.replace("?","&");
	writeDebug("[h] Geting ajax variable: "+variable);
	if (hash.indexOf("&"+variable+"=")!=-1)
	{
		writeDebug("[h] AJAX variable present");
		start = hash.indexOf("&"+variable+"=")+variable.length+2;
		end = hash.indexOf("&",start);
		if (end==-1) end = hash.length;
		return hash.substring(start,end);
	}
	else
	{
		writeDebug("[h] AJAX variable not present");
		return false;
	}
	
}

function fadeInImage(ID)
{
	var element = document.getElementById(ID);
	if (!imageOpacity[ID]) imageOpacity[ID] = 0;
	element.style.visibility = "visible";
	if (imageOpacity[ID]<1) imageOpacity[ID] += 0.1;
	if (imageOpacity[ID]>1) imageOpacity[ID] = 1;
	element.style.opacity = imageOpacity[ID];
	element.style.filter = "alpha(opacity=" + (imageOpacity[ID]*100) + ")";
	if (imageOpacity[ID]<1) setTimeout("fadeInImage('"+ID+"')",50);
	else if (fadingInCurrentImage)
	{
	 	fadingInCurrentImage = false;
	 	currentImageOpacity = 1;
 	}
}

function expandMenuItem(item)
{
	menuItemTaTr[item] = 100;
}

function contractMenuItem(item)
{
	menuItemTaTr[item] = 0;
}

function menuLoop()
{
	
	for (i=0;i<6;i++)
	{
		if (menuItemTr[i] != menuItemTaTr[i]) 
		{
			menuItemTr[i] += Math.ceil((menuItemTaTr[i]-menuItemTr[i])/8);
			if (Math.abs(menuItemTr[i]-menuItemTaTr[i])<8) menuItemTr[i]=menuItemTaTr[i];
			document.getElementById("menu_item_back_"+i).style.visibility = "visible";
			document.getElementById("menu_item_back_"+i).style.width = (menuItemTr[i]+50)+"px";
			document.getElementById("menu_item_back_"+i).style.left = ((100-menuItemTr[i])/2)+"px";
			document.getElementById("menu_item_back_"+i).style.opacity = (menuItemTr[i]/200);
			document.getElementById("menu_item_back_"+i).style.filter = "alpha(opacity=" + (menuItemTr[i]/2) + ")";
		}
	}
	
	setTimeout("menuLoop()",10);
	
}
