//** remade by P@X@N **//

function showAll(theTarget) {
	var theBody = document.getElementsByTagName('body')[0];
	var pageCoords = getPageCoords();

	var theShadow = document.createElement('div');
	theShadow.id = 'shadow';
	theShadow.style.height = (pageCoords[1] + 'px');
	theShadow.className = 'on';
	theBody.insertBefore(theShadow, theBody.firstChild);

	var theLoading = document.createElement('div');
	theLoading.id = 'loading';
	theLoading.style.top = parseInt(document.documentElement.clientHeight/ 2)+ 'px';
	theLoading.onclick = function() { closeAll(); }
	theShadow.appendChild(theLoading);

	var imgPreload = new Image();
	imgPreload.onload = function() {
		var theBox = document.createElement('div');
		theBox.id = 'window';
		theBox.style.width = imgPreload.width + 10 + 'px';
//		theBox.style.marginTop = parseInt(pageCoords[2] + (pageCoords[0] - imgPreload.height - 50) / 2) +200+ 'px';
//  		RDS-61 fix
		var marginTop = parseInt(pageCoords[2] + (pageCoords[0] - imgPreload.height - 150) / 2) +200;
		theBox.style.marginTop = ((marginTop < 10)? 10 : marginTop) + "px";


		var theImage = document.createElement('img');
		theImage.src = theTarget.href;
		theImage.alt = theTarget.title;
		theImage.width = imgPreload.width;
		//theImage.onclick = function() {  closeAll();
						//return false;
	  					//}
	  												
//		theImage.title = "??????? ????";


		var theClose = document.createElement('a');
		theClose.className = 'close';
		theClose.title = 'Закрыть';
		theClose.style.marginLeft = theImage.width-21+'px';
                theClose.onclick = function() { closeAll(); return false; }
        	theBox.insertBefore(theClose, theBox.firstChild);	  					


		theShadow.removeChild(theLoading);
		theBox.appendChild(theImage);
		theShadow.appendChild(theBox);

		document.onkeypress = getKey;
		return false;
	}
	imgPreload.src = theTarget.href;
}

function getPageCoords() {
     var coords = [0, 0, 0]; // height of window, document, scroll pos
     // all except IE
     if (window.innerHeight) {
          coords[0] = 0;//window.innerHeight;
          coords[2] = window.pageYOffset;          
          coords[1] = realHeight; 
//          alert(realHeight);	             
     }
     // IE 6 Strict
     else if (document.documentElement && document.documentElement.clientHeight != 0) {
          coords[0] = document.documentElement.clientHeight;
          coords[2] = document.documentElement.scrollTop;
          coords[1] = realHeight - 800;
     }
     else if (document.body) {
          coords[0] = document.body.clientHeight;
          coords[2] = document.body.scrollTop;
     }

     var test1 = document.body.scrollHeight;
     var test2 = document.body.offsetHeight;
     if (test1 > test2) {
          coords[1] = document.body.scrollHeight;
     } else {
//          coords[1] = document.body.offsetHeight;
             coords[1]=coords[1]+coords[0];                    
     }
//     if (coords[1] < coords[0]) coords[1] = coords[0];

     return coords;
}

function closeAll() {
	var theBody = document.getElementsByTagName('body')[0];
	var theBox = document.getElementById('window');
	if (theBox) theBox.style.display = 'none';
	var theShadow = document.getElementById('shadow');
	if (theShadow) theShadow.style.display = 'none';
	theBody.removeChild(theShadow);

	selects = document.getElementsByTagName('select');
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = 'visible';
	}
	document.onkeypress = '';
	imgPrev = imgNext = '';
	return false;
}

function getKey(e) {
	var arrowImg;

	if (!e) var e = window.event;
	var keycode = e.keyCode ? e.keyCode : e.which;

	switch (keycode) {
  	case 27: // esc
  	          closeAll();
	}
	if (arrowImg) { closeAll(); showAll(arrowImg); }
	return false;
}

function initAll() {
	if (!document.getElementsByTagName) { return; }
	var anchors = document.getElementsByTagName('a');

	for (i=0,len=anchors.length; i<len; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == 'window')) {
			anchor.onclick = function() { showAll(this); return false; }
		}
	}
	anchor = null;
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			//oldonload();
			func();
		}
	}
}

var time_green=0;
var global_time=0;

function blinkGreenPlan() {
var green=document.getElementById('green_hall');
var green2=document.getElementById('green_hall2');
var blue=document.getElementById('blue_hall');
var blue2=document.getElementById('blue_hall2');
if (time_green==1) { time_green=0;
                     green.style.display="block"; 
		     green2.style.display="none";
                     blue2.style.display="block"; 
		     blue.style.display="none";		     		      
		     		      
 }
else {               time_green=1;
                     green.style.display="none"; 
		     green2.style.display="block";
                     blue.style.display="block"; 
		     blue2.style.display="none";		     		      
}
global_time+=200;
if (global_time<5200) 
setTimeout("blinkGreenPlan()", 200);
else {
        green.style.display="block";
        green2.style.display="none";        
        blue.style.display="block"; 
        blue2.style.display="none";		     		      
        
     }
}

addLoadEvent(initAll);