var last_opis=-1;

function printOpisGlosy(i){
  if(i!=last_opis){
    var image_html="";
	if(xmlDoc.getElementsByTagName("glos")[i].attributes[1].nodeValue==1){
	  image_html="<img class=\"glosy\" align=\"left\" src=\"glosy.img.php?id="+xmlDoc.getElementsByTagName("glos")[i].attributes[0].nodeValue+"\"><br/>";
	}
	document.getElementById("glos_title"+i).style.border="2px solid #f20000";
	document.getElementById("glos_title"+i).style.borderWidth="0px 0px 2px 0px";
	document.getElementById("glos_title"+i).style.padding="2px";
	document.getElementById("glos_title"+i).style.textAlign="right";
	document.getElementById("a_title"+i).style.color="#f20000";
	document.getElementById("glos_content"+i).innerHTML=image_html+xmlDoc.getElementsByTagName("glos")[i].childNodes[1].childNodes[0].nodeValue;
	if(last_opis!=-1){
	  document.getElementById("glos_title"+last_opis).style.borderColor="#ffffff";
	  document.getElementById("glos_title"+last_opis).style.padding="0px";
	  document.getElementById("glos_title"+last_opis).style.textAlign="left";
	  document.getElementById("a_title"+last_opis).style.color="#000000";
	  document.getElementById("glos_content"+last_opis).innerHTML="";
	}
	last_opis=i;
  }
}

function glosy(){ 
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Sorry, Your browser doesnt support AJAX! Get Update.");
    return;
  }
  xmlHttp.onreadystatechange=function(){
	if (xmlHttp.readyState==4 ){
	  xmlDoc=xmlHttp.responseXML.documentElement;
	  // DRUKOWANIE
	  var r="<table id=\"glosy\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody>";
	  for(var i=0;i<xmlDoc.getElementsByTagName("glos").length;i++){
		var glos=xmlDoc.getElementsByTagName("glos")[i];
		r+="<tr><td id=\"glos_title"+i+"\"><a id=\"a_title"+i+"\" class=\"glosy\" onClick=\"printOpisGlosy("+i+");\" href=\"#\">";
		r+=glos.childNodes[0].childNodes[0].nodeValue+"</a></td></tr>";
		r+="<tr><td class=\"glos_content\" id=\"glos_content"+i+"\"></td></tr>";
	  }
	  r+="</tbody></table>";
	  document.getElementById("glosy").innerHTML=r;
	  // DRUKOWANIE
	  clearTimeout(t);
	}
  };
  xmlHttp.open("GET","glosy.xml.php",true);
  xmlHttp.send(null);
  t=setTimeout('glosy()',timeout);
}

