var scrollTimer = new Array();
var actualPos = new Array();
var endScr = 125;
var endVyska = 80;
var maxVyska = 205;
var actualScrollingObject = null;
var scrollingPosition = new Array();
var isNowScrolling = false;


var actScroll = unescape(readCookie("actScroll"));
if (actScroll == "null") { actScroll = "1"; }
var today = new Date();
var expire = new Date();

/**
*	Funkce, ktera ulozi cookies
*/
function setActiveScroll(id) {
	expire.setTime(today.getTime() + 3600000*24*-1);
	document.cookie = "actScroll"+"=;expires="+expire.toGMTString();

	expire.setTime(today.getTime() + 3600000*24*1000);
	document.cookie = "actScroll"+"="+escape(id)+";expires="+expire.toGMTString()+"; path=/";
}

/**
*	Funkce, ktere vynuluje pozici
*/
function startPosition(id) {
	if (!is_gecko && !is_ie5_5up && !is_opera6up)	{
		return false;
	}

	for (var i=1; i<=7; i++) {
		if (i != id) {
			var liElem = document.getElementById('l'+i);
			document.getElementById('i'+i).className = 'imgClose';
			liElem.scrollTop = 125;
			liElem.style.height = '80px';
			actualPos[i] = 0;
		} else {
			actualScrollingObject = i;
		}
	}
}

/**
*	Funkce, ktere scrolluje nahoru
*/
function myScrollUp(id) {
	var liElem = document.getElementById('l'+id);
	var vyska = parseInt(liElem.style.height);

	var actualPosition = actualPos[id];
	var pos = (actualPosition / endScr);

  var newPosition = (-Math.cos(pos*Math.PI)/2) + 0.5;
	if (newPosition == 1 || actualPosition > endScr) {
		document.getElementById('i'+id).className = 'imgClose';
		liElem.scrollTop = 125;
		liElem.style.height = '80px';
		clearInterval(scrollTimer[id]);
		actualPos[id] = 0;
		isNowScrolling = false;
		return false;
	}

	var newScroll = Math.round(newPosition*endScr);
	var scrollDiff = newScroll - liElem.scrollTop;

	liElem.scrollTop = newScroll;
	liElem.style.height = (vyska - scrollDiff) + 'px';
	actualPos[id] += 5;
}

/**
*	Funkce, ktere scrolluje dolu
*/
function myScrollDown(id) {
	var liElem = document.getElementById('l'+id);
	var vyska = parseInt(liElem.style.height);

	var actualPosition = actualPos[id];
	var pos = (actualPosition / endScr);

  var newPosition = (-Math.cos(pos*Math.PI)/2) + 0.5;
	if (newPosition == 1 || actualPosition > endScr) {
		liElem.scrollTop = 0;
		liElem.style.height = '205px';
		clearInterval(scrollTimer[id]);
		actualPos[id] = 0;
		startScrollUp(actualScrollingObject);
		actualScrollingObject = id;
		setActiveScroll(id);
		return false;
	}

	var newScroll = Math.round(newPosition*endScr);
	var scrollDiff = liElem.scrollTop- (endScr - newScroll);

	liElem.style.height = (vyska + scrollDiff) + 'px';
	liElem.scrollTop = endScr - newScroll;
	actualPos[id] += 5;

//	var debugTxt = document.getElementById('debug');
//	debugTxt.value += 'scrollTop: ' + liElem.scrollTop + ' | diff: ' + scrollDiff + ' | height: ' + liElem.style.height + '\n';
}

/**
*	Funkce, ktere zacnou scrolovani
*/
function startScrollUp(id) {
	var liElem = document.getElementById('l'+id);
	if (liElem != undefined) {
		liElem.scrollTop = 0;
		liElem.style.height = '205px';
		actualPos[id] = 0;
		scrollTimer[id] = setInterval("myScrollUp('" + id + "');", 2);
	}
}

function startScrollDown(id) {
	var liElem = document.getElementById('l'+id);
	if (liElem != undefined) {
		document.getElementById('i'+id).className = 'imgOpen';
		liElem.scrollTop = 125;
		liElem.style.height = '80px';
		actualPos[id] = 0;
		scrollTimer[id] = setInterval("myScrollDown('" + id + "');", 10);
	}
}

/**
*	Funkce, ktere vse spusti
*/
function startAction(id) {
	if (!is_gecko && !is_ie5_5up && !is_opera6up)	{
		return false;
	}

	if (id != actualScrollingObject && isNowScrolling == false) {
		startScrollDown(id);
		isNowScrolling = true;
	}
}