
var bigPhoto_tmp=null;
var bigPhoto_onload_div=null;
window.bigPhoto_act=null;

function bigPhotoShowWindow()
{
	if(bigPhoto_tmp) clearInterval(bigPhoto_tmp);
	//alert(window.bigPhoto_act);
	if(window.bigPhoto_act)
	{
		//newWindow=window.open('','x','width=' + '200' +', height=' + '200' );
		//ShowWindow();
		var o=window.bigPhoto_act;
		window.bigPhoto_act=null
		newWindow=window.open('',o.title,'width=' + o.w +', height=' + o.h );
		if(newWindow)
		{
		newWindow.document.writeln(o.text);
		newWindow.document.close();
		}
		if(bigPhoto_onload_div)
		{
			document.body.removeChild(bigPhoto_onload_div);
			bigPhoto_onload_div=null;
		}
	}
	else
	{
		bigPhoto_tmp=setInterval(bigPhotoShowWindow,40);
	}
}

function bigPhotoParent(Params)
{
	//alert(Params.w+' x '+Params.h+' x '+Params.title);
	
	newWindow=window.open('',Params.title,'width=' + Params.w +', height=' + Params.h );
	//alert(newWindow);
	if(newWindow)
	{
	newWindow.document.writeln(Params.text);
	newWindow.document.close();
	}
	if(bigPhoto_onload_div)
		{
			document.body.removeChild(bigPhoto_onload_div);
			bigPhoto_onload_div=null;
		}
}

function bigPhoto(indx, hght, wdth, img_tag,imgData)
{
	bigPhoto_onload_div=document.createElement("div");
	bigPhoto_onload_div.style.position='absolute';
	//bigPhoto_onload_div.style.top='0px';
	//bigPhoto_onload_div.style.left='0px';
	bigPhoto_onload_div.className='bigPhoto_onload';
	bigPhoto_onload_div.innerHTML='Загрузка изображения';
	//bigPhoto_onload_div.style.border='solid 1px red';
	
	document.body.appendChild(bigPhoto_onload_div);
	
	
	bigPhoto_onload_div.style.left=Math.floor((document.body.offsetWidth-bigPhoto_onload_div.offsetWidth)/2).toString()+'px';
	var s_top=document.documentElement.scrollTop;
	var s_h=window.innerHeight?window.innerHeight:document.documentElement.clientHeight;
	var s_out=s_top+Math.floor((s_h+bigPhoto_onload_div.offsetHeight)/2);
	bigPhoto_onload_div.style.top=s_out.toString()+'px';
	//alert(document.documentElement.scrollTop+' ' +document.body.clientHeight );
	
  now = new Date();
  var out_text='';
  var out_html='';
  var out_tmp='';
  var IMG1=getImgTagO(img_tag);
  img_tag.src="#";
  var IMG2=getImgTagO(img_tag);
  //newWindow=window.open('',now.getTime(),'width=' + (wdth + 40) +', height=' + (hght - 100));
  //newWindow=window.open('',now.getTime(),'width=' + (wdth + 40) );
  out_text+='<html><head>';
  out_text+='<title>' + imgData.name + '</title>';
  out_text+='<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">';
  out_text+='<link href="/styles/photo_one.css" type="text/css" rel="stylesheet" />';
  out_text+='</head>';
  out_text+='<body bgcolor="#ffffff" leftmargin="20" topmargin="20" marginwidth="20" marginheight="20">';
  out_text+='<div id="root" style="width:'+img_tag.w+'px">';
  out_text+='<table width=' + wdth + ' cellspacing="0" cellpadding="0" border="0">';
  out_html=out_text;
  out_text+='<tr><td>' + IMG1 + '</td></tr>';
  out_html+='<tr><td>' + IMG2 + '</td></tr>';
  out_tmp+='</table><br/>';
  if(imgData.name!='') out_tmp+='<div class="Name"><span>Наименование: </span>'+imgData.name+'</div>';
  if(imgData.desc!='') out_tmp+='<div class="Desc"><span>Описание: </span>'+imgData.desc+'</div>';
  if(imgData.place!='') out_tmp+='<div class="Place"><span>Место: </span>'+imgData.place+'</div>';
  if(imgData.source!='') out_tmp+='<div class="Source"><span>Источник: </span>'+imgData.source+'</div>';
  if(imgData.date!='') out_tmp+='<div class="Date"><span>Дата публикации: </span>'+imgData.date+'</div>';
  out_tmp+=('</div>');
  //newWindow.document.writeln('<script>alert(document.getElementById("root").offsetHeight);</script>');
  //newWindow.document.writeln('<script>alert(document.body.outerHTML);</script>');
  //newWindow.document.writeln('<script>document.body.style.height="400px";</script>');
  out_tmp+='</body></html>';
  //out_tmp+='<script>window.resizeTo(400,400); </script>';
  out_text+=out_tmp;
  out_html+=out_tmp;
  var out_script='';
  out_script+='<script>';
  out_script+='var out_text="'+escape(out_text)+'";';
  out_script+='var wdth='+wdth+';';
  out_script+='function start()';
  out_script+='{';
  out_script+='var h=document.getElementById("root").offsetHeight;';
  out_script+='var now = new Date();';
  //out_script+="var newWindow=window.open('',now.getTime(),'width=' + (wdth + 40) +', height=' + (h+20));";
  out_script+='window.parent.bigPhotoParent({title:now.getTime(),w:(wdth + 40),h:(h+40),text:unescape(out_text)});';
  //out_script+='window.parent.bigPhoto_act={title:now.getTime(),w:(wdth + 40),h:(h+40),text:unescape(out_text)};';
  //out_script+='newWindow.document.writeln(unescape(out_text));';
  //out_script+='alert(window.parentDocument+" x "+document);';
  out_script+='}';
  out_script+='window.onload=start;';
  out_script+='</script>';

  //newWindow=window.open('',now.getTime(),'width=' + (wdth + 40) +', height=' + (hght +40));
  //newWindow.document.writeln(out_text);
  //newWindow.document.close();
  bigPhoto_tmp=setInterval(bigPhotoShowWindow,40);

  var fr=document.createElement('iframe');
  var fr_p=document.createElement('div');
  fr_p.style.width='1px';
  fr_p.style.height='1px';
  fr_p.style.overflow='hidden';
  fr.style.width=(wdth + 40)+'px';
  //fr.style.height='200px';
  fr_p.appendChild(fr);
  document.body.appendChild(fr_p);
  fr.contentWindow.document.writeln(out_script+out_html);
  fr.contentWindow.document.close();


}

function getImgTag(file, alt, hght, wdth, border) {
  return '<img src="' + file + '" border="' + border + '" alt="' + alt + '" HEIGHT="' + hght + '"  WIDTH="' + wdth + '" />';
}
function getImgTagO(data) {
  return '<img src="' + data.src + '" border="' + data.border + '" alt="' + data.alt + '" height="' + data.h + '"  width="' + data.w + '" />';
}

function navigation_map(indx, hght, wdth, src)
{
  now = new Date();
  newWindow=window.open('',now.getTime(),'width=' + wdth + ', height=' + hght );
  newWindow.location.replace(src);
}
