var vs_to = 0;
var vs_from = 0;
var vs_speed = 0.20;
var vs_cnt_up = 0;
var vs_cnt_down = 0;

var VacAnimTimer;
var autoAnimTimer = false;

var current_info = false;

function autoAnim()
{

	if(autoAnimTimer) {
		clearTimeout(autoAnimTimer);
		scrolldown();
	}
	autoAnimTimer = setTimeout("autoAnim();",7000);
}


function scrolldown ()
{
	if(autoAnimTimer) {clearTimeout(autoAnimTimer);}
	vs_from += 105;

	for (i=0;i<vacorder.length;i++) {
  		vacorder[i] -= 105;
  		if(vacorder[i] < 0) vacorder[i]=(vacorder.length-1)*105;
  	}
	VacAnim();
}

function scrollTo (el)
{
	if(autoAnimTimer) {clearTimeout(autoAnimTimer);}	
	var elID = parseFloat(el.id.substr(3));
	
	var oldPos = vacorder[elID];
	
	for (i = 0; i < vacorder.length; i++) {
		var pos = (3 + i) % vacorder.length;;
		var idx = (elID + i) % vacorder.length;;
   		vacorder[idx] = pos * 105;
  	}
  	
	vs_from = oldPos - vacorder[elID]
	VacAnim();
}

function scrollup ()
{
	if(autoAnimTimer) {clearTimeout(autoAnimTimer);}
	vs_from -= 105;

	for (i=0;i<vacorder.length;i++) {
   		vacorder[i] += 105;
   		if(vacorder[i] > (vacorder.length-1)*105 ) vacorder[i]=0;
  	}
	VacAnim();
}


function VacAnim()
{
	if(VacAnimTimer) clearTimeout(VacAnimTimer);
	VacAnimTimer = setTimeout("VacAnim();",10);

	vs_from += vs_speed * (vs_to - vs_from);
	

	for (i=0;i<vacorder.length;i++) {
		var vacdiv = document.getElementById('vac'+i);

		var pos = vacorder[i];
		var newpos = pos+(Math.round(vs_from)-105);
		if( newpos < 0) newpos = (vacorder.length-1)*105;
		vacdiv.style.top = newpos+'px';
	}
	

	if(Math.round(vs_from) == vs_to) {
      clearTimeout(VacAnimTimer);
      	
      for (v in vacorder) {
			if(vacorder[v]==315) {
				ShowItemDetails(v);
			}
		}
  	}
}

function ShowItemDetails(id) 
{
	if(current_info !== false) {
		$('#item_details_'+current_info).fadeOut('fast', function() {
			$('#item_details_'+id).fadeIn('fast');
			current_info = id;
		});
	} else {
		$('#item_details_'+id).fadeIn('fast');
		current_info = id;
	}
	
}
