/*******************************************************************************
*                   AJAX POP-UP-WINDOW v.1.1
*                       08.11.2006
*                       20.05.2006
*                     Martin Korbel
*******************************************************************************/
var pop_up_window = new Object();
  pop_up_window.dir = '';
  pop_up_window.style = 'window';
  pop_up_window.imgWidth = 0;
  pop_up_window.imgHeight = 0;
  pop_up_window.imgSize = 0;
  pop_up_window.window = null;
  pop_up_window.winWidth = 0;
  pop_up_window.winHeight = 0;
  pop_up_window.positionX = 0;
  pop_up_window.positionY = 0;
  pop_up_window.pageHeight = 0;
  pop_up_window.pageWidth = 0;
  pop_up_window.winParms = 'resizable=yes, scrollbars=yes, channelmode=no, fullscreen=no, directories=no, location=no, menubar=no,';
  pop_up_window.infoScript = 'ajax_getinfo.php';
  pop_up_window.resizableScript = 'image.php';
  pop_up_window.resizable = 'auto';  
  pop_up_window.maxSize = 1024;      // Maximalni velikost soubory pri, ktere obrazek neni zmensen scriptem

pop_up_window.show = function (imageURL,parms) {
 if(!ajax) {
  alert("Error: Not found ajax library! Please load library.");
  return false;
 }

 var url = pop_up_window.dir+pop_up_window.infoScript;
 var param = 'file='+encodeURIComponent(imageURL)+'&path='+encodeURIComponent(pop_up_window.dir);
// document.getElementsByTagName('H1')[0].innerHTML = url+'?'+param;
 ajax.send(url,param,'XML',
  function(xml){
    if(xml) {
     // Zjisteni velikosti obrazku
     
     var Width = xml.getElementsByTagName('WIDTH');
     if(Width.length==0) return false;
     pop_up_window.imgWidth = parseInt(Width[0].firstChild.data);
     
     var Height = xml.getElementsByTagName('HEIGHT');
     pop_up_window.imgHeight = parseInt(Height[0].firstChild.data);
     
     var Size = xml.getElementsByTagName('SIZE');
				 pop_up_window.imgSize = parseInt(Size[0].firstChild.data)
     
     if(pop_up_window.style == 'window') {
      pop_up_window.winWidth = pop_up_window.imgWidth;
 				 pop_up_window.winHeight = pop_up_window.imgHeight;
      // Upravavelikosti okna
      if(pop_up_window.winWidth>screen.availWidth) pop_up_window.winWidth=screen.availWidth;
      if(pop_up_window.winHeight>(screen.availHeight-150)) pop_up_window.winHeight=(screen.availHeight-150);
      // Nastaveni polohy okna
      pop_up_window.positionX = (screen.availWidth - pop_up_window.winWidth)/2;
      pop_up_window.positionY = (screen.availHeight - pop_up_window.winHeight)/2;
       
      // Nastaveni zdroje obrazku
      var url = imageURL;
      if(pop_up_window.resizable==true || pop_up_window.resizable=='true' || (pop_up_window.resizable=='auto' &&  pop_up_window.imgSize > pop_up_window.maxSize)) {
        url = pop_up_window.dir+pop_up_window.resizableScript + '?';
        url = url+'path='+pop_up_window.dir+'&src='+imageURL+'&original=1';
      }
      // Tvorba a zobrazeni okna
      var  imgwin = document.open(url,'_blank',pop_up_window.winParms+'width='+pop_up_window.winWidth+',height='+pop_up_window.winHeight+',left='+pop_up_window.positionX+',top='+pop_up_window.positionY);
      //imgwin.document.onclick = function() { imgwin.window.close();};
      pop_up_window.window = imgwin;
     }else{
     
       // Cela delka dokumentu
       if(pop_up_window.pageHeight == 0) {
        pop_up_window.pageHeight = document.body.scrollHeight;
						  pop_up_window.pageWidth = document.body.clientWidth;
						 }

       var html = document.getElementsByTagName('HTML')[0];
       html.style.position = 'absolute';
       html.style.top = '0px';
       html.style.left = '0px';
       html.style.height = '100%';
       html.style.width = '100%';
//       html.style.padding = '0px';
       document.body.style.position = 'absolute';
       document.body.style.top = '0px';
       document.body.style.left = '0px';
       document.body.style.height = '100%';
       document.body.style.width = '100%'; 
 						// Pokud nebyl dokument velky jako okno,tak ho prenastavime
 						if(pop_up_window.pageHeight < document.body.clientHeight) {
        pop_up_window.pageHeight = document.body.clientHeight;
						 }
						 if(pop_up_window.pageWidth < document.body.clientWidth) {
						  pop_up_window.pageWidth = document.body.clientWidth;
 						}
 						// Jen zobrazena cast dokumentu
       if(pop_up_window.winHeight == 0) {
        pop_up_window.winHeight = winH();
        pop_up_window.winWidth = winW();
       }

       var max_size = false;
       if(document.getElementById('pop_up_image_box')) return false;
							// Schovani vsech selectu
       selects = document.getElementsByTagName('SELECT');
       for(iLoop=0;iLoop<selects.length;iLoop++) {
        selects[iLoop].style.display = 'none';
       }
       // Vypocitame pomer zmenseni
       var pomer = pop_up_window.imgWidth/pop_up_window.imgHeight;
              
       if(pop_up_window.imgHeight>(pop_up_window.winHeight-100)) {
          pop_up_window.imgHeight=pop_up_window.winHeight-100;
          pop_up_window.imgWidth = Math.round(pop_up_window.imgHeight * pomer);
          max_size = true;
       }

       if(pop_up_window.imgWidth>(pop_up_window.winWidth-30)) {
          pop_up_window.imgWidth = (pop_up_window.winWidth-30);
          pop_up_window.imgHeight = Math.round(pop_up_window.imgWidth * ( 1 / pomer ));
          max_size = true;
       }
       //alert(html.scrollTop)
       pop_up_window.positionX = Math.round((pop_up_window.winWidth - pop_up_window.imgWidth)/2) + html.scrollLeft;
       pop_up_window.positionY = Math.round((pop_up_window.winHeight - pop_up_window.imgHeight)/2)  + html.scrollTop;
							
       bgbox = document.createElement('DIV');
       document.body.appendChild(bgbox);
	      bgbox.id = 'pop_up_overlay';
       bgbox.style.display = 'none';
       bgbox.style.zIndex = '1001';
       bgbox.style.position = 'absolute';
       bgbox.style.top = '0px';
       bgbox.style.left = '0px';
       bgbox.style.width = pop_up_window.pageWidth+'px';      
       bgbox.style.height = pop_up_window.pageHeight+'px';
       bgbox.style.backgroundColor = '#000';
       
       bgbox.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)"; 
       bgbox.style.MozOpacity = 0.5;
       bgbox.style.opacity = 0.5;

       box = document.createElement('DIV');
       document.body.appendChild(box);
       box.id = 'pop_up_image_box';
       box.style.display = 'none';
       box.style.zIndex = '1004';
       box.style.position = 'absolute';
       box.style.top = pop_up_window.positionY+'px';
       box.style.left = pop_up_window.positionX+'px';
       box.style.width = (pop_up_window.imgWidth+20)+'px';
       box.style.height = (pop_up_window.imgHeight+40)+'px';
       box.style.backgroundColor = '#FFF';
       box.style.textAlign = 'center';
       box.style.border='1px #000 solid';
       img = document.createElement('IMG');
       box.appendChild(img);

       img.style.margin = '20px 10px 20px 10px';
       var def = 0;
       if(max_size) {
        def = 20;
       }
       img.height = pop_up_window.imgHeight-def;
       img.width = pop_up_window.imgWidth-def;
       // Nastaveni zdroje obrazku
       var url = imageURL;
       if(pop_up_window.resizable==true || pop_up_window.resizable=='true' || (pop_up_window.resizable=='auto' &&  pop_up_window.imgSize > pop_up_window.maxSize)) {
        url = pop_up_window.dir+pop_up_window.resizableScript + '?';
        url = url+'path='+pop_up_window.dir+'&src='+imageURL+'&width='+(pop_up_window.imgWidth-def)+'&height='+(pop_up_window.imgHeight-def);
       }
       //alert(url);
       img.src = url; 
       
       img.title = 'Zavrit okno';
      
       img.onclick = function() {
        bgbox.style.display = 'none';
        box.style.display = 'none';        
        box.removeChild(img);
        document.body.removeChild(box);
        document.body.removeChild(bgbox);
        selects = document.getElementsByTagName('SELECT');
        for(iLoop=0;iLoop<selects.length;iLoop++) {
         selects[iLoop].style.display = 'block';
        }
       }
       bgbox.style.display = 'block';
       box.style.display = 'block';       
       pop_up_window.winindow = box;
     }
  }
  return 1;
 });
  
  return 1;
}

function winH() {
   if (window.innerHeight)
      /* NN4 a kompatibilni prohlizece */
      return window.innerHeight;
   else if
   (document.documentElement &&
   document.documentElement.clientHeight)
      /* MSIE6 v std. rezimu - Opera a Mozilla
      jiz uspely s window.innerHeight */
      return document.documentElement.clientHeight;
   else if
   (document.body && document.body.clientHeight)
      /* starsi MSIE + MSIE6 v quirk rezimu */
      return document.body.clientHeight;
   else
      return null;
}

function winW() {
   if (window.innerWidth)
      /* NN4 a kompatibilni prohlizece */
      return window.innerWidth;
   else if
   (document.documentElement &&
   document.documentElement.clientWidth)
      /* MSIE6 v std. rezimu - Opera a Mozilla
      jiz uspely s window.innerHeight */
      return document.documentElement.clientWidth;
   else if
   (document.body && document.body.clientWidth)
      /* starsi MSIE + MSIE6 v quirk rezimu */
      return document.body.clientWidth;
   else
      return null;
}