var show_flag = new Array(0,0,0,0);
var start_menu = 0;
function init_menu() {start_menu = 1;}
function show_menu(order) {
	if (start_menu) {
		show_flag[order] = 1;
		window.setTimeout('show_menu_make(' + order + ')',300);
	}
}
function show_menu_make(order) {
	if (show_flag[order]) {
		var _top = document.getElementById('menu').offsetTop + document.getElementById('sp_' + order).offsetTop + document.getElementById('sp_' + order).offsetHeight + 10;
		var _left = document.getElementById('menu').offsetLeft + document.getElementById('sp_' + order).offsetLeft;
		document.getElementById('submenu_' + order).style.top = _top +  'px';
		document.getElementById('submenu_' + order).style.left = _left +  'px';
		document.getElementById('submenu_' + order).style.display = 'block';
	}
}
function hide_menu(order) {
	show_flag[order] = 0;
	window.setTimeout('hide_menu_make(' + order + ')',300);
}
function hide_menu_make(order) {
	if (!show_flag[order]) document.getElementById('submenu_' + order).style.display = 'none';
}
function init_scroll() {
	start_menu = 1;
	if (document.getElementById('text_envelope').offsetHeight < document.getElementById('text_content').offsetHeight) {
		document.getElementById('scroll_back').style.display = 'block';
		vs = document.getElementById('scroll_back').offsetHeight - 2*document.getElementById('move_down').offsetHeight - 2;
		vd = document.getElementById('text_content').offsetHeight;
		move_height = Math.floor(Math.pow(vs,2)/vd);
		document.getElementById('move_position').style.height = move_height + 'px';
	}
	else document.getElementById('scroll_back').style.display = 'none';
	document.getElementById('text_content').style.top = 0;
}
var move_flag = 0;
var move_height = 0;
var vd = 0;
var vs = 0;
function movescroll(x) {
	if (move_flag) {
		var actual;
		var moveobj = document.getElementById('text_content');
		var max_move = document.getElementById('text_envelope').offsetHeight - moveobj.offsetHeight - 5;
		if ((x >= 0 && moveobj.offsetTop <= 0) || (x <= 0 && moveobj.offsetTop >= max_move)) actual = moveobj.offsetTop + x;
		if (actual < max_move) actual = max_move;
		if (actual > 0) actual = 0;
		moveobj.style.top = actual + 'px';
		window.setTimeout('movescroll(' + x + ')',50);
		var act_pos = Math.floor((actual)*(vs - 5 - move_height)/max_move) + 11;
		document.getElementById('move_position').style.top = act_pos + 'px';
	}
}
function startscroll(x) {
	move_flag = 1;
	movescroll(x);
}
function stopscroll() {move_flag = 0;}
function set_active_a(cl,name) {
	var all_as = document.getElementsByTagName('A');
	for (x=0;x<all_as.length;x++) if (all_as[x].className == 'active' && all_as[x].id.substr(0,cl.length) == cl) all_as[x].className = 'inactive';
	document.getElementById(cl + name).className = 'active';
}
function change_div(name) {
	set_active_a('m_',name);
	var all_divs = document.getElementsByTagName('DIV');
	for (x=0;x<all_divs.length;x++) if (all_divs[x].className == 'price_div') all_divs[x].style.display = 'none';
	document.getElementById(name).style.display = 'block';
	init_scroll();
}
function verify_form(obj) {
	if (obj.date_od.value == '') {
		window.alert('Nie je zadaný termín');
		obj.date_od.focus();
		return false;
	}
	if (obj.name.value == '') {
		window.alert('Nie je zadané meno');
		obj.name.focus();
		return false;
	}
	if (obj.address.value == '') {
		window.alert('Nie je zadaná adresa');
		obj.address.focus();
		return false;
	}
	if (obj.tel.value == '') {
		window.alert('Nie je zadané telefónne číslo');
		obj.tel.focus();
		return false;
	}
	return true;
}
function show_picture(path) {
	document.getElementById('pict_big').src = 'images/empty.gif';
	var link = document.getElementById('download_link');
	if (link != null) link.href = 'download_picture.php?name=images/galeria/original/' + path.substr(path.lastIndexOf('/') + 1);
	document.getElementById('pict_preview').style.display = 'block';
	document.getElementById('pict_big').src = path;
}
function close_picture() {document.getElementById('pict_preview').style.display = 'none';}
function show_firts(flag) {
	document.getElementById('pict_big').src = 'images/galeria/big/' + foto_array[0];
	if (flag) document.getElementById('download_link').href = 'download_picture.php?name=images/galeria/original/' + foto_array[0];
}
function show_last(flag) {
	document.getElementById('pict_big').src = 'images/galeria/big/' + foto_array[foto_array.length - 1];
	if (flag) document.getElementById('download_link').href = 'download_picture.php?name=images/galeria/original/' + foto_array[foto_array.length - 1];
}
function get_actual_index() {
	for (x=0;x<foto_array.length;x++) {
		if (document.getElementById('pict_big').src.indexOf('images/galeria/big/' + foto_array[x]) != -1) return x;
	}
	return 0;
}
function show_prew(flag) {
	var src = '';
	var actual = get_actual_index();
	if (actual) src = foto_array[actual - 1]; else src = foto_array[foto_array.length - 1];
	document.getElementById('pict_big').src = 'images/galeria/big/' + src;
	if (flag) document.getElementById('download_link').href = 'download_picture.php?name=images/galeria/original/' + src;
}
function show_next(flag) {
	var src = '';
	var actual = get_actual_index();
	if (actual < foto_array.length - 1) src = foto_array[actual + 1]; else src = foto_array[0];
	document.getElementById('pict_big').src = 'images/galeria/big/' + src;
	if (flag) document.getElementById('download_link').href = 'download_picture.php?name=images/galeria/original/' + src;
}
function scrollto(name) {
	set_active_a('scroll_',name);
	var _top = -document.getElementById(name).offsetTop;
	document.getElementById('text_content').style.top = _top + 'px';
	
}
