// Position des ganz linken Items.
var positionLeft = 0;

// Position des aktiven Items.
var itemPosition = 0;

// Itembreite in Pixeln.
var itemWidth = 55;

// Anzahl von Items die im Container angezeigt werden können.
var containerViewCount = 11;

// Anzahl der Items.
var itemCount = 0;

// Slideposition initialisieren.
function initSlide()
{
	// 1. Durch alle Items wandern und die Position des aktiven items ermitteln (rechtsbündig zum Sichtbereich).
	navItems = $$('.subnavigation-5 .container .items .navitem');

	// Anzahl der Arrayitems ermitteln.
	itemCount = navItems.size();

	// Slidebuttons ausblenden, wenn nicht geblättert werden kann.
	if (itemCount <= containerViewCount)
	{
		$$('.subnavigation-5 .slide-button').each(
				function (e)
				{
					e.hide();
				}
		)
	}
	
	positionLeft = 0;
	
	navItems.each(
		function (e, i)
		{
			if (e.hasClassName('active'))
			{
				itemPosition = i;
				
				// Position des aktiven Menüitems initialisieren.
				positionLeft = - itemPosition;
				
				// Items berechnen, die rechts im Sichtfeld fehlen.
				var itemsRightMissing = containerViewCount - (itemCount - itemPosition);
				
				// Wenn rechts mehr Items vorhanden sind, als in das Sichtfeld passen, fehlende Items auf 0 setzen.
				if (itemsRightMissing < 0)
				{
					itemsRightMissing = 0;
				}

				// Items berechnen die links außerhalb des Sichtfeldes verfügbar sind.
				var itemsLeftAvailable = itemPosition;
				
				// Itemposition um die Anzahl verfügbarer Items erhöhen.
				(itemsLeftAvailable >= itemsRightMissing) ? positionLeft += itemsRightMissing : positionLeft += itemsLeftAvailable;
				
				// Linksposition in Pixeln berechnen.
				var positionLeftPx = positionLeft * itemWidth;
				
				$('items').setStyle({marginLeft: positionLeftPx + "px" });
			}
		}
	);
}

// Linksslide ausführen.
function slideLeft()
{
	if (positionLeft > (- itemCount + containerViewCount))
	{
		positionLeft = positionLeft - 1;
	}
	
	$('items').setStyle({marginLeft: (positionLeft * itemWidth) + "px"});
}

// Rechtsslide ausführen.
function slideRight()
{
	if (positionLeft < 0)
	{
		positionLeft = positionLeft + 1;
	}
	
	$('items').setStyle({marginLeft: (positionLeft  * itemWidth) + "px"});
}
