//
//  fullimg.js ver 1.5
//	http://igisoft.ru/
//
//  Что нового:
//  29.01.07 Средствами DOM код скрытых картинок вставляется в 
//	самый конец body. Этим убирается проблема если вызов просихожил 
//	из дива с position:absolute и установленным overflow
//

var hidendivs = '';

function GetWindowHeight(){
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		var WindowHeight = document.body.clientHeight;
		return WindowHeight;
	} else { 
		var WindowHeight = window.outerHeight;
		return WindowHeight;
	}
	return;
}

function GetWindowWidth(){
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		var WindowWidth = document.body.clientWidth;
		return WindowWidth;
	} else { 
		var WindowWidth = window.outerWidth;
		return WindowWidth;
	}
	return;
}

/* Отображение ответа на комменты*/
   function look_img(a){
	if(document.getElementById("um_img_"+a).style.display=="none"){

		pic = new Image();
		pic.src = "/photo/"+a;
		if (pic.complete == false){
			window.open("/photo/"+a);	
		}else{
			if (pic.width > 0) {
				var LeftIMG= Math.floor((GetWindowWidth()-pic.width) / 2);
				if (LeftIMG < 0) LeftIMG = 0;
			}else {
				var LeftIMG = 0;
			}
			if (pic.height > 0) {
				var TopIMG = Math.floor((GetWindowHeight()-pic.height) / 2);
				if (TopIMG < 0) TopIMG = 0;
			}else {
				var TopIMG = 0;
			}
	  
			TopIMG = TopIMG + document.documentElement.scrollTop;

			document.getElementById("um_img_"+a).style.left=LeftIMG+'px'; 
			document.getElementById("um_img_"+a).style.top=TopIMG+'px';
			document.getElementById("um_img_"+a).style.display="";
		}
    }else{
      document.getElementById("um_img_"+a).style.display="none";
    }
  } 

/* Функция вывода кода формы отправки коммента */
   function create_form_comm(img_name){
	picm = new Image();
	picm.src = "/photo/m_"+img_name;
	var s = "<a onclick='look_img(\""+img_name+"\");'  href=\"javascript:void(0)\"><img src='"+picm.src+"' /></a>";
	document.write(s);

	pic = new Image();
	pic.src = "/photo/"+img_name;


	hidendivs = hidendivs + "<DIV style='position:absolute; left:0; top:0; display:none;' onclick='look_img(&quot;"+img_name+"&quot;);' id=um_img_"+img_name+"><a href='javascript:void(0)'><img src='" + pic.src +"' /></a></DIV>";
	
  }
  
 	function init() {
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		
		if (_timer) {
			clearInterval(_timer);
			_timer = null;
		}
		
		//Вывод после боди массива скрытых дивов
		var mBody = document.getElementsByTagName("body")[0];
		if (navigator.userAgent.indexOf("MSIE") > 0) {
			mBody.innerHTML = mBody.innerHTML + hidendivs;
		}else{

		div=document.createElement('div');
		div.innerHTML = hidendivs;
		mBody.appendChild(div);
		}

	};
	
	/* for Mozilla */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", init, false);
	}
	
	/* for Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
		document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				init(); // call the onload handler
			}
		};
	/*@end @*/
	
	/* for Safari */
	if (/WebKit/i.test(navigator.userAgent)) { // sniff
		var _timer = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				init(); // call the onload handler
			}
		}, 10);
	}
	
	/* for other browsers */
	window.onload = init;
