var thisX = 0;
var thisY = 0;
var i, thisItem, thisLink, thisInput, timer;
var menuItems = new Array('a_tym', 'b_tym', 'c_tym', 'mladez', 'zeny');

function _subMenu (id) {
	if (typeof(menuItems) != "undefined" && menuItems.length > 0) {
		for (x = 0; x < menuItems.length; x++) {
			thisItem = myGet('sub_' + menuItems[x]);
			if (thisItem) {
				thisItem.className = 'menu_sub hidden';
			}
			thisItem = myGet(menuItems[x]);
			if (thisItem && thisItem.getElementsByTagName('a').length > 0) {
				thisItem.getElementsByTagName('a')[0].style.backgroundImage = "url('/images/_layout/bg-menu-top-li-" + menuItems[x] + ".gif')";
			}
		}
	}
	
	thisItem = myGet('sub_' + id);
	if (thisItem) {
		thisItem.className = 'menu_sub';
	}
	thisItem = myGet(id);
	if (thisItem && thisItem.getElementsByTagName('a').length > 0) {
		thisItem.getElementsByTagName('a')[0].style.backgroundImage = 'none';
	}
}

// menu - zobraz
function _menuShowSub () {
	if (this.className == "menu_left") {
		this.style.backgroundImage = "url('/images/_layout/bg-menu-left-li-over.gif')";
		this.getElementsByTagName('a')[0].className = "selected";
	}
	
	if (this.getElementsByTagName('ul').length > 0) {
		for (i = 0 ; i < this.getElementsByTagName('ul').length ; i++) {
			//this.getElementsByTagName('ul')[i].style.visibility = 'visible';
			this.getElementsByTagName('ul')[i].style.display = 'block'; 
		}
	}
}

// menu - skryj
function _menuHideSub () {
	if (this.className == "menu_left") {
		this.style.backgroundImage = "url('/images/_layout/bg-menu-left-li.gif')";
		this.getElementsByTagName('a')[0].className = "";
	}
	if (this.getElementsByTagName('ul').length > 0) {
		for (i = 0 ; i < this.getElementsByTagName('ul').length ; i++) {
			//this.getElementsByTagName('ul')[i].style.visibility = 'hidden';
			this.getElementsByTagName('ul')[i].style.display = 'none'; 
		}
	}
}

// menu - inicializace
function _menuInit (id) {
	var thisMenu = myGet(id);

	if (thisMenu && thisMenu.getElementsByTagName('ul').length > 0){
		if (thisMenu.getElementsByTagName('ul').length > 0) {
			for (i = 0 ; i < thisMenu.getElementsByTagName('ul').length ; i++) {
				//thisMenu.getElementsByTagName('ul')[i].style.visibility = 'hidden'; 
				thisMenu.getElementsByTagName('ul')[i].style.display = 'none'; 
			}
		}
	
		var li = thisMenu.firstChild;
		while (li) {
			li.onmouseover = _menuShowSub;
			li.onmouseout  = _menuHideSub;
			li = li.nextSibling;
		}
	}
}

// otázky
function addQuestion () {
	thisItem = myGet('otazka');
	thisInput = myGet('pridej');
	
	if (thisItem && thisInput) {
		if (thisItem.className == "hidden") {
			thisItem.className = "visible";
			thisInput.value = 'zavĹ™i dotaz';
		} else {
			thisItem.className = "hidden";
			thisInput.value = 'pĹ™idej dotaz';
		}
	}
}

// partneri
var timerScroll = null;
var timerPos = 430;
var timerMove = 2;
var scrollPause = false;

function _showPartners () {
	var thisScroll = myGet('scroll');
	
	if (thisScroll && !scrollPause) {
		if (thisScroll.scrollHeight < Math.abs(timerPos)) {
			timerPos = 430;
		}
		timerPos = timerPos - timerMove;
		thisScroll.style.top = timerPos + 'px';
	}
	
	clearTimeout(timerScroll);
	timerScroll = window.setTimeout("_showPartners()", 30);
}

