﻿var scrollArea = "scroller";
var paneTag = "_pane";
var paneWidth = 700;
var currentSectionIndex = 0;

function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}

function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )

	return Array(elemX, elemY);
}

function ScrollSection(targetSectionIndex)
{
  if (targetSectionIndex == currentSectionIndex) return;
  
  currentSectionIndex = targetSectionIndex;
  
 
  // auskommentiert: wird nur benötigt wenn die seiten via dropdown angesteuert werden sollen
  
  // document.getElementById("topToolbar").selectedIndex =  
  // document.getElementById("bottomToolbar").selectedIndex = currentSectionIndex;

  var link = toolbarNames[currentSectionIndex]+"_pane";
	
	if (typeof(OnScrollSection) == "function") OnScrollSection(currentSectionIndex);
	
  theScroll = document.getElementById(scrollArea);
  position = findElementPos(document.getElementById(link));
  if (offset != "") {
	  offsetPos = findElementPos(document.getElementById(offset));
	  position[0] = position[0] - offsetPos[0];
  }

  scrollStart(theScroll, theScroll.scrollLeft, position[0]);
}

function ScrollArrow(direction) {
  var targetSectionIndex = currentSectionIndex;
	if (direction == "left") 
		if (currentSectionIndex - 1 < 0) 
			targetSectionIndex = toolbarNames.length-1;
		 else 
		  targetSectionIndex--;
	else 
		if ((currentSectionIndex + 1) > (toolbarNames.length - 1)) 
		  targetSectionIndex = 0;
		 else 
		  targetSectionIndex++;
	ScrollSection(targetSectionIndex);
}

var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end)
{
	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 25;
	scrollanim.element = elem;
  scrollanim.timer = setInterval("scrollHorizAnim();", 15);
}

function scrollHorizAnim() { 
  if (scrollanim.time > scrollanim.duration) { 
    clearInterval(scrollanim.timer); 
    scrollanim.timer = null;
		var w = document.getElementById("ifrWidget"+currentSectionIndex);
    if (w && w.src == "about:blank") w.src = w.getAttribute("targetSrc");
  } else { 
    move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration); 
    scrollanim.element.scrollLeft = move; 
    scrollanim.time++; 
  }
}


