﻿var NRow, NColunm;
var NameSuffix;
var ImageTD;
var oldClientWidth;
var dK;

var wTD, hTD;
var isLoaded = true;
var time_LoadProccess;

function setLang()
{
	h=Tbody.clientHeight;
	w=Tbody.clientWidth;
	if(!dK)
	{
		dK=Tbody.clientWidth/1020;
	}
	document.getElementById('langAz').style.top=70*dK;
	document.getElementById('langAz').style.left=290*dK;

	document.getElementById('langRu').style.top=70*dK;
	document.getElementById('langRu').style.left=480*dK;
	
	document.getElementById('langEn').style.top=70*dK;
	document.getElementById('langEn').style.left=630*dK;

	
}



//----------------------------------------------------------------------------
//              ShowTitle
//----------------------------------------------------------------------------
function ShowTitle(Rows, Columns, Suffix)
{
  NRow = Rows;
  NColunm = Columns;
  NameSuffix = Suffix;
  wTD = new Array(NColunm);
  hTD = new Array(NRow);

  oldClientWidth = Tbody.clientWidth;

  Prepare();
  time_LoadProccess = setInterval("LoadProccess()",1000);
}   

 
//----------------------------------------------------------------------------
//              Prepare
//----------------------------------------------------------------------------
function Prepare()
{
  ImageTD = new Array(NRow);

  for(var i=0; i<NRow; i++) {
      ImageTD[i] = new Array(NColunm);
	  for(var j=0; j<NColunm; j++) {
	      ImageTD[i][j] = new Image();
		  var str = NameSuffix + (i+1) + "" + (j+1) + ".jpg";
		  ImageTD[i][j].src = str;
	   }
   }

   
  for(var i=0; i<NRow; i++)  hTD[i] = 0;

  for(var i=0; i<NColunm; i++)  wTD[i] = 0;
} 
  

//----------------------------------------------------------------------------
//              LoadProccess
//----------------------------------------------------------------------------
function LoadProccess()
{
 isLoaded = true;
 Resize();

 if(isLoaded) {
   clearInterval(time_LoadProccess);
   window.onresize = Repaint;
   isLoaded = false;
  }

}

//----------------------------------------------------------------------------
//              Resize
//----------------------------------------------------------------------------
function Resize()
{
var strInnerHTML = " ";

dK = oldClientWidth/1020;
if(oldClientWidth/Tbody.clientHeight > 1.6)
   Tbody.scroll = "yes";
else   
   Tbody.scroll = "no";

  var top = 0;
  for(var i=0; i<NRow; i++) {
	  var left = 0;
	  for(var j=0; j<NColunm; j++) {
	  
	      if(!ImageTD[i][j].complete) {
		     isLoaded = false;
			 continue;
		   }
		  if(wTD[j]==0) wTD[j] = ImageTD[i][j].width;
		  if(hTD[i]==0) hTD[i] = ImageTD[i][j].height;
		  
		  ImageTD[i][j].width = wTD[j]*dK;
		  ImageTD[i][j].height = hTD[i]*dK;
	      strInnerHTML += "<img id=\"i_" + (i+1)+ "" + (j+1) + "\"" +
		                  " style=\"display: block; z-index: 0; position: absolute;" +
						  " left: " + left + "; top: " + top + ";" +
						  " width: " + ImageTD[i][j].width + ";" +
						  " height: " + ImageTD[i][j].height + ";\"" +
						  " src=" + ImageTD[i][j].src + " border=\"0\">\n";
						  
	      left += ImageTD[0][j].width;
	   }  
	  top += ImageTD[i][0].height;
   }

 MyTable.innerHTML = strInnerHTML;

}

//----------------------------------------------------------------------------
//              Repaint
//----------------------------------------------------------------------------
function Repaint()
{
  if(Tbody.clientWidth != oldClientWidth) {
     oldClientWidth = Tbody.clientWidth;
     Resize();
	 setLang();
   }	 
}

