/*

tohle prijde do hlavicky
    <script src="ajaxhint/ajaxHint.js"></script> 

takhle nejak by melo vypadat body
    <body onload="ajaxHintRun();">   
    
a tohle staci pripsat k elementum ktere chcete hintovat; pro priklad uvedena tabulka projekt s id=15)
    ajaxWindow="projekty;id;15"
    

s pozdravem Bogan

*/

function ajaxWindowRun(click){
  var v=ajaxWindowgetElementsByAttribute(document,'*','ajaxWindow','*');
  for (var o in v) {
    ob=v[o];
    ajaxWindowOver = ob.getAttribute('ajaxWindowOver');
    
    if (click && !ajaxWindowOver) {
      if (IE) ob.attachEvent('onclick',ajaxWindowTimeToShow); else ob.addEventListener('click',ajaxWindowTimeToShow,false);
    } else {
      if (IE) ob.attachEvent('onmousemove',ajaxWindowTimeToShow); else ob.addEventListener('mousemove',ajaxWindowTimeToShow,false);
      if (IE) ob.attachEvent('onmouseout',ajaxWindowAbortWindow); else ob.addEventListener('mouseout',ajaxWindowAbortWindow,false);
    }
  }
  var b=document.getElementsByTagName('body')[0];
  ajaxWindowWindow = document.createElement('DIV');
  ajaxWindowWindow.style.position='absolute';
  ajaxWindowWindow.style.zIndex='15';
  ajaxWindowWindow.style.backgroundColor='white';
  ajaxWindowWindow.style.color='black';
  ajaxWindowWindow.style.border='1px solid black';
  ajaxWindowWindow.style.fontFamily='Verdana';
  ajaxWindowWindow.style.fontSize='90%';  
  ajaxWindowWindow.style.display='none';   
  if(ajaxWindowOver){
    if (IE) ajaxWindowWindow.attachEvent('onmouseout',ajaxWindowTimeToHide); else ajaxWindowWindow.addEventListener('mouseout',ajaxWindowTimeToHide,false);
  }
  
  if (IE) ajaxWindowWindow.attachEvent('onmouseover',ajaxWindowStayVisible); else ajaxWindowWindow.addEventListener('mouseover',ajaxWindowStayVisible,false);
  b.appendChild(ajaxWindowWindow);
}

function ajaxWindowGetData(otazka){
  ajaxWindowWindow.innerHTML='nahravají se data';
  var hlavicka = document.getElementsByTagName('head')[0];
  var dataLoader = document.getElementById('ajaxWindowLoader');
  if (dataLoader) hlavicka.removeChild(dataLoader);
	script = document.createElement('script');
	script.id = 'ajaxWindowLoader';
	script.src = ajaxWindowAbsoluteUrl+'ajaxWindow/ajaxWindow.php?get='+otazka;
	//alert(script.src);
 	x = document.getElementsByTagName('head')[0];
  x.appendChild(script);
}
    
function ajaxWindowgetElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
  var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
  var arrReturnElements = new Array();
  var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
  var oCurrent;
  var oAttribute;
  for(var i=0; i<arrElements.length; i++){
      oCurrent = arrElements[i];
      if (oCurrent.getAttribute) {
        oAttribute = oCurrent.getAttribute(strAttributeName);
        if(typeof oAttribute == "string" && oAttribute.length > 0){
            if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
                arrReturnElements.push(oCurrent);
            }
        }
      }
  }
  return arrReturnElements;
}

function ajaxWindowFindElement(o){
  while (o.getAttribute('ajaxWindow')==null){
    o=o.parentElement;
  }
  return o;
}

function ajaxWindowTimeToShow(e){
  //alert(e);
  if (ajaxWindowWindow.style.display=='block') return;
  
  clearTimeout(ajaxWindowTimerIn);
  var o=null;
  var px = 0;
  var py = 0;
  if (IE) { 
    o=ajaxWindowFindElement(e.srcElement);
    px = e.clientX + document.body.scrollLeft;
    py = e.clientY + document.body.scrollTop;
  } else { 
    o=e.currentTarget;
    px = e.pageX;
    py = e.pageY;
  } 
  ajaxWindowWindow.style.left=px-10;
  ajaxWindowWindow.style.top=py-10;
  //alert('ajaxWindowShow(\''+o.getAttribute('ajaxWindow')+'\')');
  ajaxWindowTimerIn=setTimeout('ajaxWindowShow(\''+o.getAttribute('ajaxWindow')+'\')',IE ? 800 : 100);
}

function ajaxWindowShow(data){
  ajaxWindowGetData(data);
  ajaxWindowStayVisible();
  ajaxWindowTimerDie=setTimeout('ajaxWindowHide()',30000);
}

function ajaxWindowStayVisible(){
  clearTimeout(ajaxWindowTimerOut);
  clearTimeout(ajaxWindowTimerDie);
  ajaxWindowWindow.style.display='block';
}

function ajaxWindowTimeToHide(){
  clearTimeout(ajaxWindowTimerOut);
  ajaxWindowTimerOut=setTimeout('ajaxWindowHide()',100);
}

function ajaxWindowAbortWindow(){
  clearTimeout(ajaxWindowTimerIn);
}

function ajaxWindowHide(){
  clearTimeout(ajaxWindowTimerOut);
  ajaxWindowWindow.style.display='none';
}


var IE = document.all ? true : false;
var ajaxWindowWindow=null;
var ajaxWindowTimerIn=null;
var ajaxWindowTimerOut=null;
var ajaxWindowTimerDie=null;
var ajaxWindowOver=null;

