/*

Teaser Slider by elements.at
Author: Elements

*/

itemWidth = 90; // Breite eines Teasers
maskWidth = 210; // Breite des Teasers-Containers
steps = 1;

if($('price_slide'))
{
	p_items = $('price_slider').getElementsByTagName('div');
	itemsCounter = 0;
	for(i=0;i<p_items.length;i++)
	{
		if(p_items[i].className == "teaser")
		{
			itemsCounter++;
		}
	}
	
	sliderWidth = (itemsCounter * itemWidth);
	
	$('price_slider').style.left = "0px";
	
	$('toLeft').onclick = toLeft;
	$('toRight').onclick = toRight;
	$('toSeason').onclick = toSeason;
	toSeason();
}


function toLeft ()
{
	$('toLeft').onclick = null;
	
	position = parseInt($('price_slider').style.left);
	if(position < -10) {
		newPosition = itemWidth-20;
		
		end = position + (newPosition*steps);
		
		ex9 = new Animator({transition: Animator.makeEaseOut(4),duration: 1000,onComplete: function() {$('toLeft').onclick = toLeft;}});
		ex9.addSubject(new NumericalStyleSubject($('price_slider'), 'left', position, end));
		ex9.play();
			
	}
	else
	{
		$('toLeft').onclick = toLeft;
	}
	
}


function toRight () 
{

	$('toRight').onclick = null;
	position = parseInt($('price_slider').style.left);
	temp = (sliderWidth - maskWidth) + position;	

	if(temp >= 20)
	{
		newPosition = itemWidth-160;
	
		end = position + (newPosition*steps);
		
		ex9 = new Animator({transition: Animator.makeEaseOut(4),duration: 1000,onComplete: function() {$('toRight').onclick = toRight;}});
		ex9.addSubject(new NumericalStyleSubject($('price_slider'), 'left', position, end));
		ex9.play();
			
	}
	else
	{
		$('toRight').onclick = toRight;
	}
	
}

function toSeason ()
{
	
	
	day=$('beginDayPackage').value;
	month=$('beginMonthPackage').value;
	year=$('beginYearPackage').value;
		
	date = Date.UTC(year, (month-1), day, 0, 0, 00);
	date=date/1000;
	
	var newpos=null;
	for ( var i=0; i<teaserinfo.length; ++i )
	{
	   if(date<teaserinfo[i][1] && date>=teaserinfo[i][0])
	   {
			newpos=i;
	   }
	   
    }
	if (newpos==null)
	{
			newpos=(teaserinfo.length-1);
	}
	
	
	$('toSeason').onclick = null;
	position = parseInt($('price_slider').style.left);
	currentpos=position/(itemWidth-20)*(-1);
	
	
	
	if(newpos>currentpos)
	{
		for(i=currentpos;i<=newpos;i++)
		{
			steps =newpos-currentpos;
			toRight();
			steps = 1;
		}
	}
	else if(newpos<currentpos)
	{
		for(i=currentpos;i>=newpos;i--)
		{
			steps=currentpos-newpos;
			toLeft();
			steps=1;
		}
	}
	else
	{
		
	}
	
	$('toSeason').onclick = toSeason;
	
}

