maxWidth = new Array();
anzShow = new Array();
step = new Array();
lastPicInCont = new Array();

function setArtikelZahl( anz, slideId)
{
	anzShow[slideId] = anz;
	var anzArtikel = $(slideId + ' .list li').length;
	if ( anzArtikel <= anz)
	{
		lastPicInCont[slideId] = anzArtikel;
	}
	else
	{
		lastPicInCont[slideId] = anz;
	}
		
}

function setStep( stepno, slideId)
{
	step[slideId] = stepno;
}

function setSlideList(id)
{
	var anzArtikel = $(id + ' .list li').length;
	width = parseInt( $( $(id + ' li')[0]).width());
	marginLeft = 2*parseInt( $( $(id + ' li')[0]).css( 'margin-left'));
	borderWidth = 2*parseInt( $( $(id + ' li a')[0]).css( 'border-left-width'));
	maxWidth[id] = anzArtikel * ( width + marginLeft + borderWidth);
	
	extraWidth = 10;
	liWidth = maxWidth[id] + extraWidth;
	$(id + ' .list ul').css( "width", liWidth);
}

function setSlideBtns(id, anz)
{
	prevBtn = $( id + ' .prev a');
	nextBtn = $( id + ' .next a');
	prevBtn.unbind( 'click');
	nextBtn.unbind( 'click');

	var anzArtikel = $(id + ' .list li').length;

	if( anzArtikel <= anz )
	{
		//SlideBtns deaktivieren
		prevBtn.click(function(){ return false; });
		nextBtn.click(function(){ return false; });
		$( id + ' .prev').addClass( 'off');
		$( id + ' .next').addClass( 'off');
	}
	else
	{
		actLeft = $( id + ' .list ul').css( 'left');
		actLeft = ( actLeft == null || actLeft == 'auto') ? 0 : parseInt( actLeft);
		
		lastLeft = -(maxWidth[id] - ( anzShow[id] * (maxWidth[id] / anzArtikel))); 
		
		//alert('ACT: ' + actLeft + ' LAST: ' + lastLeft);
		
		if ( actLeft == 0)
		{
			prevBtn.click( function() { return false; } );
			nextBtn.click( function() { slide('next', id, this); return false; } );
			$( id + ' .prev').addClass( 'off');
			$( id + ' .next').removeClass( 'off');
		}
		else if ( actLeft <= lastLeft)
		{
			prevBtn.click( function() { slide('prev', id, this); return false; } );
			nextBtn.click( function() { return false; } );
			$( id + ' .prev').removeClass( 'off');
			$( id + ' .next').addClass( 'off');
		}
		else
		{
			prevBtn.click( function() { slide('prev', id, this); return false; } );
			nextBtn.click( function() { slide('next', id, this); return false; } );
			$( id + ' .prev').removeClass( 'off');
			$( id + ' .next').removeClass( 'off');
		}
		
	}
	
}

function slide(direction, slideId, btn)
{
	$( slideId + ' .prev a').unbind( 'click').click( function() { return false;});
	$( slideId + ' .next a').unbind( 'click').click( function() { return false;});
	list = $( slideId + ' ul');
	borderWidth = 2*parseInt( $( $(slideId + ' li a')[0]).css( 'border-left-width'));
	//moveVal = ( $( $(slideId + ' li')[0]).width() + borderWidth ) * step[slideId];
	moveVal = ( $( $(slideId + ' li')[0]).width() ) * step[slideId];
	//alert( $( $(slideId + ' li')[0]).width() );
	oldLeft = list.css( 'left');
	oldLeft = (oldLeft == null || oldLeft == 'auto') ? 0 : parseInt( oldLeft);
	if( direction == "next")
	{
		newLeft = oldLeft - moveVal;
		newLeft -= (2 * parseFloat( $( $(slideId + ' li')[0]).css( 'margin-left'))) * step[slideId];
		lastPicInCont[slideId] += step[slideId];
	}
	else
	{
		newLeft = oldLeft + moveVal;
		newLeft += (2 * parseFloat( $( $(slideId + ' li')[0]).css( 'margin-left'))) * step[slideId];
		lastPicInCont[slideId] -= step[slideId];
	}
	//alert( newLeft);
	list.animate( {left: (newLeft+"px")}, 1500, function(){ setSlideBtns( slideId); } );
}

function setSlider( anz, id, stepno)
{
	if ($(id).length)
	{
		//alert($(id).width());
		setArtikelZahl( anz, id);
		setStep( stepno, id);
		setSlideList( id);
		setSlideBtns( id, anz);		
	}
}

