var LastIdOpen=0;
var OpenState=0;

var base_vel_index=10;

var step_count = new Array();;
var step_index = new Array();

var m_size=21;

var luc_st='height='+m_size+' width='+m_size+' hspace="0" background="img/M_LUcorner.png" ';
var ruc_st='height='+m_size+' width='+m_size+' hspace="0" background="img/M_RUcorner.png" ';
var rbc_st='height='+m_size+' width='+m_size+' hspace="0" background="img/M_RBcorner.png" ';
var lbc_st='height='+m_size+' width='+m_size+' hspace="0" background="img/M_LBcorner.png" ';
	
var lb_st='hspace="0" background="img/M_Lborder.png" ';
var ub_st='hspace="0" background="img/M_Uborder.png" ';
var rb_st='hspace="0" background="img/M_Rborder.png" ';
var bb_st='hspace="0" background="img/M_Bborder.png" ';

var InImage = '';

var RealHeight = new Array();
var RealWidth = new Array();

var BigSource = new Array();
var SmlSource = new Array();

var BigTextalign = new Array();
var BigTextsize = new Array();

var SmlWidth = new Array();
var BigWidth = new Array();

var SmlHeight = new Array();
var BigHeight = new Array();

var SmlLeft = new Array();
var BigLeft = new Array();

var SmlTop = new Array();
var BigTop = new Array();

var SmlBorder = new Array();
var BigBorder = new Array();

var CurRealWidth = new Array();
var EndRealWidth = new Array();
var StepRealWidth = new Array();

var CurRealHeight = new Array();
var EndRealHeight = new Array();
var StepRealHeight = new Array();

var CurLeft = new Array();
var EndLeft = new Array();
var StepLeft = new Array();

var CurTop = new Array();
var EndTop = new Array();
var StepTop = new Array();

var CurWidth = new Array();
var EndWidth = new Array();
var StepWidth = new Array();

var CurHeight = new Array();
var EndHeight = new Array();
var StepHeight = new Array();

var CurTextsize = new Array();
var EndTextsize = new Array();
var StepTextsize = new Array();

var CurBordersize = new Array();
var EndBordersize = new Array();
var StepBordersize = new Array();

var BigText = new Array();
var BigBackcolor = new Array();
var BigTextcolor = new Array();
var divMainBackground = new Array();
var divText = new Array();

var refProcess = new Array();

