window.onload=initImg;
function initImg(){
  cur=0;
  get_imgs();
}
function next(){
  cur++; 
  if(imagini.length<=cur) cur=0;
    
  var im_det=document.getElementById("img_det");
  im_det.value=" Se incarca...";
  newImg= new Image();
  newImg.src="gen_img.php?i="+imagini[cur];
  waitFor(newImg);
}
function backimg(){
  cur--;
  if(cur<0) cur=imagini.length-1;
  var im_det=document.getElementById("img_det");
  im_det.value=" Se incarca...";
  newImg= new Image();
  newImg.src="gen_img.php?i="+imagini[cur];
  waitFor(newImg);
}

function waitFor(img){ 
	if(!img.complete){ 
	   imgWait=setTimeout(function(){waitFor(img)}, 250); 
	} 
	else{ 
	   chImg(img);
	} 
} 

function chImg(img){
  var im=document.getElementById("img");
  im.src=img.src;
  var im_det=document.getElementById("img_det");
  im_det.value=imagini_d[cur];
}


function imgBig(){
   url="show_big_im.php?img="+imagini[cur];
   window.open(url,"myw","status=no,location=no,menubar=no,resizable=yes,width=1000,height=600");	
}

function get_imgs(){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request");
	 return;
	 }
	var url="get_img.php";
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
      var resp=xmlHttp.responseText; 
	  resp=resp.split("<#>");
	  set_img(resp[0],resp[1]);
 } 


}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


function set_img(img,det){
	imagini=img.split("<+>");
	imagini_d=det.split("<+>");
}
