function sineInOut(t, b, c, d){
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;}

function cubicInOut(t, b, c, d){
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + 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);
  }

var currentSection = "prvni-str"; // prvně viditelná stránka
var tabTag = "-tab";
var strTag = "-str";

function posunsekce(link, scrollArea, offset){
	if (currentSection == link) {return;}
  	lastSection = currentSection;
  	currentSection = link;
  	
    sectionTab = currentSection.split("-")[0] + tabTag;
    document.getElementById(sectionTab).className = "active";
     
   if (lastSection) {lastTab = lastSection.split("-")[0] + tabTag;
	    document.getElementById(lastTab).className = "inactive";}
    	
	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], "horiz");
  }

function sipka(direction, stranky, scrollArea, offset) {
  strankyElem = document.getElementById(stranky);
	strankyNames = new Array();
      
	if (strankyElem.hasChildNodes()){
		var children = strankyElem.childNodes;
		for (var i = 0; i < children.length; i++) 
		  {
			if (strankyElem.childNodes[i].tagName == "LI") {
				strankyNames.push(strankyElem.childNodes[i].id.split("-")[0]);}
		  }
	}

	for (var i = 0; i < strankyNames.length; i++) {
		if (strankyNames[i] == currentSection.split("-")[0]) {
			if (direction == "left") {
				if (i - 1 < 0) {
					gotoTab = strankyNames[strankyNames.length - 1];} 
          else {gotoTab = strankyNames[i - 1];}} 
            else {if ((i + 1) > (strankyNames.length - 1))
              {gotoTab = strankyNames[0];} 
              else {gotoTab = strankyNames[i + 1];}
			      }
		}
	}
		
	posunsekce(gotoTab+strTag, scrollArea, offset);

}

var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end, direction){
	if (scrollanim.timer != null) {clearInterval(scrollanim.timer);
		scrollanim.timer = null;}
  	scrollanim.time = 0;              //JAK RYCHLO TO VYSTARTUJE  vyšší=rychleji
  	scrollanim.begin = start;
  	scrollanim.change = end - start;
  	scrollanim.duration = 50;        // RYCHLOST JAKOU SE TO BUDE PŘEVÍJET
  	scrollanim.element = elem;
  	
	if (direction == "horiz") {scrollanim.timer = setInterval("scrollHorizAnim();", 15);}              
	 else {scrollanim.timer = setInterval("scrollVertAnim();", 15);}
}

function scrollVertAnim(){
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;}
	  else {move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
  		scrollanim.element.scrollTop = move; 
  		scrollanim.time++;}
}


function posun(){
  var x = 0;
  }
       
        

function scrollHorizAnim(){
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;}
  	else {
  		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
  		scrollanim.element.scrollLeft = move;
  		scrollanim.time++;}
}