var W3CDOM = (document.createElement && document.getElementsByTagName);
var nav = new Array();
var as = new Array();
var div = new Array();
var divs = new Array();
var aheights = new Array();
var print = new Array()
window.onload = init;



function init()
{
	       if (!W3CDOM) return;
	        new_window_link();
 
          findImages();
          
	       }
	


      
       var path_to_icon 		= 'http://www.rusnuclear.cz/images/icon.gif';
			 var link_alt_text 		= 'Otevřít odkaz v novém okně';
			 var link_title_text 	= 'Otevřít odkaz v novém okně';

			function new_window_link() {
			  
				if (!document.getElementById || !document.createTextNode || !document.domain || !document.getElementById('text')) return;
				
        var text = document.getElementById('text');
        var linx = text.getElementsByTagName('a');
       
				for (var i = 0; i < linx.length; i++) {

					// just for off-site links
					
			    if(linx[i].protocol == 'http:'){
					if (linx[i].href.split('/')[2].replace(/www\./, '') != document.domain.replace(/www\./, '')
						&& !linx[i].getAttribute('target')
						&& !linx[i].parentNode.id.match(/^copy/)) {

						// create new elements
						var nwl = document.createElement('a');
						var nwl_image = document.createElement('img');
						var space = document.createTextNode(' ');

						// setup image attributes
						nwl_image.setAttribute('src', path_to_icon);
						nwl_image.setAttribute('alt', link_alt_text);
						nwl_image.setAttribute('title', link_title_text);

						// set link attributes
						nwl.setAttribute('href', linx[i].getAttribute('href'));
						nwl.setAttribute('target', '_blank');
						nwl.setAttribute('title', link_title_text);
						nwl.className = 'new_window_link';

						// append new elements
						nwl.appendChild(nwl_image);
						linx[i].parentNode.insertBefore(space, linx[i].nextSibling);
						linx[i].parentNode.insertBefore(nwl, linx[i].nextSibling.nextSibling);
					}
				}
			
				}
			}

function findImages(){
    if(document.getElementById('content')){
    var images_div = document.getElementById('content');
    var as = images_div.getElementsByTagName('a');
    for(var foo = 0; foo < as.length; foo++){			
    if(as[foo].id){
    as[foo].number  = as[foo].id;
    as[foo].onclick = workImage;
    }		
    }
    }
}   

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
    return myHeight;
}

function workImage(){
    var stringfrom = this.number;  
    var splits = new Array();
    splits = stringfrom.split('-');
    var order = splits[0];
    var imagename = splits[1];
    var imagew = splits[2];
    var imageh = splits[3]; 

    if(document.getElementById('printgalerie')){ 
    var overlayscroll = (document.documentElement.scrollTop);
    }
    
    var monitor = alertSize()-40;
    if(monitor > imageh){
    var mtop = -(imageh/2);
    var vyska = imageh;
    }
    else{
    var mtop = -(monitor/2)
    var vyska = monitor;
    }
    
    mtop = mtop + overlayscroll - 15 ;
    if(document.getElementById('printgalerie')){ document.getElementById('printgalerie').style.height = vyska+'px'; }
    
    newheight = vyska-20;
    
    var newidth = imagew/(imageh/newheight);
    
    var mleft = newidth/2;

       
    if(document.getElementById('printgalerie')){ document.getElementById('printgalerie').style.marginTop = mtop+'px'; }
    if(document.getElementById('printgalerie')){ document.getElementById('printgalerie').style.marginLeft = '-'+mleft+'px'; }
    
        url='../pages/openpicture.php?imageid='+imagename+'&newheight='+newheight;
        
      
        if (window.ActiveXObject)
        {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", url, true);

        httpRequest.onreadystatechange= function () {processRequest(); } ;
        httpRequest.send(null);
      


    return false;
} 

function processRequest()
{

   
  
  if (httpRequest.readyState == 4)
  {
    if(httpRequest.status == 200)
    {
      
      buildGalery();
      var semka = document.getElementById("printgalerie");
      semka.innerHTML = httpRequest.responseText;
         
    
    
    }
    else
    {
        alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}


function buildGalery(){

   
   var overlayheight = (document.body.clientHeight);

   
   
   if(document.getElementById('overlay')){ document.getElementById('overlay').style.display = 'block'; }
   if(document.getElementById('overlay')){ document.getElementById('overlay').style.height = overlayheight + 'px'; }
   if(document.getElementById('printgalerie')){ document.getElementById('printgalerie').style.display = 'block'; }
   
}

function killImage(){
   if(document.getElementById('overlay')){ document.getElementById('overlay').style.display = 'none'; }
   if(document.getElementById('printgalerie')){ document.getElementById('printgalerie').style.display = 'none'; }
}

