var algor = 0;
var mousex = 0;
var mousey = 0;
var offsetx = 20; // vzdálenost preview okna od kurzoru myši na ose X
var offsety = -50; // vzdálenost preview okna od kurzoru myši na ose Y
var ns6 = document.getElementById && !document.all; // pro kontrolu zda jse o FF,NS6 nebo o IE
var URI;
var URL;
var response;
var responsesText;
var loaded = 0;
var side;
var previewWidth;

URI = "http://www.humanistinarovinu.cz/fotos.php?id="; //cesta k serveru

function init() {
	loaded = 1;
//	document.onmousemove = update;
}

function getXY(e)
{ 
  if (!e) e = window.event;

  if (e)
  { 
    if (e.pageX || e.pageY)
    {
      mousex = e.pageX + offsetx;
      mousey = e.pageY + offsety;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] ';
    }
    else if (e.clientX || e.clientY)
    {
      mousex = e.clientX + document.body.scrollLeft + offsetx;
      mousey = e.clientY + document.body.scrollTop + offsety;
	  algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] ';
    }  
  }
}

function update(e)
{
  getXY(e); 
  if (ns6)
  	{
	if (side==1) {mousex-=document.getElementById("preview").style.width+10;}
			window.document.getElementById("preview").style.left = mousex.toString(10) + 'px';
			window.document.getElementById("preview").style.top = mousey.toString(10) + 'px';
	}
	else
		{
	if (side==1) {mousex-=document.getElementById("preview").style.width+10;}
			window.document.getElementById("preview").style.posLeft = mousex;
			window.document.getElementById("preview").style.posTop = mousey;
		}
 }

function show(uid) 
 {
	side = 0;
	if (loaded == 1)
		{
		URL = "";
		URL = URI + uid; 
//		make_request(URL);
		window.document.getElementById("preview").style.visibility = "visible";
		window.document.getElementById("preview").style.display = "block";
		window.document.getElementById("preview").style.zIndex = "99";
		window.document.getElementById("preview").innerHTML = "<a href=\"javascript:hide()\" title=\"Kliknutím zavři...\"><img src=\""+URL+"\" border=\"0\" alt=\"Foto\" /></a><br /><font color=\"#FFFFFF\"><strong>Klikem na obrázek zavři</strong></font>";
		}
 }

function show_r(uid) 
 {
	side=1;
	if (loaded == 1)
		{
		URL = "";
		URL = URI + uid; 
//		make_request(URL);
		window.document.getElementById("preview").style.visibility = "visible";
		window.document.getElementById("preview").style.display = "block";
		window.document.getElementById("preview").style.zIndex = "99";
		window.document.getElementById("preview").innerHTML = "<img src=\""+URL+"\" border=\"0\" />";
		}
 }

function hide()
 {
	if (loaded == 1)
		{
		window.document.getElementById("preview").style.visibility="hidden";
		window.document.getElementById("preview").style.display="none";
		}
 }
 

function make_request(url) {
var xmlhttp=false;
	if(window.XMLHttpRequest){
		try {xmlhttp = new XMLHttpRequest();}
		catch(e) {xmlhttp = false;window.document.getElementById("preview").innerHTML = "<div align='center'><strong>Error</strong><br /><br>cannot create or handle request</div>";}
	}
	else if(window.ActiveXObject){
		try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
	 	catch(e) {
			try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
				catch(e) {xmlhttp = false;window.document.getElementById("preview").innerHTML = "<div align='center'><strong>Error</strong><br /><br>cannot create or handle request</div>";}
		}
	}

	try {xmlhttp.open("GET",url,true);}
		catch(e) {window.document.getElementById("preview").innerHTML = "<div align='center'><strong>Security block</strong><br /><br>data cannot be loaded from other domain</div>";return false;}
	xmlhttp.onreadystatechange=function(){
		stav(xmlhttp);}
	xmlhttp.send(null);
	return false;
}


function stav(xmlhttp) {
	try{if (xmlhttp.readyState==4) {if (xmlhttp.status==200) {parseImage(xmlhttp.responseText);}
		else if (xmlhttp.status==404) {alert ("Sorry, no response");xmlhttp.abort();}
		else {return false;}
		}
	}
	catch(e){alert ("No images found or other error: "+e);}
}


function parseImage(feedBack)
	{
			window.document.getElementById("preview").innerHTML = "";
			window.document.getElementById("preview").innerHTML = "<img src=\""+feedBack+"\" border=\"0\" />";
	}


function parseText(feedBack)
	{
			window.document.getElementById("preview").innerHTML = "";
			window.document.getElementById("preview").innerHTML = "<span>Detail</span>";
			var returned = feedBack.substring(0,feedBack.length);
			var records = returned.split(';');
			var countRec = records.length;
			for (var i=0; i<countRec-1;i++)
				{
					var record = records[i].split(':');
					if (record[0] == "" || record[0] == " " || record[0] == null) record[0] = "&nbsp";
					if (record[1] == "" || record[1] == " " || record[1] == null) record[1] = "&nbsp";
					window.document.getElementById("preview").innerHTML += "<span class = 'leftDetail'>" + record[0] + "</span><span class = 'rightDetail'>" + record[1] + "</span>"; 
				}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
