/* Ajax */
// <![CDATA[
var XMLHTTP = null;

if(window.XMLHttpRequest)
{
	XMLHTTP = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
	try
	{
		var XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(ex)
	{
		try
		{
			var XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");	
		}
		catch(ex)
		{
		}
	}
}
// ]]>

/*function Ausgabe()
{	
	if(!loading)
	{
		loading = true;
		divbox.innerHTML = '';
		divbox.style.backgroundImage = 'url(images/loading.gif)';
	}
	
	if(XMLHTTP.readyState == 4)
	{
		loading = false;
		divbox.style.backgroundImage = '';
		divbox.innerHTML = XMLHTTP.responseText;
		if(changelocation)
		{
			self.location.href=changelocation;
			scrolltotop();
		}
	}
}*/

var ajaxQueueArray = new Array();
var ajaxRunning = false;

function ajax_savePNavState (id, state)
{	
	ajaxQueue("action=pNavSaveState&itemId="+id+"&state="+state);
}

function ajaxQueue(sendString)
{
	if(sendString!=null)
	{
		ajaxQueueArray.push(sendString);
	}
	
	if(ajaxRunning == false && ajaxQueueArray.length>0)
	{		
		ajaxRunning = true;
		XMLHTTP.open("POST", "ajax.php");
		XMLHTTP.onreadystatechange = checkQueue;
		XMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		XMLHTTP.send(ajaxQueueArray[0]);
	}
}

function checkQueue()
{
	if(XMLHTTP.readyState == 4)
	{
		ajaxQueueArray.shift();
		ajaxRunning = false;
		ajaxQueue(null);
	}
}

/* Navigationssteuerung */
var pNavOpen = new Array();
var animationRunning = false;

function resetAnimation()
{
	animationRunning = false;
}

function pNavToggle(id, navId, expand, over, height, color)
{	
	if(over == null)
	{
		over = 1;	
	}
	
	if(animationRunning == true && over == 1)
	{
		return false;
	}
	
	animationRunning = true;
	setTimeout("resetAnimation()", 550);
	
	if(expand == 0 && pNavOpen[navId]>0 && pNavOpen[navId]!=id)
	{
		pNavToggle(pNavOpen[navId], navId, 1, 0, 1);
	}
	
	//new Effect.toggle('pNavBox_'+id, 'slide', { duration: .5 });
	
	if(document.getElementById('pNavItem_'+id).className == 'first pNavImgNormal' || document.getElementById('pNavItem_'+id).className == 'first pNavImgHover')
	{
		
		document.getElementById('pNavItem_'+id).className = 'first pNavImgActive';
		ajax_savePNavState(id, 1);
		pNavOpen[navId] = id;
		
		document.getElementById('pNavBox_'+id).style.height = '1px';
		document.getElementById('pNavBox_'+id).style.display = 'block';
		
		new Effect.Morph('pNavBox_'+id, { style: 'height: '+height+'px;', duration: .5 });
	}
	else
	{		
		if(over == 1)
		{
			document.getElementById('pNavItem_'+id).className = 'first pNavImgHover';
			if(color != 'def')
			{
				document.getElementById('pNavItem_'+id).style.backgroundColor = color;
			}
		}
		else
		{
			document.getElementById('pNavItem_'+id).className = 'first pNavImgNormal';
			if(color != 'def')
			{
				document.getElementById('pNavItem_'+id).style.backgroundColor = '#BBBBBB';
			}
		}
		ajax_savePNavState(id, 0);
		
		new Effect.Morph('pNavBox_'+id, { style: 'height: 1px;', duration: .5 });
		//new Effect.SlideUp('pNavBox_'+id);
	}
}

function pNavHoverOver(id,rgb) //IE6 und niedriger bietet kein Hover auf <li> Elemente
{
	if(document.getElementById('pNavItem_'+id).className == 'first pNavImgNormal')
	{
		document.getElementById('pNavItem_'+id).className = 'first pNavImgHover';
		
		if(rgb != 'def')
		{
			document.getElementById('pNavItem_'+id).style.backgroundColor = rgb;
		}
	}
	
}

function pNavHoverOut(id,rgb) //IE6 und niedriger bietet kein Hover auf <li> Elemente
{
	if (document.getElementById('pNavItem_'+id).className == 'first pNavImgHover')
	{
		document.getElementById('pNavItem_'+id).className = 'first pNavImgNormal';
		
		if(rgb != 'def')
		{
			document.getElementById('pNavItem_'+id).style.backgroundColor = '#BBBBBB';
		}
	}
}

function pNavInitOpened(openedString)
{
	var openedArray = openedString.split(';');
	var openedNaviArray;
	
	for(var i=0; i<openedArray.length; i++)
	{
		openedNaviArray = openedArray[i].split(',');
		pNavOpen[openedNaviArray[0]] = openedNaviArray[1];
	}
}