// scrolling function
var scrolltimer = null;
function verScroll(dir, spd, loop) {
	loop = true;
	direction = "right";

	direction = dir;
	speed = parseInt(spd);
	var x_pos = parseInt(setScroll(null));
	if (loop == true) {
		if (direction == "left") {
			

			if (-((86*photocount)-420) < x_pos) {
				setScroll(x_pos - (speed));
			}
			
		} else {
			if (direction == "right" && x_pos < 0) {
				setScroll(x_pos + (speed));
			} else {
				if (direction == "top") {
					setScroll(0);
				}
 		  }
		}
		scrolltimer = setTimeout("verScroll(direction,speed)", 1);
	}
}

function setScroll(position) {
	if (document.layers) {
		var page = eval(document.contentLayer);
	} else {
		if (document.getElementById) {
			var page= eval("document.getElementById('contentLayer').style");
		} else {
			if (document.all) {
				var page = eval(document.all.contentLayer.style);
			}
		}
	}
	if (position == null) {
		return page.left;
	} else {
		page.left = position;
	}
}

function stopScroll() {
	loop = false;
	clearTimeout(scrolltimer);
}
function re(message){
	document.post_form.msg.value = "[u]"+message+"[/u]";
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function show_hint(hintID){
	hlink = document.getElementById('hlink'+hintID);
	hlink_x = window.hlink.offsetLeft;
	hlink_y = window.hlink.offsetTop;

	hint_div = document.getElementById('hint'+hintID);
	hint_div.style.left = hlink_x+20;
	hint_div.style.top = hlink_y-100;
	
	hparent = hlink.offsetParent;
	hparent_w = hparent.offsetWidth;
	hparent_h = hparent.offsetHeight;
	
/*	if(hlink_x<200 && hlink_y<200){
	hint_div.style.left = hlink_x+30;
	hint_div.style.top = hlink_y+20;
	}else if(hlink_x<200 && (hlink_y+200)<hparent_h){
	hint_div.style.left = hlink_x+30;
	hint_div.style.top = hlink_y-220;		
	}else if((hlink_x+200)<hparent_w && (hlink_y+200)<hparent_h){
	hint_div.style.left = hlink_x-230;
	hint_div.style.top = hlink_y-220;		
	}else if((hlink_x+200)<hparent_w && hlink_y<200){
	hint_div.style.left = hlink_x-230;
	hint_div.style.top = hlink_y+20;		
	};
*/	
	hlink_w = hlink.offsetWidth;
	hlink_h = hlink.offsetHeight;

	hint_div.style.display = 'block';
	hint_w = hint_div.offsetWidth;
	hint_h = hint_div.offsetHeight;
//	alert('hint_w: '+hint_w+' hint_h: '+hint_h);	
	
/*	if(hlink_x<hint_w && hlink_y<hint_h){
	hint_div.style.left = hlink_x+30;
	hint_div.style.top = hlink_y+20;
	}else if(hlink_x<hint_w && (hlink_y+hint_h)<hparent_h){
	hint_div.style.left = hlink_x+30;
	hint_div.style.top = hlink_y-hint_h;		
	}else if((hlink_x+hint_w)>hparent_w && (hlink_y+hint_h)<hparent_h){
	hint_div.style.left = hlink_x-hint_w;
	hint_div.style.top = hlink_y-hint_h;		
	}else if((hlink_x+hint_w)>hparent_w && hlink_y<hint_h){
	hint_div.style.left = hlink_x-hint_w;
	hint_div.style.top = hlink_y+20;		
	};*/
	
	if(hlink_x<hint_w){
	hint_div.style.left	= hlink_x+30;
	}else if((hlink_x+hlink_w+hint_w)>hparent_w){
	hint_div.style.left	= hlink_x-hint_w;
	}else{
	hint_div.style.left	= hlink_x+30;
	//alert('x: '+hlink_x+' w: '+hint_w+' +: '+(hlink_x-hint_w));
	};

	if(hlink_y<hint_h){
	hint_div.style.top	= hlink_y+20;
	}else if((hlink_y+hlink_h+hint_h)>hparent_h){
	hint_div.style.top	= hlink_y-hint_h;
	}else{
	hint_div.style.top	= hlink_y+20;
	};

	//alert('hlink_x: '+hlink_x+' hlink_y: '+hlink_y);
	//alert('hparent_w: '+hparent_w+' hparent_h: '+hparent_h);
	//alert(hlink.offsetParent);

	//alert('left '+hlink_x+' top '+hlink_y);
	//alert('height '+hparent_h+' width '+hparent_w);
//	alert('hlink_x: '+hlink_x+'hlink_y: '+hlink_y);	

//	function findPos(obj) {
/*	hint_div = document.getElementById('hlink'+hintID);
	var curleft = curtop = 0;
	if (hint_div.offsetParent) {
	do {
	curleft += hint_div.offsetLeft;
	curtop += hint_div.offsetTop;
	} while (hint_div = hint_div.offsetParent);
	}
	hint_div = document.getElementById('hint'+hintID);
	hint_div.style.left = curleft+20;
	hint_div.style.top = curtop+20;
	hint_div.style.display = 'block';*/
//	return [curleft,curtop];
//	alert('curtop: '+curtop+' curleft: '+curleft);

}
function hide_hint(hintID){
	hint_div = document.getElementById('hint'+hintID);
	hint_div.style.display = 'none';
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function displayPhoto(photoseq) {
	currentphoto = photoseq;
	
	//showElement('loading');
	var img_date = photo[currentphoto][0];
	var img_name = photo[currentphoto][1];
	var img_desc = photo[currentphoto][2];
	var filename = photo[currentphoto][3];
	var filewidth = photo[currentphoto][4];
	var fileheight = photo[currentphoto][5];
	var img_id = photo[currentphoto][6]
	var lang = photo[currentphoto][7]
	var logged = photo[currentphoto][8]
	
	element = document.getElementById("image_dock");
	
	//zkousim nastavit za pomoci CSS vlastnosti divu image_dock, ale nejde dosadit vyska (div je jinak prazdny)
	//element.style.background='url(\'images/photos/resized/'+filename+'\') no-repeat';
	//element.style.height=fileheight+'px';
	//document.body.height = '100%';
	
	//do divu pridam jeste tag img a menim cely vnitrek v divu. v ie to dela vyse zminenou chybu
	element.innerHTML = '<a href="fullimg.php?id='+img_id+'" target="_blank"><img src="images/photos/resized/'+photo[currentphoto][3]+'" border="0" height="'+fileheight+'" width="'+filewidth+'" /></a>';
	
	element = document.getElementById("image_desc_date");
	element.innerHTML = img_date;
	element.style.display = "block";
	
	element = document.getElementById("image_desc_name");
	element.innerHTML = img_name;
	element.style.display = "inline";
	
	element = document.getElementById("image_desc_desc");
	element.innerHTML = img_desc;
	element.style.display = "block";

	if(logged == 1){
	element = document.getElementById("image_desc_menu");
	element.innerHTML = '';
	};
	
	/////////////////////
/*	
	if(lang == "cz"){
	var prev_label = document.createTextNode('předchozí');
	var next_label = document.createTextNode('následující');
	}else{
	var prev_label = document.createTextNode('previous');
	var next_label = document.createTextNode('next');	
	};
	var imagenav_menu = document.getElementById('image_navmenu');
	var prev_link = document.createElement('a');
	var next_link = document.createElement('a');
	
	prev_num = currentphoto - 1;
	next_num = currentphoto + 1;
	
	if(prev_num <= 0){
		prev_num = photocount;
	};
	if(next_num > photocount){
		next_num = 1;
	};

	prev_link.setAttribute('href', 'javascript:void()');
	prev_link.setAttribute('onclick', 'displayPhoto('+prev_num+')');
	prev_link.onclick=function(){displayPhoto(prev_num);};
	prev_link.appendChild(prev_label);
	next_link.setAttribute('href', 'javascript:void()');
	next_link.setAttribute('onclick', 'displayPhoto('+next_num+')');
	next_link.onclick=function(){displayPhoto(next_num);};
	next_link.appendChild(next_label);
	
	var prev_span = document.createElement('span');
	var next_span = document.createElement('span');
	prev_span.setAttribute('class', 'left');
	prev_span.setAttribute('className', 'left');
	next_span.setAttribute('class', 'right');
	next_span.setAttribute('className', 'right');	
	prev_span.appendChild(prev_link);
	next_span.appendChild(next_link);

	imagenav_menu.innerHTML = '';
	imagenav_menu.appendChild(prev_span);	
	imagenav_menu.appendChild(next_span);
	*/
	/////////////////////
	
	if(logged == 1){
	if(lang == "cz"){
	var edit_label = document.createTextNode('upravit');
	var delete_label = document.createTextNode('smazat');
	}else{
	var edit_label = document.createTextNode('edit');
	var delete_label = document.createTextNode('delete');	
	};
	var imagedesc_menu = document.getElementById('image_desc_menu');
	var edit_link = document.createElement('a');
	var delete_link = document.createElement('a');
	var slash = document.createTextNode(' / ');
	edit_link.setAttribute('href', 'index.php?link=admin&action=edit_image&id='+img_id);
	edit_link.appendChild(edit_label);
	delete_link.setAttribute('href', 'index.php?link=admin&action=delete_image&id='+img_id);
	delete_link.appendChild(delete_label);
	imagedesc_menu.appendChild(edit_link);	
	imagedesc_menu.appendChild(slash);	
	imagedesc_menu.appendChild(delete_link);
	};
	
	document.getElementById("footer").style.margin = '0px auto 0px auto';
	document.getElementById("footer").style.margin = '-60px auto 0px auto';
/*	
	document.getElementById("image_dock").style.margin = '0px 0px 0px 0px';
	document.getElementById("image_dock").style.margin = '0px 20px 20px 20px';
*/
	//element = document.getElementById("image_desc_menu");
	//element.innerHTML = '<a href="index.php?link=admin&action=edit_image&id='+img_id+'">upravit</a> / <a href="index.php?link=admin&action=delete_image&id='+img_id+'">smazat</a>';
	/*
	element2 = document.getElementById("image_desc");
	element2.innerHTML = '<span class="menu" id="image_desc_menu"><a href="" name="img_edit">upravit</a> / <a href="">smazat</a></span>\n<span class="date" id="image_desc_date">'+img_date+'</span>\n<span class="name" id="image_desc_name">'+img_name+'</span>\n<span class="desc" id="image_desc_desc">'+img_desc+'</span>';
	*/
	
	/*document.img_edit.href='index.php?link=admin&action=edit_image&id='+img_id;*/
	//document.getElementById("center").style.margin = '0 auto 0 auto';
	//jiny zpusob, taky pres img, ktery mam pojmenovany image_container. stejna chyba jako v predchozim
	//document.image_container.src = 'images/photos/resized/'+filename;
	//document.image_container.width = filewidth;
	//document.image_container.height = fileheight;
	
	//var bodyheight = body.getGeight();
	/*
	var center_height = document.getElementById("center").offsetHeight;
	var body = document.body.offsetHeight;
	alert('center: '+center_height);
	alert('body: '+body);
	var main = document.getElementById("main").offsetHeight;
	alert('main: '+main);
	var content = document.getElementById("content").offsetHeight;
	alert('content: '+content);
	*/
}
function quickStart(){
	setScroll(0);
}
function quickEnd(){
	if (photocount >= 5){
	end_pos = -((86*photocount)-420);
	setScroll(end_pos);
	};
}
function movemenu_show(nr){
	var menu_div_name = "movemenu"+nr;
  document.getElementById(menu_div_name).style.display="block";
}
function movemenu_hide(nr){
	var menu_div_name = "movemenu"+nr;
  document.getElementById(menu_div_name).style.display="none";
}
function reveal_category(id){
	var catname = "cat"+id;
	if(document.getElementById(catname).style.display=="none"){
	document.getElementById(catname).style.display="block";
	}else{
	document.getElementById(catname).style.display="none";	
	}
/*
	document.getElementById("image_dock").style.margin = '0px 20px 20px 20px';
	

	document.getElementById("image_dock").style.margin = '0px 0px 0px 0px';
	document.getElementById("image_dock").style.margin = '0px 20px 20px 20px';
*/
	document.getElementById("footer").style.margin = '0px auto 0px auto';
	document.getElementById("footer").style.margin = '-60px auto 0px auto';
}
function change_gbook_state(g_var){
  	g = document.gbook_form;
	if(g_var.value == "off"){
		g.gbook_text_cz.disabled = false;
		g.gbook_text_en.disabled = false;
	}else{
		g.gbook_text_cz.disabled = true;
		g.gbook_text_en.disabled = true;
	}
}
