/**********************
 *    Script by Vitaly Z.
 *  darkavanger@ukr.net
 *
 **********************/
 
var IE = false;

function init( ) {

try {



	if ( typeof(document.body.style.maxHeight) === "undefined") { // if IE 6
			IE = true;
/*			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if ( document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='overlay'></div><div id='windowdiv'><div><iframe id='okno'></iframe></div></div>");
				$("#overlay").click(stopTheWar);
			}
*/	}

	//all others
	var Body = document.body;
	
/*	Body.innerHTML += '<div id="overlay" onclick="stopTheWar();" style="display: none; z-index: 1;></div>\n<div id="windowdiv" style="z-index: 10; display: none;">\n<div>\n<iframe id="okno" style="z-index: 10;"></iframe>\n</div>\n</div>';
	alert( Body.innerHTML );
*/

    var Overlay = document.createElement("div");
    Overlay.setAttribute('id', 'overlay');
    Overlay.setAttribute('onclick', "stopTheWar();");
    Overlay.style.display = 'none';
    Overlay.style.zIndex = '1';
    Body.appendChild(Overlay);
	
    var windowDiv = document.createElement("div");
    windowDiv.setAttribute('id', 'windowdiv');
	windowDiv.style.zIndex = '10';
    windowDiv.style.display = 'none';
    Body.appendChild(windowDiv);
	
	var windowDivDiv = document.createElement("div");
    //windowDiv.setAttribute('id', 'windowdiv');
	//windowDiv.style.zIndex = '10';
    //windowDivDiv.style.display = 'none';
    windowDiv.appendChild(windowDivDiv);
	
	var okno = document.createElement("iframe");
    okno.setAttribute('id', 'okno');
//	okno.setAttribute('onkeydown', "escape(event)");
	okno.style.zIndex = '10';
    //okno.style.display = 'none';
    windowDivDiv.appendChild(okno);
	
	//$("#overlay").click(hideme);
	
//	alert( Body.innerHTML );

//	alert( document.getElementById("overlay").innerHTML );

	var arrayPageSize = getPageSize();
//	alert(arrayPageSize[0]);
//	alert(arrayPageSize[1]);


	if (IE === true) {
//		alert(IE);

		var arrayPageSize = getPageSize();
		fon = document.getElementById('overlay');
		fon.style.filter = "alpha(style=0, opacity=40)";
		fon.style.position = "absolute";
		fon.style.top	= "0";
		fon.style.bottom = "0";
		
		Body.style.height = "100%";
		/*
		$("#overlay").hide().css({
			width: '100%',
			zIndex: '10090',
			height: arrayPageSize[1] + 'px',
			opacity : Lightbox.overlayOpacity
		}).fadeIn();
		*/
	}

	document.body.onclick = "";

//	alert("init");

} catch(e) {
		//nothing here
}

}

function showPage( link, event ) {

	//document.cancelBubble(); // = true;
	event.cancelBubble = true;
//	document.event.cancelBubble = true;

	layer = document.getElementById('overlay').style;
	layer.display = "block";
	layer.position = "absolute";
	layer.top	= "0";
	layer.bottom = "0";
	
	var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) { 
      xScroll = window.innerWidth + window.scrollMaxX;
      yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
    }
    else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
    }
	
	/*layer.width = xScroll;*/
	layer.height = yScroll;
	
	posFrame();

	windowDiv = document.getElementById('windowdiv').style;
	windowDiv.zIndex = "20";
	windowDiv.position = "absolute";
	/*windowDiv.position = (IE === true) ? "absolute" : "fixed";*/
	windowDiv.display = 'block';

		document.getElementById("okno").src = link.href;	// работает в 2-х
		if ( !document.getElementById("okno").src )
			frames[0].location.href = link.href;			// для IE
		//frames[0].location.href = link.href;			// работает в 2-х


	document.body.onclick = stopTheWar;
	window.onresize = posFrame;

	return false;
}

function escape(event) {
	if( event.keyCode == 27 )
		stopTheWar();
}

function stopTheWar() {
//	alert("click");

	layer = document.getElementById('overlay').style;
	layer.display = "none";
	
	okno = document.getElementById('okno');
/*	okno.src = "/blank.html";
	if ( !document.getElementById("okno").src )
		frames[0].location.href = "/blank.html";
*/	okno.src = "";
	if ( !document.getElementById("okno").src )
		frames[0].location.href = "/blank.html";

	windowDiv = document.getElementById('windowdiv').style;
	windowDiv.zIndex = "";
	windowDiv.position = "static";
	windowDiv.display = "none";
	
	document.body.onclick = "";
	window.onresize = "";
}

function posFrame() {

	var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) { 
      xScroll = window.innerWidth + window.scrollMaxX;
      yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
    }
    else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) { // all except Explorer
      if (document.documentElement.clientWidth) {
        windowWidth = document.documentElement.clientWidth; 
      }
      else {
        windowWidth = self.innerWidth;
      }
      windowHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowWidth = document.documentElement.clientWidth;
      windowHeight = document.documentElement.clientHeight;
    }
    else if (document.body) { // other Explorers
      windowWidth = document.body.clientWidth;
      windowHeight = document.body.clientHeight;
    }

/*	alert( xScroll + "x" + yScroll + "\n" + windowWidth + "x" + windowHeight );*/
	
	var offsetLeft = parseInt(((windowWidth - 800 )>> 1),10);
	offsetLeft = ( offsetLeft < 0 )? 0 : offsetLeft;
	/*alert( offsetLeft );*/
	windowDiv = document.getElementById('windowdiv').style;
	windowDiv.left = offsetLeft + "px";
}

function getPageSize() {

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) { 
      xScroll = window.innerWidth + window.scrollMaxX;
      yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
    }
    else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) { // all except Explorer
      if (document.documentElement.clientWidth) {
        windowWidth = document.documentElement.clientWidth; 
      }
      else {
        windowWidth = self.innerWidth;
      }
      windowHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowWidth = document.documentElement.clientWidth;
      windowHeight = document.documentElement.clientHeight;
    }
    else if (document.body) { // other Explorers
      windowWidth = document.body.clientWidth;
      windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
      pageHeight = windowHeight;
    }
    else { 
      pageHeight = yScroll;
    }


    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) { 
      pageWidth = xScroll;  
    }
    else {
      pageWidth = windowWidth;
    }

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight) 
    return arrayPageSize;
}