// fotky
function _pic (e, i) {
	var o_width, o_height, w_width, w_height, w_offset_x, w_offset_y, picsLength;

	if (typeof(pics) != "undefined" && pics.length > 0) {
		o_width = parseInt(pics[i][1]);
		o_height = parseInt(pics[i][2]);

		picsLength = pics.length;
		for (x = 0; x < picsLength; x++) {
			if (typeof(pics[x]) == "undefined") {
				picsLength--;
			} 
		}
	
		if (self.innerWidth) {															// all except Explorer
			w_width = parseInt(self.innerWidth);
			w_height = parseInt(self.innerHeight);
			w_offset_x = parseInt(self.pageXOffset);
			w_offset_y = parseInt(self.pageYOffset);
		} else if (document.documentElement && document.documentElement.clientHeight) {	// Explorer 6 Strict Mode
			w_width = parseInt(document.documentElement.clientWidth);
			w_height = parseInt(document.documentElement.clientHeight);
			w_offset_x = parseInt(document.documentElement.scrollLeft);
			w_offset_y = parseInt(document.documentElement.scrollTop);
		} else if (document.body) {														// other Explorers
			w_width = parseInt(document.body.clientWidth);
			w_height = parseInt(document.body.clientHeight);
			w_offset_x = parseInt(document.body.scrollLeft);
			w_offset_y = parseInt(document.body.scrollTop);
		}

		var thisItem = myGet('photo');
		var thisOverlay = myGet('overlay');
		var thisInnerHTML = '';
	
		if (thisItem && thisOverlay) {
			if (e) {
				thisX = w_width / 2 - o_width / 2 + w_offset_x;
				thisX = thisX < 0 ? 0 : thisX;
				thisY = w_height / 2 - o_height / 2 + w_offset_y;
				thisY = thisY < 0 ? 0 : thisY < w_offset_y ? w_offset_y : thisY;
			}
	
			thisOverlay.style.display = 'block';
			thisItem.style.display = 'block';
			thisItem.style.width = o_width + 20 + 'px';
			thisItem.style.height = o_height + (pics[i][3] != "" ? 40 : 20) + 'px';
			thisItem.style.top = thisY + (pics[i][3] != "" ? -20 : 0) + 'px';
			thisItem.style.left = thisX + 'px';

			thisInnerHTML = '<div class="margin">';
			thisInnerHTML += '<div class="close"><a href="javascript:_pic_close(' + i + ');" title="zavĹ™i obrĂˇzek">zavĹ™i obrĂˇzek</a></div>';
			if (picsLength > 1 && i >= 0) {
				thisInnerHTML += '<ul class="nav">';
				thisInnerHTML += !i ? '<li class="first_off"><span>prvnĂ­ obrĂˇzek</span></li>' : '<li class="first"><a href="#" onclick="return _pic(false, 0);" title="prvnĂ­ obrĂˇzek"><span>prvnĂ­ obrĂˇzek</span></a></li>';
				thisInnerHTML += !i ? '<li class="prev_off"><span>pĹ™edchozĂ­ obrĂˇzek</span></li>' : '<li class="prev"><a href="#" onclick="return _pic(false, ' + (i-1) + ');" title="pĹ™edchozĂ­ obrĂˇzek"><span>pĹ™edchozĂ­ obrĂˇzek</span></a></li>';
				thisInnerHTML += i == (picsLength-1) ? '<li class="next_off"><span>dalĹˇĂ­ obrĂˇzek</span></li>' : '<li class="next"><a href="#" onclick="return _pic(false, ' + (i+1) + ');" title="dalĹˇĂ­ obrĂˇzek"><span>dalĹˇĂ­ obrĂˇzek</span></a></li>';
				thisInnerHTML += i == (picsLength-1) ? '<li class="last_off"><span>poslednĂ­ obrĂˇzek</span></li>' : '<li class="last"><a href="#" onclick="return _pic(false, ' + (picsLength-1) + ');" title="poslednĂ­ obrĂˇzek"><span>poslednĂ­ obrĂˇzek</span></a></li>';
				thisInnerHTML += '</ul>';
			}
			thisInnerHTML += '<a href="javascript:_pic_close(' + i + ');" title="zavĹ™i obrĂˇzek"><img src="' + pics[i][0] + '" width="' + pics[i][1] + '" height="' + pics[i][2] + '" alt="' + pics[i][3] + '" /></a>';
			thisInnerHTML += (pics[i][3] != "" ? '<p>' + pics[i][3] + '</p>' : '');
			thisInnerHTML += '</div>';
			thisItem.innerHTML = thisInnerHTML;
		}
	}

	return false;
}

//zavři fotku
function _pic_close (i) {
	var thisItem = myGet('photo');
	var thisOverlay = myGet('overlay');
	
	if (thisItem) {
		thisItem.innerHTML = '';
		thisItem.style.display = '';
		thisOverlay.style.display = '';
	}
}

// smajliky
function _smile (code) {
	thisInput = myGet('prispevek');
	
	if (thisInput) {
		thisInput.value = thisInput.value + ' ' + code;
	}
}

// získání elementu
function myGet (name) {
	if (document.getElementById)
		return document.getElementById(name);
	else if (document.all)
		return document.all(name);
	else
		return null;
}
