var height, width;
var og, stepL, stepR, curL, curR, stepT, stepB, curT, curB, gw,gh,td,ih,ids;
var iter=1; var oact=0;

function initdiv(){
if(window.innerHeight>0){
height = window.innerHeight;
width = window.innerWidth;
} else {
height = document.body.offsetHeight;
width  = document.body.offsetWidth;
}
//	if (document.all) {
//		height = document.body.offsetHeight;
//		width  = document.body.offsetWidth;
//	}   else {
//		if (document.layers){
//			height = window.innerHeight;
//			width = window.innerWidth;
//		}
//	}
	if(oact>0){
		pw=p.style.width.substr(0,p.style.width.length-2);
		ph=p.style.height.substr(0,p.style.height.length-2);
		p.style.left=(width-pw-20)/2;
		p.style.top=(height-ph)/2+document.body.scrollTop;
		pb.style.left=(width-pw-20)/2-20;
		pb.style.top=(height-ph)/2-21+document.body.scrollTop;
	}
}

function h(){
	if(td==1){
		oact=0;
		p.innerHTML='';
		p.style.width=120;
		p.style.height=120;
		p.style.left=0;
		p.style.top=0;
		pb.style.width=120;
		pb.style.height=120;
		pb.style.left=0;
		pb.style.top=0;
		p.style.visibility='hidden';
		pb.style.visibility='hidden';
		td=0;
	}
}

function a(o,m,w,h,ihtml,dscr){
var dscrt='';
if(typeof(_picarray)!="undefined" && !w && m!=1 && oact!=1){
w=_picarray[o][2];
h=_picarray[o][3];
ihtml="<img src="+_picarray[o][4]+">";
dscr=_picarray[o][5];
o2h=document.getElementById("pic"+o);
dscrt="[<a class=nn href='javascript:void(0);' onClick='h(o2h);a("+(_picarray.length-1)+");'>в конец</a>] "+dscrt;
dscrt="[<a class=nn href='javascript:void(0);' onClick='h(o2h);a(0);'>в начало</a>] "+dscrt;
dscrt="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a class=nn href='"+_picarray[o][4]+"' target=_blank>upload</a>] "+dscrt;
if(o<(_picarray.length-1)){dscrt="[<a class=nn href='javascript:void(0);' onClick='h(o2h);a("+(o+1)+");'>»след»</a>] "+dscrt;} 
if(o>0){dscrt="[<a class=nn href='javascript:void(0);' onClick='h(o2h);a("+(o-1)+");'>«пред«</a>] "+dscrt;} 
dscrt="<b>"+(o+1)+" из "+(_picarray.length)+"</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+dscrt;
o=document.getElementById("pic"+o);
o.style.opacity=0.3;
o.style.filter="alpha(opacity=30)";
}
	gw=w; gh=h; ih=ihtml;ids=dscr;idst=dscrt;

	if(oact>0 && m!=1){return;}
	
	if(oact>0){
		p.innerHTML='';
		p.style.width=120;
		p.style.height=120;
		p.style.left=0;
		p.style.top=0;
		pb.style.width=120;
		pb.style.height=120;
		pb.style.left=0;
		pb.style.top=0;
		p.style.visibility='hidden';
		pb.style.visibility='hidden';
		oact=0;
//		td=0;
//	}
	} else {
		var l = 0;var t = 0;
		while (o){l += o.offsetLeft;t += o.offsetTop;o= o.offsetParent;}
		p.style.left=l;
		p.style.top=t;
		p.style.visibility='visible';
		ol=l;
		ot=t;
		curL=l;
		curR=curL+120;
//	if (document.all) {
//		height = document.body.offsetHeight;
//		width  = document.body.offsetWidth;
//	}   else {
//		if (document.layers){
if(window.innerHeight>0){
height = window.innerHeight;
width = window.innerWidth;
} else {
height = document.body.offsetHeight;
width  = document.body.offsetWidth;
}
//		}
//	}

		dx=(width-w-20)/2;
		stepL=(curL-dx)/8;
		stepR=(width-curR-dx)/8;

		curT=t-document.body.scrollTop;
		curB=curT+120;

		if((height-50)<h){dy=50;} else {dy=(height-h)/2;}
		stepT=(curT-dy)/8;
		stepB=(height-curB-dy)/8;

		og=p;
		fade();
		oact=1;
	}

}

function fade(){
	curL=curL-stepL;
	curR=curR+stepR;
	curT=curT-stepT;
	curB=curB+stepB;
	og.style.left=curL;
	og.style.width=(curR-curL);
	og.style.top=curT+document.body.scrollTop;
	og.style.height=(curB-curT);
	
	if ( iter < 8 ) {
		setTimeout(fade,1); 
		iter++;
	} else {
		iter=1;
		og.innerHTML=ih;
		og.style.left=dx;
		og.style.width=gw;
		og.style.top=dy+document.body.scrollTop;
		og.style.height=gh;
//		pb.style.left=dx-20;
//		pb.style.width=gw+40;
//		pb.style.top=dy-21+document.body.scrollTop;
//		pb.style.height=gh+41;
		dx1=og.style.left; 
		dx1=dx1.replace("px","");
		dx1=dx1-20;
		pb.style.left=dx1;
		pb.style.width=gw+40;
		dy1=og.style.top; 
		dy1=dy1.replace("px","");
		dy1=dy1-21;
		pb.style.top=dy1;
		pb.style.height=gh+41;
		pb.style.visibility='visible';
//		pb.innerHTML="<b>"+ids+"</b>";
pb.innerHTML="<table width=100% style='color:white;' border=0 cellspacing=0 cellpadding=2 height=100%><tr height=50%><td align=center valign=top>"+idst+"</td></tr><tr height=50%><td align=center valign=bottom><b>"+ids+"</b></td></tr></table>";
		td=1;
	}
	
}




