var timer;
var timer2;
var nhgt = 120;
var nwdt = 90;
var nopa = 0;
var gal_id = 0;
var gal_type = 0;
var tempimg = new Image();
tempimg.src = "layout/styles/images/loading2.gif";

var steph = 75;
var stepw = 75;
var stepb = 15;
var buffimage = new Image();

var imgpath = "data/nemovitosti/";
var aimage = new Array();
var atext = new Array();
var curimg = 0;

function redirect(url)
{
	window.location.href = url;
}
function news(n)
{
	for(i = 1; i <= 6; i++)
		document.getElementById('new'+i).style.display = ((i == n)?'block':'none');
}
function foto(file)
{
  window.open("foto.php?foto="+file,"x","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=no,width=350,height=262,left=50,top=50"); 
}
function hide_show()
{
	var disp = document.getElementById('hidden');
	disp.style.display = ((disp.style.display == 'block')?'none':'block');
}
function image_position(evt)
{
	var small = document.getElementById('image_small');
	var large = document.getElementById('image_large');
	var img_x;
	var img_y;
	var pos_x;
	var pos_y;
	if (document.all)
	{
		img_x = evt.offsetX;
		img_y = evt.offsetY;
	} else {
		img_x = evt.clientX;
		img_y = evt.clientY;
		for (var offMark = evt.target; offMark;	offMark = offMark.offsetParent)
			img_x -= offMark.offsetLeft;
		for (var offMark = evt.target; offMark;	offMark = offMark.offsetParent)
			img_y -= offMark.offsetTop;
	}
	pos_x = (img_x / small.width) * 100;
	pos_y = (img_y / small.height) * 100;
	large.style.backgroundPosition = pos_x+'% '+pos_y+'%';
	large.style.backgroundPositionX = pos_x+'%';
	large.style.backgroundPositionY = pos_y+'%';
}
function image_swap(target, imaget)
{
	var img = document.getElementById(target);
	img.src = imaget;
}
function image_swap_background(target, imaget)
{
	var img = document.getElementById(target);
	img.style.backgroundImage = 'url('+imaget+')';
}