function GetNextColor(cur_col, tar_col, steps_count)
{
	cur_col_16=cur_col.substring(1);
	cur_col_10=parseInt(cur_col_16, 16);

	tar_col_16=tar_col.substring(1);
	tar_col_10=parseInt(tar_col_16, 16);

	cur_col_16_R=cur_col.substring(1,3);
	cur_col_16_G=cur_col.substring(3,5);
	cur_col_16_B=cur_col.substring(5,7);

	cur_col_10_R=parseInt(cur_col_16_R, 16);
	cur_col_10_G=parseInt(cur_col_16_G, 16);
	cur_col_10_B=parseInt(cur_col_16_B, 16);

	tar_col_16_R=tar_col.substring(1,3);
	tar_col_16_G=tar_col.substring(3,5);
	tar_col_16_B=tar_col.substring(5,7);

	tar_col_10_R=parseInt(tar_col_16_R, 16);
	tar_col_10_G=parseInt(tar_col_16_G, 16);
	tar_col_10_B=parseInt(tar_col_16_B, 16);

	cur_col_10_R_step=Math.floor((tar_col_10_R-cur_col_10_R)/steps_count);
	cur_col_10_G_step=Math.floor((tar_col_10_G-cur_col_10_G)/steps_count);
	cur_col_10_B_step=Math.floor((tar_col_10_B-cur_col_10_B)/steps_count);

	if (tar_col_10_R!=cur_col_10_R && cur_col_10_R_step==0) {cur_col_10_R>tar_col_10_R ? cur_col_10_R_step=-1 : cur_col_10_R_step=1}
	if (tar_col_10_G!=cur_col_10_G && cur_col_10_G_step==0) {cur_col_10_G>tar_col_10_G ? cur_col_10_G_step=-1 : cur_col_10_G_step=1}
	if (tar_col_10_B!=cur_col_10_B && cur_col_10_B_step==0) {cur_col_10_B>tar_col_10_B ? cur_col_10_B_step=-1 : cur_col_10_B_step=1}
	
	new_col_10_R=Math.floor(cur_col_10_R+cur_col_10_R_step);
	new_col_10_G=Math.floor(cur_col_10_G+cur_col_10_G_step);
	new_col_10_B=Math.floor(cur_col_10_B+cur_col_10_B_step);

	if (new_col_10_R<0) new_col_10_R=0;
	if (new_col_10_G<0) new_col_10_G=0;
	if (new_col_10_B<0) new_col_10_B=0;

	if (new_col_10_R>255) new_col_10_R=255;
	if (new_col_10_G>255) new_col_10_G=255;
	if (new_col_10_B>255) new_col_10_B=255;

	if (Math.abs(new_col_10_R-tar_col_10_R)<10) new_col_10_R=tar_col_10_R;
	if (Math.abs(new_col_10_G-tar_col_10_G)<10) new_col_10_G=tar_col_10_G;
	if (Math.abs(new_col_10_B-tar_col_10_B)<10) new_col_10_B=tar_col_10_B;

	new_col_16_R=new_col_10_R.toString(16);
	new_col_16_G=new_col_10_G.toString(16);
	new_col_16_B=new_col_10_B.toString(16);

	if (new_col_16_R.length==1) new_col_16_R="0"+new_col_16_R;
	if (new_col_16_G.length==1) new_col_16_G="0"+new_col_16_G;
	if (new_col_16_B.length==1) new_col_16_B="0"+new_col_16_B;

	new_col_16=new_col_16_R+new_col_16_G+new_col_16_B;

	return ('#'+new_col_16.toUpperCase());

}

function getCookieVal (offset) 
{
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1) endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) 
        {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                        return getCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0) break;
        }
   return null;
}

