/* Photos related functions
   (c)2009 Jakub Holotík: E-lion*/
var clicked_something_else;
function phGlance(id,cur_x){
   obj=document.getElementById(id);
   if(!obj) return;
   n_pos=cur_x+10;
   if(n_pos<240){
      obj.style.backgroundPosition=n_pos+' 50%';
      window.setTimeout("phGlance('"+id+"',"+n_pos+");",40);
   }
}

function phMouseOver(obj){
   hold=obj.parentNode;
   hold.style.width=hold.offsetWidth+4+'px';
   hold.style.height=hold.offsetHeight+4+'px';
   hold.style.backgroundPosition='2px 2px';
   hold.parentNode.parentNode.parentNode.style.fontWeight='bold';
   phGlance(obj.id,-137);
}

function phMouseOut(obj){
   hold=obj.parentNode;
   hold.style.width=hold.offsetWidth-4+'px';
   hold.style.height=hold.offsetHeight-4+'px';
   hold.style.backgroundPosition='0px 0px';
   hold.parentNode.parentNode.parentNode.style.fontWeight='normal';
}

function phClick(ide){
   fader.style.display='block';
   phLoad(ide);
}

var ph_http;
var c_ph=new Image();
c_ph.onload=function(){if(ph_http.readyState==4 && ph_http.status==200) eval(ph_http.responseText);};

function phLoad(id){
   c_ph.src='../photos/orig/'+id+'.jpg';
   document.getElementById('fader_in').style.background='url(grfx/loader.gif) 50% 50% no-repeat';
   ph_http=new XMLHttpRequest();
   ph_http.onreadystatechange=phLoaded;
   ph_http.open("GET",'fotky_s.php?id='+id,true);
   ph_http.send(null);
}

function phLoaded(){
   if(ph_http.readyState==4){
      if(ph_http.status==200){
         if(c_ph.complete)eval(ph_http.responseText);
      }
      else {
         alert("Error "+ph_http.status+"<br>"+ph_http.responseText);
      }
   }
}

function faderHide(){
   if(clicked_something_else){
      clicked_something_else=false;
      return;
   }
   fader.style.display='none';
   var fader_in=document.getElementById('fader_in');
   fader_in.innerHTML='';
   fader_in.style.height='100%';
   fader_in.style.background='url(grfx/loader.gif) 50% 50% no-repeat';
}

var ph_int;

function phResize(){
   var fader_in=document.getElementById('fader_in');
   var nh=fader_in.offsetHeight+20;
   var nw=fader_in.offsetWidth+20;
   var ext=0;
   if(nh>fader_in.parentNode.offsetHeight) ext++;
   else fader_in.style.height=nh+'px';
   if(nw>fader_in.parentNode.offsetWidth) ext++;
   else fader_in.style.width=nw+'px';
   if(ext==2)clearInterval(ph_int);
}

function phNext(idr){
   clicked_something_else=true;
   phLoad(idr);
   itemHide(document.getElementById('fader_in'));
}

function phPreload(idr){
   var img=new Image();
   img.src='../photos/orig/'+idr+'.jpg';
}
