

function newelement_foto(newid)			// v pripade, ze jeste nebyl vytvoren element <div id="tooltip_foto">, tato funkce jej vytvori
{   
    	 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
	        el.onmouseover= new Function('clearTimeout(timeout_id)');
	        //el.onmouseout= new Function('countdown_foto()');
          el.id = newid;     
          
          el.style.display = 'none';
          el.style.position = 'absolute';
	        //el.style.opacity= '0.0';
          //el.innerHTML = '&nbsp;'; 
          document.body.appendChild(el); 
    } 
} 
function countdown_foto()			//fce pro zajisteni 'zmizeni' tooltip_fotou za uplynulou dobu v milisekundach
{	is_countdown_foto=true;
    	timeout_id=setTimeout('disappear_foto(); is_countdown_foto=false;',1000);
}
function tooltip_foto(object)			// vytvoreni tooltipu, umisteni a jeho zviditelneni v okne prohlizece
{   
    if(visible)     // jestlize uz je zobrazeny jinde, nebudeme otevirat novy tooltip
        return;
        
    var x=findPosX(object); 
    var y=findPosY(object);	
    x=x+object.offsetWidth;			// pozice zobrazovaneho tooltipu
    	
    //object.onmouseout= new Function('countdown_foto()');
	
    if(!document.getElementById('tooltip_foto')) 
	     newelement_foto('tooltip_foto');
    
    if (is_countdown_foto)				//jestlize se ma objevit novy tooltip, timeout pro zmizeni po 5ti vterinach se rusi
	     clearTimeout(timeout_id);
			
    var my_tooltip_foto = document.getElementById('tooltip_foto');

    var reakce_na=object.getAttribute('reakce');    
	                     
                       // vytvoreni tabulky pro oramovani tooltipu
    var prvni_cast_tabulky  = '<table><tr><td id=t1></td><td id=t2></td><td id=t3></td></tr><tr><td id=t4></td><td id=t5>';

    var formular= '	 <fieldset id="formular">' +
                        
                  '      <table> '+
                  '      <tr><td> <textarea class="same" id="text_popis" rows="4" cols="40"></textarea> </td></tr>'+
  		          
                  '      </td></tr> '+
                  '      <tr><td> '+
                  '      <input id="button" type="submit" name="button" value="Odeslat" onClick=ulozZpravu($F("text_popis"),$F("title_popis"),$F("parent_popis"),$F("user_popis"),$F("id_fotky_popis")) ;> </td></tr> '+
                  '      <tr> '+
                  '      <td><input id="buttonClose" type="submit" name="buttonClose" value="Zavřít" onclick="disappear_foto(); return false;" > '+
                  
                  '      </td></tr></table> '+
                  '      </fieldset>';
    
    var druha_cast_tabulky  = '</td><td id=t6></td></tr><td id=t7></td><td id=t8></td><td id=t9></td></tr></table>';
                        // vlozeni kodu do tooltipu
    my_tooltip_foto.innerHTML = prvni_cast_tabulky+formular+druha_cast_tabulky;
    
    //my_tooltip.style.display = 'block';     // zobrazeni tooltipu
    my_tooltip_foto.style.left = x+'px';         // umisteni tooltipu
    my_tooltip_foto.style.top = y+'px';	
    appear_foto();
}



function findPosX(obj)			//fce pro vypocet vzdalenosti elementu od leveho okraje okna (pro vsechny prohlizece)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)			//fce pro vypocet vzdalenosti elementu od horniho okraje okna (pro vsechny prohlizece)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function disappear_foto(){
	opacity=1.0;
	visible=false;
	//id_intervalu=window.setInterval('document.getElementById(\'tooltip\').style.opacity = opacity; opacity=opacity-0.1; if (opacity<=0){ window.clearInterval(id_intervalu); document.getElementById(\'tooltip\').style.display = \'none\';}',100);
	document.getElementById('tooltip_foto').style.display = 'none';
}

function appear_foto(){
        opacity=0.0;
        visible=true;
	      document.getElementById('tooltip_foto').style.display = 'block';
        //id_intervalu=window.setInterval('document.getElementById(\'tooltip_foto\').style.opacity = opacity; opacity=opacity+0.1; if (opacity>0.9){ window.clearInterval(id_intervalu); }',100);

}

function getElementsByAttribute(strAttributeName){
    var arrElements = document.getElementsByTagName('*');
    var arrReturnElements = new Array();
    var oCurrent;
    var oAttribute;
    for(var i=0; i<arrElements.length; i++){
        oCurrent = arrElements[i];
        oAttribute = oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0)
                arrReturnElements.push(oCurrent);
        
    }
    return arrReturnElements;
}


function ulozZpravu(text_popis, title_popis, parent_popis, user_popis, id_fotky_popis){
	
		//alert(user_popis);
		var url = 'insert_popis.php';
		var pars = 'text=' + text_popis + '&title=' + title_popis + '&user=' + user_popis+'&id_fotky=' + id_fotky_popis;
		
		var myAjax = new Ajax.Request(
			url, 
			{
				method: 'post', 
				postBody: pars, 
				onComplete: showResponse
			});
		
	}

	function showResponse(originalRequest)
	{
		
		$('text_popisu').innerHTML = originalRequest.responseText;
	}




//------------------- inicializace tooltip_foto elementů --------------------

function add_attribs_to_tip_foto(){
	   
	var list = getElementsByAttribute('zmenit_popis');
    	if (! list)
        	return;
  //window.status='setting_attribs';
              	
    	for (var i = 0; i < list.length; ++i){
    	//window.alert('Element no '+i); 
    	list[i].onclick=new Function('tooltip_foto\(this\)');
		Element.addClassName(list[i],'tip_foto');
	}
		
}

document.writeln('<link rel="stylesheet" type="text/css" href="./js/reakce/style.css" >');

var timeout_id;
var id_intervalu;
var is_countdown_foto=false;
var opacity;
var visible=false;

Event.observe(window, 'load', add_attribs_to_tip_foto);