function SetCookie (name, value) 
{
        var argv = SetCookie.arguments;
        var argc = SetCookie.arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
        var path = (argc > 3) ? argv[3] : null;
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function popup(title, imgSrc, imgWidth, imgHeight) 
{			
	var wndLeft = (screen.width / 2) - (imgWidth / 2);
	var wndTop = (screen.height / 2) - (imgHeight / 2);
	_w = window.open("about:blank", "_w", "width=" + imgWidth + ",height=" + imgHeight + ",top=" + wndTop + ",left=" + wndLeft);
	var doc = _w.document;
	doc.open();
	doc.write('<html><head><title>' + title + '</title></head>');
	doc.write('<body bgcolor="#ffffff" topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0" marginwidth="0" marginheight="0"">');
	doc.write('<img onclick="Test();" src="' + imgSrc + '" alt="' + title + '" width="' + imgWidth + '" height="' + imgHeight + '" hspace="0" vspace="0"><br>');
	doc.write('</body></html>');
	doc.close();
	_w.focus();

return false;
}


function ZoomImage(in_img, in_col_text, mSrc, bSrc , bLeft, bTop, bWidth, bHeight, rHeight, rWidth, in_div, in_txt, mBrd, bBrd, in_col, in_text, text_align, in_size) 
{			
	
	if (OpenState==1 && LastIdOpen!=in_img) return false;
	
	LastIdOpen=in_img;
	OpenState=1;
	
	step_index[in_img]=0;
	
	InImage=in_img;
	
	clearTimeout(refProcess[in_img]);
  
	objImg = document.getElementById(in_img);
	objDiv = document.getElementById(in_div);

	objTxt = document.getElementById(in_txt);
  	objTxt.style.backgroundColor=in_col;

	RealHeight[in_img] = rHeight;
	RealWidth[in_img] = rWidth;
	
	BigSource[in_img] = bSrc;
	SmlSource[in_img] = mSrc;

	BigTextalign[in_img]=text_align;
	BigTextsize[in_img]=in_size;
	
	BigText[in_img]=in_text;
	BigBackcolor[in_img]=in_col;
	BigTextcolor[in_img]=in_col_text;
	divMainBackground[in_img]=in_div;
	divText[in_img]=in_txt;
  
	CurWidth[in_img]=objImg.width;
	CurBordersize[in_img]=Math.floor((objDiv.offsetWidth-objImg.width)/2);
	
	if (CurWidth[in_img]<bWidth)
	{ 
		SmlWidth[in_img]=objImg.width;
		SmlHeight[in_img]=objImg.height;

		SmlLeft[in_img]=parseInt(objImg.style.left);
		SmlTop[in_img]=parseInt(objImg.style.top);
	}

	BigWidth[in_img]=bWidth;
	BigHeight[in_img]=bHeight;
	
	BigLeft[in_img]=bLeft;
	BigTop[in_img]=bTop;

	SmlBorder[in_img]=mBrd;
	BigBorder[in_img]=bBrd;

	var step_countW=Math.floor((bWidth-SmlWidth[in_img])/(base_vel_index));
	var step_countH=Math.floor((bHeight-SmlHeight[in_img])/(base_vel_index));
	var step_countL=Math.floor((bLeft-SmlLeft[in_img])/(base_vel_index));
	var step_countT=Math.floor((bTop-SmlTop[in_img])/(base_vel_index));
	
	step_count[in_img]=Math.max(Math.abs(step_countW), Math.abs(step_countH), Math.abs(step_countL), Math.abs(step_countT), 15);
	

  if (CurWidth[in_img]<bWidth) 
  {
	objDiv.innerHTML='';
	objDiv.innerHTML+='<img id="'+in_img+'_buf" height="'+parseInt(SmlHeight[in_img])+'" width="'+parseInt(SmlWidth[in_img])+'" src="'+SmlSource[in_img]+'" style="cursor: pointer; z-index: 12; position: absolute;">';
	objDiv.innerHTML+='<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td '+luc_st+'></td><td '+ub_st+'>&nbsp;</td><td '+ruc_st+'></td></tr><tr id="trContent'+in_img+'" height="100%"><td id="tdContent'+in_img+'" '+lb_st+'>&nbsp;</td><td bgcolor="'+in_col+'">&nbsp;</td><td '+rb_st+'>&nbsp;</td></tr><tr><td '+lbc_st+'></td><td '+bb_st+'>&nbsp;</td><td '+rbc_st+'></td></tr></table>';
	

	objImg.style.zIndex=-1;
	objImg.style.top=-1500;
	objImg.style.left=-1500;
	objImg.src=BigSource[in_img];
	objImg.width=parseInt(RealWidth[in_img]);
	objImg.height=parseInt(RealHeight[in_img]);
	objImg.style.clip="rect(0, "+BigWidth[in_img]+", "+BigHeight[in_img]+", 0)";

	objImg = document.getElementById(in_img+'_buf');
	
  	objDiv.style.zIndex=10;
  	objImg.style.zIndex=11;
  	objTxt.style.zIndex=11;

  	StepWidth[in_img]=(bWidth-SmlWidth[in_img])/step_count[in_img];
  	EndWidth[in_img]=bWidth;

  	CurHeight[in_img]=SmlHeight[in_img];
  	StepHeight[in_img]=(bHeight-SmlHeight[in_img])/step_count[in_img];
  	EndHeight[in_img]=bHeight;

  	CurBordersize[in_img]=mBrd;
  	EndBordersize[in_img]=bBrd;
  	StepBordersize[in_img]=Math.ceil((bBrd-mBrd)/step_count[in_img]);
	
  	StepLeft[in_img]=(bLeft-SmlLeft[in_img])/step_count[in_img];
  	CurLeft[in_img]=SmlLeft[in_img];
  	EndLeft[in_img]=bLeft;

  	StepTop[in_img]=(bTop-SmlTop[in_img])/step_count[in_img];
  	CurTop[in_img]=SmlTop[in_img];
  	EndTop[in_img]=bTop;
	
	ZoomProcess(in_img);
  }
  else
  {
  	StepWidth[in_img]=(-1)*(bWidth-SmlWidth[in_img])/step_count[in_img];
  	EndWidth[in_img]=SmlWidth[in_img];

  	CurHeight[in_img]=bHeight;
  	EndHeight[in_img]=SmlHeight[in_img];
	StepHeight[in_img]=(-1)*(bHeight-SmlHeight[in_img])/step_count[in_img];
	
  	CurBordersize[in_img]=bBrd;
  	EndBordersize[in_img]=mBrd;
  	StepBordersize[in_img]=(-1)*(bBrd-mBrd)/step_count[in_img];
	
  	StepLeft[in_img]=(SmlLeft[in_img]-bLeft)/step_count[in_img]; 
  	CurLeft[in_img]=bLeft;
  	EndLeft[in_img]=SmlLeft[in_img];

  	StepTop[in_img]=(SmlTop[in_img]-bTop)/step_count[in_img];
  	CurTop[in_img]=bTop;
  	EndTop[in_img]=SmlTop[in_img];

  	HideText(in_img);
  }
  
  
  return false;
}

function ZoomProcess(in_img) 
{			
	  
	step_index[in_img]++;
	
	(Math.abs(EndWidth[in_img]-CurWidth[in_img])>Math.abs(StepWidth[in_img])) ? CurWidth[in_img]+=StepWidth[in_img] : CurWidth[in_img]=EndWidth[in_img];
	(Math.abs(EndHeight[in_img]-CurHeight[in_img])>Math.abs(StepHeight[in_img])) ? CurHeight[in_img]+=StepHeight[in_img] : CurHeight[in_img]=EndHeight[in_img];
	(Math.abs(EndLeft[in_img]-CurLeft[in_img])>Math.abs(StepLeft[in_img])) ? CurLeft[in_img]+=StepLeft[in_img] : CurLeft[in_img]=EndLeft[in_img];
	(Math.abs(EndTop[in_img]-CurTop[in_img])>Math.abs(StepTop[in_img])) ? CurTop[in_img]+=StepTop[in_img] : CurTop[in_img]=EndTop[in_img];
	(Math.abs(EndBordersize[in_img]-CurBordersize[in_img])>Math.abs(StepBordersize[in_img])) ? CurBordersize[in_img]+=StepBordersize[in_img] : CurBordersize[in_img]=EndBordersize[in_img];
	
	objImg = document.getElementById(in_img+'_buf');
	objImg.width=CurWidth[in_img];
	objImg.height=CurHeight[in_img];

	objDiv = document.getElementById(divMainBackground[in_img]);
	
	objDiv.style.width=CurWidth[in_img]+2*CurBordersize[in_img];
	objDiv.style.height=CurHeight[in_img]+2*CurBordersize[in_img];
	
	objTr = document.getElementById('trContent'+in_img);
	objTr.height=CurHeight[in_img]+2*CurBordersize[in_img]-2*m_size;
	
	objTd = document.getElementById('tdContent'+in_img);
	objTd.height=CurHeight[in_img]+2*CurBordersize[in_img]-2*m_size;
	
	objImg.style.top=CurBordersize[in_img];
	objImg.style.left=CurBordersize[in_img];
  
  	objDiv.style.top=CurTop[in_img];
  	objDiv.style.left=CurLeft[in_img];

	refProcess[in_img] = setTimeout("ZoomProcess('"+in_img+"')",30);
	if (StepWidth[in_img]>0)
	{
	  if (step_index[in_img]==step_count[in_img]) 
	  {
	  	clearTimeout(refProcess[in_img]);
		
		
		objImg_buf = document.getElementById(in_img+'_buf');
		objImg = document.getElementById(in_img);
		
		objImg.style.left=EndLeft[in_img]+CurBordersize[in_img];
		objImg.style.top=EndTop[in_img]+CurBordersize[in_img];
		objImg.style.zIndex=12;

		objImg_buf.style.zIndex=-1;
		
		ShowText(in_img);
	  }
	}
	else
	{
	  if (step_index[in_img]==step_count[in_img]) 
	  {
	  	clearTimeout(refProcess[in_img]);

		objImg_buf = document.getElementById(in_img+'_buf');
		objImg = document.getElementById(in_img);
		
		objImg.style.left=CurLeft[in_img]+CurBordersize[in_img];
		objImg.style.top=CurTop[in_img]+CurBordersize[in_img];
		objImg.style.zIndex=12;
		
		objImg_buf.style.zIndex=-1;

  		objImg_buf.src=''
  		objImg_buf.width=1;
  		objImg_buf.height=1;
		
	  	objImg.style.zIndex=2;
	  	objDiv.style.zIndex=1;
		objTxt = document.getElementById(divText[in_img]);
  		objTxt.style.zIndex=2;
  		
  		if (LastIdOpen==in_img)
  		{
  			OpenState=0;
  			if (document.getElementById('divKuzPhotos')!=null) ReturnNormalWidth();
  		}
  		  		
	  }
	}
 
  return false;
}

function HideText(in_img) 
{
	objDiv = document.getElementById(divText[in_img]);
  	objDiv.innerHTML="";
  	objDiv.style.width=0;
  	objDiv.style.height=0;

	CurTextsize[in_img] = BigTextsize[in_img];
	EndTextsize[in_img] = 0;
	StepTextsize[in_img] = -base_vel_index;

	CurRealWidth[in_img] = (RealWidth[in_img]-BigWidth[in_img]);
	EndRealWidth[in_img] = 0;
	StepRealWidth[in_img] = (-1)*Math.ceil(CurRealWidth[in_img]/(BigTextsize[in_img]/base_vel_index));

	CurRealHeight[in_img] = (RealHeight[in_img]-BigHeight[in_img]);
	EndRealHeight[in_img] = 0;
	StepRealHeight[in_img] = (-1)*Math.ceil(CurRealHeight[in_img]/(BigTextsize[in_img]/base_vel_index));
	
	ZoomText(in_img)
	
}

function ShowText(in_img) 
{
	CurTextsize[in_img] = 0;
	EndTextsize[in_img] = BigTextsize[in_img];
	StepTextsize[in_img] = base_vel_index;
	
	CurRealWidth[in_img] = 0;
	EndRealWidth[in_img] = (RealWidth[in_img]-BigWidth[in_img]);
	StepRealWidth[in_img] = Math.ceil(EndRealWidth[in_img]/(BigTextsize[in_img]/base_vel_index));

	CurRealHeight[in_img] = 0;
	EndRealHeight[in_img] = (RealHeight[in_img]-BigHeight[in_img]);
	StepRealHeight[in_img] = Math.ceil(EndRealHeight[in_img]/(BigTextsize[in_img]/base_vel_index));
	
	ZoomText(in_img)
	
}

function ZoomText(in_img) 
{			
	objDiv = document.getElementById(divMainBackground[in_img]);

	(Math.abs(EndTextsize[in_img]-CurTextsize[in_img])>Math.abs(StepTextsize[in_img])) ? CurTextsize[in_img]=parseInt(CurTextsize[in_img])+parseInt(StepTextsize[in_img]) : CurTextsize[in_img]=EndTextsize[in_img];
	(Math.abs(EndRealWidth[in_img]-CurRealWidth[in_img])>Math.abs(StepRealWidth[in_img])) ? CurRealWidth[in_img]=parseInt(CurRealWidth[in_img])+parseInt(StepRealWidth[in_img]) : CurRealWidth[in_img]=EndRealWidth[in_img];
	(Math.abs(EndRealHeight[in_img]-CurRealHeight[in_img])>Math.abs(StepRealHeight[in_img])) ? CurRealHeight[in_img]=parseInt(CurRealHeight[in_img])+parseInt(StepRealHeight[in_img]) : CurRealHeight[in_img]=EndRealHeight[in_img];
	
	if (BigTextalign[in_img]=='right')
	{
		CurWidth[in_img] = Math.floor(BigWidth[in_img])+Math.floor(CurTextsize[in_img])+Math.floor(CurRealWidth[in_img]);
		CurHeight[in_img] = Math.floor(BigHeight[in_img])+Math.floor(CurRealHeight[in_img]);
	}
	
	
	objImg = document.getElementById(in_img);
	objImg.style.clip="rect(0, "+Math.floor(BigWidth[in_img]+CurRealWidth[in_img])+", "+Math.floor(BigHeight[in_img]+CurRealHeight[in_img])+", 0)";
	
	if (BigTextalign[in_img]=='right')
	{
		objDiv.style.width=CurWidth[in_img]+2*CurBordersize[in_img];
		objDiv.style.height=CurHeight[in_img]+2*CurBordersize[in_img];

		objTr = document.getElementById('trContent'+in_img);
		objTr.height=CurHeight[in_img]+2*CurBordersize[in_img]-2*m_size;
	
		objTd = document.getElementById('tdContent'+in_img);
		objTd.height=CurHeight[in_img]+2*CurBordersize[in_img]-2*m_size;

		objDiv = document.getElementById(divText[in_img]);
	  	objDiv.style.left=BigLeft[in_img]+2*CurBordersize[in_img]+BigWidth[in_img]+CurRealWidth[in_img];
	  	objDiv.style.top=BigTop[in_img]+CurBordersize[in_img];
	  	objDiv.style.width=Math.max(0,CurTextsize[in_img]-CurBordersize[in_img]);
	  	objDiv.style.height=CurHeight[in_img];
		
	}

	
  	refProcess[in_img+'text'] = setTimeout("ZoomText('"+in_img+"')",30);
	
	if (StepTextsize[in_img]>0)
	{
	  if (CurTextsize[in_img]>=EndTextsize[in_img]) 
	  {
	  	clearTimeout(refProcess[in_img+'text']);

		objDiv = document.getElementById(divText[in_img]);
	  	objDiv.style.left=BigLeft[in_img]+2*CurBordersize[in_img]+BigWidth[in_img]+CurRealWidth[in_img];
	  	objDiv.style.top=BigTop[in_img]+CurBordersize[in_img];
	  	objDiv.style.width=EndTextsize[in_img]-CurBordersize[in_img];
	  	objDiv.style.height=CurHeight[in_img];
	  	objDiv.innerHTML='<table height="100%" width=100% border=0 ><tr valign=top><td><div align=right onclick="CloseImage();" style="cursor: pointer;"><img src="img/close.png"></div></td></tr><tr valign="bottom"><td><div style="margin-left: 30; overflow: auto; color: '+BigTextcolor[in_img]+'">'+BigText[in_img]+'</div></td></tr></table>';
		
		
	  }
	}
	else
	{
	  if (CurTextsize[in_img]<=EndTextsize[in_img]) 
	  {
	  	clearTimeout(refProcess[in_img+'text']);

		objImg_buf = document.getElementById(in_img+'_buf');
		objImg_buf.style.zIndex=12;

		objImg = document.getElementById(in_img);
		objImg.style.zIndex=-1;
		objImg.style.top=-1500;
		objImg.style.left=-1500;
		objImg.src=SmlSource[in_img];
		objImg.style.clip="rect(0, auto, auto, 0)";
		objImg.width=parseInt(SmlWidth[in_img]);
		objImg.height=parseInt(SmlHeight[in_img]);
		
	  	ZoomProcess(in_img);
	  }
	}
 
  return false;
}

function CloseImage()
{
	var in_img=InImage;
	
	ZoomImage(in_img,BigTextcolor[in_img],SmlSource[in_img],BigSource[in_img],BigLeft[in_img],BigTop[in_img],BigWidth[in_img],BigHeight[in_img],RealHeight[in_img],RealWidth[in_img],divMainBackground[in_img],divText[in_img],SmlBorder[in_img],BigBorder[in_img],BigBackcolor[in_img],BigText[in_img],BigTextalign[in_img],BigTextsize[in_img]);
}

