var is_ie = ((navigator.userAgent.toLowerCase().indexOf("msie") != -1) && (navigator.userAgent.toLowerCase().indexOf("opera") == -1));
function PageSize()
{
  var xScroll, yScroll;
  if (window.innerHeight && window.scrollMaxY)
  {
		xScroll = document.getElementsByTagName('body')[0].scrollWidth;
		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
		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 = windowWidth;
  }
  else
  {
		pageWidth = xScroll;
  }
  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  return arrayPageSize;
}
function ShowPic(pic, lang)
{
	var obj_body = document.getElementsByTagName("body").item(0);
	if (!document.getElementById('body'))
	{
		var obj_div = document.createElement("div");
		obj_div.setAttribute('id','body');
		obj_div.style.display = 'none';
		obj_div.style.position = 'absolute';
		obj_div.style.top = '0px';
		obj_div.style.left = '0px';
		obj_div.style.zIndex = '100';
		obj_div.style.background = '#000000';
		if (is_ie) obj_div.style.filter = 'alpha(opacity=80)';
		else obj_div.style.opacity = '0.80';
		obj_body.insertBefore(obj_div, obj_body.firstChild);
	}
	if (!document.getElementById('pic'))
	{
		var obj_pic = document.createElement("div");
		obj_pic.setAttribute('id', 'pic');
		obj_pic.style.display = 'none';
		obj_pic.style.position = 'absolute';
		obj_pic.style.zIndex = '101';
		obj_pic.style.width = '100%';
		obj_pic.style.background = '#efefef';
		obj_pic.style.border = '2px outset';
    obj_body.insertBefore(obj_pic, obj_div.nextSibling);
		var obj_close = document.createElement('img');
		obj_close.src = '/pict/_close.png';
		obj_close.style.width = '16px';
		obj_close.style.height = '16px';
		obj_close.style.cursor = 'pointer';
		obj_close.style.margin = '2px';
		obj_pic.setAttribute('align', 'right');
		obj_close.onclick = function () {ClosePic(this.parentNode); return false;}
		obj_pic.appendChild(obj_close);
		var obj_img = document.createElement('img');
		obj_img.src = '/pict/_preloader.gif';
		obj_img.style.width = '16px';
		obj_img.style.height = '16px';
		obj_pic.appendChild(obj_img);
	}
	var x = (is_ie)?(event.x+document.body.scrollLeft):(100+document.body.scrollLeft);
	var y = (is_ie)?(event.y+document.body.scrollTop):(100+document.body.scrollTop);
	var obj = document.getElementById('body');
	var	div = document.getElementById('pic');
	if (div.style.display != 'block')
	{
		div.childNodes[1].style.width = '16px';
		div.childNodes[1].style.height = '16px';
		div.childNodes[1].src = '/pict/_preloader.gif';
		div.childNodes[1].style.margin = '48 67';
		div.style.left = parseInt((document.body.clientWidth - 16 - 67*2) / 2 + document.body.scrollLeft)+'px';
		div.style.top = parseInt((document.body.clientHeight - 29 - 48*2) / 2 + document.body.scrollTop)+'px';
		div.style.width = '150px';
		div.style.height = '131px';
		div.style.display = 'block';
		var sizes = PageSize();
		obj.style.left = 0;
		obj.style.top = 0;
		obj.style.width = sizes[0];
		obj.style.height = sizes[1];
		obj.style.display = 'block';

		return set_image(pic, x, y);
	}
	
//  var temp = '/showpic.php?pic=' + pic + '&lang=' + lang;
//  var xpos = (screen.width-100)/2;
//  var ypos = (screen.height-100)/2;
//  window.open(temp,'displayWindow','fullscreen=no,channelmode=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=1,height=1,top='+ypos+',left='+xpos); 
}
function ClosePic(obj)
{
	document.getElementById('body').style.display = 'none';
	obj.style.display ='none';
	document.getElementById('body').onclick = ''
}
function set_image(pic, x, y)	// подгружает картинку
{
	var big_pic = new Image();
	big_pic.src = pic.replace('/tn_', '/')+'?'+Math.random();
	big_pic.onload = function() {return get_image(pic, this, x, y);}
//	return true;
}
function get_image (pic, big_pic, x, y)	// определяет размеры картинки и показывает
{
	var left = 0;
	var top = 0;
	var width = big_pic.width;
	var height = big_pic.height;
	if (width > 800)
	{
		width = 800;
		height = big_pic.height / (big_pic.width / width);
	}
	if (height > 600)
	{
		height = 600;
		width = big_pic.width / (big_pic.height / height);
	}
	var div = document.getElementById('pic');
	left = parseInt((document.body.clientWidth - width) / 2 + document.body.scrollLeft);
	top = parseInt((document.body.clientHeight - height - 13) / 2 + document.body.scrollTop);
	div.style.left = left+'px';
	div.style.top = top+'px';
	div.style.width = parseInt(width+10)+'px';
	div.style.height = parseInt(height+25)+'px';
	document.getElementById('body').onclick = function() {ClosePic(div);}
	var image = div.childNodes[1];
	image.src = big_pic.src;
	image.style.width = parseInt(width)+'px';
	image.style.height = parseInt(height)+'px';
	image.style.margin = '0 5 5 5';
	if (is_ie) image.style.filter = 'alpha(opacity=0)';
	else image.style.opacity = '0.0';
	filter_image(0);
//	return true;
}
function filter_image(j)
{
	var div = document.getElementById('pic');
	var image = div.childNodes[1];
  j += 1;
	if (is_ie) image.style.filter = 'alpha(opacity='+j+'0)';
	else image.style.opacity = j/10;
	if (j < 10) setTimeout('filter_image('+j+')', 1);
}
