var js = '<scri'+'pt language="javascript" type="text/javascript">'+"\n"+
'  function fitToWindow() {'+"\n"+
'	var isNav4, isIE4, isFF;'+"\n"+
'	if (parseInt(navigator.appVersion.charAt(0)) >= 4) {'+"\n"+
'	  isNav4 = (navigator.appName == "Netscape") ? 1 : 0;'+"\n"+
'	  isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;'+"\n"+
'	  isOpera = (navigator.appName.indexOf("Opera") != -1) ? 1 : 0;'+"\n"+
'	  isFF = (navigator.userAgent.indexOf("Firefox") != -1) ? 1 : 0;'+"\n"+
'	}'+"\n"+
'	var xtraWidth = 0; // margin'+"\n"+
'	var xtraHeight = -20; // space for close button'+"\n"+
'	if (isNav4) {'+"\n"+
'	  window.innerWidth = document.images[0].width + xtraWidth;'+"\n"+
'	  window.innerHeight = document.images[0].height + xtraHeight;'+"\n"+
'	  if (window.innerWidth>=screen.width) {'+"\n"+
'		if (window.innerHeight>=screen.height) {'+"\n"+
'		  window.resizeTo((screen.width-30), (screen.height-50));'+"\n"+
'		} else {'+"\n"+
'		  window.resizeTo(screen.width-20,window.innerHeight);'+"\n"+
'		}'+"\n"+
'	  } else if (window.innerHeight>=screen.height) {'+"\n"+
'		if (window.innerWidth>=screen.width) {'+"\n"+
'		  window.resizeTo((screen.width-30), (screen.height-50));'+"\n"+
'		} else {'+"\n"+
'		  window.resizeTo(window.innerWidth,screen.height-40);'+"\n"+
'		}'+"\n"+
'	  } else {'+"\n"+
'		window.resizeTo(window.innerWidth,window.innerHeight);'+"\n"+
'	  }'+"\n"+
'//	  window.moveTo(((screen.width-30)-window.innerWidth)/2,((screen.height-70)-window.innerHeight)/2);'+"\n"+
'	}'+"\n"+
'	if (isIE4 || isFF || isOpera) {'+"\n"+
'	  window.resizeTo(660, 500);'+"\n"+
'	  width = 660 - (document.body.clientWidth -  document.images[0].width);'+"\n"+
'	  height = 520 - (document.body.clientHeight -  document.images[0].height);'+"\n"+
'	  width = width + xtraWidth;'+"\n"+
'	  height = height + xtraHeight;'+"\n"+
'	  if (width < 170) width = 170;'+"\n"+
'	  if (height < 150) height = 150;'+"\n"+
'	  if (width>=screen.width) {'+"\n"+
'		if (height>=screen.height) {'+"\n"+
'		  window.resizeTo((screen.width-30), (screen.height-50));'+"\n"+
'		} else {'+"\n"+
'		  window.resizeTo(screen.width-20, height);'+"\n"+
'		}'+"\n"+
'		document.body.scroll = \'auto\';'+"\n"+
'	  } else if (height>=screen.height) {'+"\n"+
'		if (width>=screen.width) {'+"\n"+
'		  window.resizeTo((screen.width-30), (screen.height-50));'+"\n"+
'		} else {'+"\n"+
'		  window.resizeTo(width, screen.height-40);'+"\n"+
'		}'+"\n"+
'		document.body.scroll = \'auto\';'+"\n"+
'	  } else {'+"\n"+
'		window.resizeTo(width, height);'+"\n"+
'	  }'+"\n"+
'//	  window.moveTo(((screen.width-30)-document.body.clientWidth)/2, ((screen.height-70)-document.body.clientHeight)/2);'+"\n"+
'	}'+"\n"+
'  }'+"\n"+
'</'+'script>'+"\n";

function popupImage(href, title) {
  href = unescape(href);
  title = unescape(title);
  newWindow = window.open("", "popupImage", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,scrolling=auto,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150");
  newWindow.document.open();
  newWindow.document.write("<html>\n<head>\n<title>"+title+"</title>\n"+js+"<meta http-equiv=\"content-type\" content=\"text/html; charset=windows-1251\" />\n</head>\n<body style=\"margin: 0;\" onload=\"fitToWindow(); self.focus();\"><img src=\""+href+"\" alt=\""+title+"\""+(title ? " title=\""+title+"\"" : "")+" border=\"0\" />\n</body>\n</html>");
  newWindow.document.close();
  return false;
}

function preloadPopups() {
  var hrefs = new Array();
  elements = document.getElementsByTagName('a');
  for (i=0; i<elements.length; i++) {
	link_href = elements[i].href;
	link_target = elements[i].target;
	dot_position = link_href.lastIndexOf('.');
	if (dot_position!=-1 && link_target=='_blank') {
	  link_type = link_href.substring(dot_position+1).toLowerCase();
	  if (link_type=='jpeg') link_type = 'jpg';
	  q_position = link_type.lastIndexOf('?');
	  if (q_position!=-1) {
		link_type = link_type.substring(0, q_position);
		link_href = link_href.substring(0, link_href.lastIndexOf('?'));
	  }
	  if (link_type=='jpg' || link_type=='gif' || link_type=='png') {
		if (elements[i].title) {
		  img_title = element.title;
		} else if (elements[i].innerHTML.indexOf('title=')!=-1) {
		  img_title = elements[i].innerHTML.replace(/^[^<img]*(<img[^>]*>).*$/i, "$1");
		  img_title = img_title.replace(/.*title=['"]?([^'">]*)['"\s]?.*/i, "$1");
		} else if (elements[i].innerHTML.indexOf('alt=')!=-1) {
		  img_title = elements[i].innerHTML.replace(/^[^<img]*(<img[^>]*>).*$/i, "$1");
		  img_title = img_title.replace(/.*alt=['"]?([^'">]*)['"\s]?.*/i, "$1");
		} else {
		  img_title = link_href;
		}
		img_title = img_title.replace(/^\s*|­\s(?=\s)|\s*$/g, "");
		elements[i].outerHTML = elements[i].outerHTML.replace(/<(a[^>]*)>/i, "<$1 onclick=\"popupImage('"+escape(link_href)+"', '"+escape(img_title)+"'); return false;\">");
	  }
	}
  }
}

function MM_preloadImages() {
  var d = document;
  if (d.images) {
	if (!d.MM_p) d.MM_p = new Array();
	var i,j = d.MM_p.length, a = MM_preloadImages.arguments;
	for (i=0; i<a.length; i++) {
	  if (a[i].indexOf("#")!=0) {
		d.MM_p[j] = new Image;
		d.MM_p[j++].src=a[i];
	  }
	}
  }
}