function menu(i, j, k, keep, from)
{
	var n;
	for(n = from+1; n < from+20; n++)
	{
	  if(document.getElementById('mnu'+n) != null)
		{
	    var submenu = document.getElementById('mnu'+n);
			if(n == i || n == j || n == k)
				submenu.style.display = 'block';
			else
				submenu.style.display = 'none';
		}
	}
	if(i + j + k)
		document.getElementById('mnu'+from).style.backgroundPosition = '0 -35px';
	else if(!keep)
		document.getElementById('mnu'+from).style.backgroundPosition = '0 0';
}
function new_window(link)
{
  window.open(link,"x","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=yes,width=620,height=800,right=50,top=50"); 
}
function editor_toEditor(target)
{
  var editor = document.getElementById('editor_'+target);
  var text = document.getElementById('data_'+target);
  editor.contentWindow.document.body.innerHTML = text.innerHTML;
  return true;
}
function editor_toTextarea(target)
{
  var editor = document.getElementById('editor_'+target);
  var text = document.getElementsByName(target)[0];
  text.value = editor.contentWindow.document.body.innerHTML;
  return true;
}
function editor_setup()
{
	var editors = document.getElementsByTagName('iframe');
	var i;
	for(i = 0; i < editors.length; i++)
	{
		editors[i].contentWindow.document.designMode = 'on';
	}
}
function editor_submit()
{
	var editors = document.getElementsByTagName('iframe');
	var i;
	for(i = 0; i < editors.length; i++)
	{
		var eid = editors[i].id;
		var tname = eid.split("_")[1];
		if(text = document.getElementsByName(tname)[0])
			text.value = editors[i].contentWindow.document.body.innerHTML;
	}
}
function editor_execCommand(target, command, value)
{
  var top = document.body.scrollTop;
  var editor = document.getElementById('editor_'+target);
  editor.contentWindow.document.execCommand(command, false, value);
  editor.contentWindow.focus();
  document.body.scrollTop = top;
}
function editor_eurl(target)
{
  var url = document.getElementById('url_'+target).value;
	url = url.replace(/\\\\/g, 'file://///');
	url = url.replace(/\\/g, '/');
  editor_execCommand(target, 'createLink', url);
}
function editor_eimg(target)
{
  var url = document.getElementById('img_'+target).value;
  editor_execCommand(target, 'insertImage', url);
}
function editor_galerie(target)
{
  window.open("galerie_shout.php?target="+target,"x","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=auto,resizable=yes,width=800,height=300,left=500,top=50"); 
}
function editor_insertimg(target, img)
{
  var pos = document.getElementById('pos').value;
  var vel = document.getElementById('vel').value;
  var url = 'data/galerie/'+vel+'/'+img;
  var urlp = 'data/galerie/'+vel+'/'+img+'xyz';
  var urlm = "javascript:zobraznahled('data/galerie/medium/"+img+"')";
  var editor = window.opener.document.getElementById('editor_'+target);
  editor.contentWindow.document.execCommand('insertImage', false, urlp);
  var str = editor.contentWindow.document.body.innerHTML;
  var newstr = str.replace('<img src="'+urlp+'">', '<a href="'+urlm+'"><img src="'+url+'" style="float:'+pos+';" class="text'+pos+'"></a>');
  editor.contentWindow.document.body.innerHTML = newstr;
  editor.contentWindow.focus();
}
function editor_inserturl(target)
{
  var url = document.getElementById('url_'+target).value;
	url = url.replace(/\\\\/g, 'file://///');
	url = url.replace(/\\/g, '/');
  var urlp = document.getElementById('url_'+target).value+'xyz';
	urlp = url.replace(/\\\\/g, 'file://///');
	urlp = url.replace(/\\/g, '/');
  var editor = document.getElementById('editor_'+target);
  editor.contentWindow.document.execCommand('createLink', false, urlp);
  var str = editor.contentWindow.document.body.innerHTML;
  var newstr = str.replace('href="'+urlp+'"', 'href="'+url+'" onclick="target=\'_blank\';"');
  editor.contentWindow.document.body.innerHTML = newstr;
  editor.contentWindow.focus();
}
function editor_inserttext(target)
{
  var text = document.getElementById('inserttext_'+target).value;
  var editor = document.getElementById('editor_'+target);
  editor.contentWindow.document.body.innerHTML = text;
  editor.contentWindow.focus();
}
function zobrazskryj(cil)
{
  var item = document.getElementById(cil);
  if(item.style.display == 'block')
    item.style.display = 'none';
  else
    item.style.display = 'block';
}
function gzobraz(cil)
{
  var img = document.getElementById('img'+cil);
  var over = document.getElementById('over'+cil);
  img.style.display = 'block';
  if(document.getElementById('txt'+cil) != null) document.getElementById('txt'+cil) = 'block';
}
function gskryj(cil)
{
  var img = document.getElementById('img'+cil);
  var over = document.getElementById('over'+cil);
  img.style.display = 'none';
  if(document.getElementById('txt'+cil) != null) document.getElementById('txt'+cil) = 'block';
}

function winHeight() {
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' )
    myHeight = window.innerHeight;
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    myHeight = document.documentElement.clientHeight;
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    myHeight = document.body.clientHeight;
  return myHeight;
}
function zobraznahled(i)
{
  var nahled = document.getElementById("nahled");
  var img = document.getElementById("nahledimg");
  var imgn = document.getElementById("imgn");
  var button = document.getElementById("nahledbutton");
  var ph = "layout/styles/loading.gif";
  imgn.src = ph;
  imgn.src = i;
  button.style.left = ((screen.width / 2) - 45) + 'px';
  nahled.style.display = 'block';
  nahled.style.height = winHeight() + 'px';
  img.style.display = 'block';
}
function skryjnahled()
{
  var nahled = document.getElementById("nahled");
  var img = document.getElementById("nahledimg");
  nahled.style.display = 'none';
  img.style.display = 'none';
}
function faqq(i)
{
	faq = document.getElementById('faq'+i);
	if(faq.style.display == 'block')
		faq.style.display = 'none';
	else
		faq.style.display = 'block';
}
