var zI=1002;

window.onscroll = function()
{
	look_at_fix2('adm_place');
}
window.onresize = function()
{
	look_at_fix2('adm_place');
}

function look_at_fix2(id)
{
	if(document.getElementById(id))
	{
		var p_img=document.getElementById(id);
		x=document.documentElement.scrollLeft;
		y=document.documentElement.scrollTop;
		x+=document.documentElement.clientWidth-p_img.clientWidth;
		//y+=Math.round(document.documentElement.clientHeight/2);
		//p_img.style.left=x+'px';
		p_img.style.top=y+'px';
	}
}

function setCookie (name, value, expires, path, domain, secure)
{
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name)
{
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = "";
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function add_c_adm_pl(mode)
{
	var current_date = new Date;
	var cookie_year = current_date.getFullYear() + 1;
	var cookie_month = current_date.getMonth();
	var cookie_day = current_date.getDate();
	var the_exp = cookie_day+"/" + cookie_month + "/" + cookie_year + " 00:00:00";

	setCookie("adm_pl_op", mode, the_exp, "/");
}

function vis_adm_place(t)
{
	var vis_t={'hide':{0:'hidden',1:'visible',2:8},'show':{0:'visible',1:'hidden',2:36}};
	var pls=document.getElementById('adm_place').childNodes;
	var pl;
	for(i=0;i<pls.length;i++)
	{
		if(pls[i].nodeType!=3)
			{
				pl=pls[i];
				break;
			}
	}
	var alements=pl.childNodes;

	for(ind in alements)
	{
		el = alements[ind];
		if(el.nodeType!=3 && !isNaN(ind)) el.style.visibility=vis_t[t][0];
	}
	arr=document.getElementById('a_show_lnk').style.visibility=vis_t[t][0];
	arr=document.getElementById('a_hide_lnk').style.visibility=vis_t[t][1];
	pl.style.height=vis_t[t][2]+'px';
	add_c_adm_pl(t);
	return false;
}

function lets_round(q)
{
var bck=q.body.style.backgroundColor;
	obj=q.getElementById('search');
	round_corners('search',obj.offsetHeight/2+1,obj.offsetHeight/2+1,'#C3C3C3',{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('search',obj.offsetHeight/2-3,obj.offsetHeight/2-4,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('menu_row',8,8,'#f2c772',{'lt':false,'rt':false,'rb':true,'lb':true});
	round_corners('menu_row',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('search_tools_place',8,8,'#a6a6a6',{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('search_tools_place',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('nav_place',8,8,'#899e8f',{'lt':false,'rt':false,'rb':true,'lb':true});
	round_corners('nav_place',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('nav_place_lith',8,8,'#899e8f',{'lt':false,'rt':false,'rb':true,'lb':true});
	round_corners('nav_place_lith',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('about_place',8,8,'#899e8f',{'lt':false,'rt':false,'rb':true,'lb':true});
	round_corners('about_place',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('but1',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('but1',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('but11',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('but11',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('but12',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('but12',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('but2',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('but2',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('but3',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('but3',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('but4',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('but4',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('but5',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('but5',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('but6',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('but6',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('q_but',8,8,'#899e8f',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('q_but',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('news_place',8,8,'#a6a6a6',{'lt':false,'rt':false,'rb':true,'lb':true});
	round_corners('news_place',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('poll_place',8,8,'#a6a6a6',{'lt':false,'rt':false,'rb':true,'lb':true});
	round_corners('poll_place',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('map_place',8,8,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('footer',8,8,'#f2c772',{'lt':false,'rt':false,'rb':true,'lb':true});
	round_corners('footer',6,6,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('proj_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('about_proj_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('stream_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('vacant_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('cat_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('sub_group_tbl',6,6,'#0D4B8F',{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('sub_group_tbl',3,3,'#ddd',{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('sub_group_tbl',3,3,bck,{'lt':false,'rt':false,'rb':true,'lb':true});
	round_corners('sub_cat_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('itm_tbl',10,10,'#959595',{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('itm_tbl',6,6,'#ccc',{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('itm_tbl',4,4,bck,{'lt':true,'rt':true,'rb':true,'lb':true});
	round_corners('about_rus_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('about_info_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
	round_corners('branch_place',8,8,bck,{'lt':true,'rt':true,'rb':false,'lb':false});
}

// Фича ещё пригодится, ибо заказчик не ведает, что творит!
// window.onscroll = function()
// {
// look_at_fix();
// }
// Убираем каменты и превьюшка поползёт.

function print_back(color,op,x,y,w,h)
{
	if(!x) x=0;
	if(!y) y=0;
	if(!w) w=document.body.parentNode.scrollWidth+'px';
	if(!h) h=document.body.parentNode.scrollHeight+'px';
	b=document.createElement('div');
	b.id="back_trans";
	b.style.position='absolute';
	b.style.backgroundColor=color;
	b.style.opacity='0.'+op;
	b.style.filter='alpha(opacity='+op+')';
	b.style.zIndex='1002';
	b.style.left=x+'px';
	b.style.top=y+'px';
	b.style.width=w;
	b.style.height=h;
	document.body.appendChild(b);
}


function look_at_fix()
{
	if(document.getElementById('prev_img'))
	{
		var p_img=document.getElementById('prev_img');
		x=document.documentElement.scrollLeft;
		y=document.documentElement.scrollTop;
		x+=Math.round(document.documentElement.clientWidth/2)-300;
		y+=Math.round(document.documentElement.clientHeight/2)-200;
		p_img.style.left=x+'px';
		p_img.style.top=y+'px';
	}
}
function pr_image(src)
{
	window.open('/preview_image.php?filename='+src,'print','width=2,height=2,status=no,toolbar=no,menubar=no, scrollbars=no, resizable=no, left=0, top=0');
	return false;
}

var prev_img_op=0;
function HidePrevImg()
{
	if(prev_img_op<=0)
	{
		document.getElementById('back_trans').parentNode.removeChild(document.getElementById('back_trans'));
		document.getElementById('prev_img').parentNode.removeChild(document.getElementById('prev_img'));
	}
	else setTimeout("Timeout_Hide()",50);
}
function Timeout_Hide()
{
	document.getElementById('back_trans').style.opacity=prev_img_op;
	document.getElementById('back_trans').style.filter="alpha(opacity="+prev_img_op*100+")";
	document.getElementById('prev_img').style.opacity=prev_img_op;
	document.getElementById('prev_img').style.filter="alpha(opacity="+prev_img_op*50+")";
	prev_img_op-=0.05;
	HidePrevImg();
}
function print_prev_img(path,ititle)
{
	document.getElementById('back_trans').onclick=HidePrevImg;
	path = path.replace(/.+\?.*image=/,"");
	div=document.createElement('div');
	div.style.position='absolute';
		
	document.getElementById('back_trans').display="none";
	div.display="none";
		
	div.style.opacity=prev_img_op;
	div.style.filter="alpha(opacity="+prev_img_op+")";
	document.getElementById('back_trans').style.opacity=prev_img_op;
	document.getElementById('back_trans').style.filter="alpha(opacity="+prev_img_op+")";
	divW=622;
	div.style.width=divW+'px';
	div.style.height='450px';
	div.style.zIndex='1003';
	div.style.background="transparent";
	x=document.documentElement.scrollLeft;
	y=document.documentElement.scrollTop;
	x+=Math.round(document.documentElement.clientWidth/2)-300;
	y+=Math.round(document.documentElement.clientHeight/2)-200;
	div.style.left=x+'px';
	div.style.top=y+'px';
	div.id="prev_img";
	
	r_x=10;
	var t_r=document.createElement('b');
	t_r.style.display="block";
	t_r.style.height=r_x+"px";
	t_r.style.width=div.style.width;
	for(i=-1*(r_x); i<0; i++)
	{
		d_x=Math.ceil(r_x-Math.pow((Math.pow(r_x,2)-Math.pow(i,2)),0.5));
		var b=document.createElement('b');
		b.style.width=(divW-2*(d_x+1))+'px';
		b.style.height='1px';
		b.style.display="block";
		b.style.overflow="hidden";
		b.style.marginLeft=d_x+'px';
		b.style.backgroundColor="#fff";
		if(i==-1*(r_x)) b.style.backgroundColor="#959595";
		b.style.border="0px solid #959595";
		b.style.borderWidth="0px 1px 0px 1px";
		b.innerHTML='';
		t_r.appendChild(b);
	}
	div.appendChild(t_r);
	inDiv=document.createElement('div');
	inDiv.style.backgroundColor='#fff';
	inDiv.style.height="425px";
	inDiv.style.border="0px solid #959595";
	inDiv.style.borderWidth="0px 1px 0px 1px";
	inDiv.innerHTML+='<img src="/image100.php?sz=s3&image='+path+'" style="cursor:pointer; clear:both; margin-left:10px;" onclick="HidePrevImg()">';
	prev_tbl='<table border=0 width="100%"><tbody><tr>';
	prev_tbl+='<td align="right" width="75"><a onclick="return pr_image(\''+path+'\');" href="#"><img src="/usr/image/printprev.gif"></a></td>';
	prev_tbl+='<td align="center"><b style="font-size:14px; color:#7a7a7a;/* font-family:Arial;*/">'+ititle+'</b></td>';
	prev_tbl+='<td align="left" width="75"><a href="#" onclick="HidePrevImg(); return false;"><img src="/usr/image/closeprev.gif"></a></td>';
	prev_tbl+='</tr></tbody></table>';
	inDiv.innerHTML+=prev_tbl;
	div.appendChild(inDiv);
	
	var t_r=document.createElement('b');
	t_r.style.display="block";
	t_r.style.height=r_x+"px";
	t_r.style.width=div.style.width;
	for(i=0; i<r_x; i++)
	{
		d_x=Math.ceil(r_x-Math.pow((Math.pow(r_x,2)-Math.pow(i,2)),0.5));
		b=document.createElement('b');
		b.style.width=(divW-2*(d_x+1))+'px';
		b.style.height='1px';
		b.style.display="block";
		b.style.overflow="hidden";
		b.style.marginLeft=d_x+'px';
		b.style.backgroundColor="#fff";
		if(i==r_x-1) b.style.backgroundColor="#959595";
		b.style.border="0px solid #959595";
		b.style.borderWidth="0px 1px 0px 1px";
		b.innerHTML='';
		t_r.appendChild(b);
	}
	div.appendChild(t_r);
	//document.body.appendChild(div);
	document.body.insertBefore(div,document.getElementById('head_row'));
	
	document.getElementById('back_trans').display="block";
	div.display="block";
	
	ApearPrevImg();
}
function ApearPrevImg()
{
	if(prev_img_op<1)
	{
		
		setTimeout("Timeout_Apear()",50);
	}
	else prev_img_op=0.6;
}
function Timeout_Apear()
{
	if(prev_img_op>=0.6)
	{
		document.getElementById('back_trans').style.opacity=0.6;
		document.getElementById('back_trans').style.filter="alpha(opacity=60)";
	}
	else
	{
		document.getElementById('back_trans').style.opacity=prev_img_op;
		document.getElementById('back_trans').style.filter="alpha(opacity="+prev_img_op*100+")";
	}
	document.getElementById('prev_img').style.opacity=prev_img_op;
	document.getElementById('prev_img').style.filter="alpha(opacity="+prev_img_op*100+")";
	prev_img_op+=0.05;
	ApearPrevImg();
}

	function print_corner(rx,ry,bck,t_x,t_y,corner)
	{
		var s,source=document.createElement('b');
		var w_prev;
		source.innerHTML="";
		
		h=1;
		switch(corner)
		{
			case 'lt':
				for(i=-1*ry;i<=0;i+=h)
				{
					w=rx-Math.pow(Math.pow(rx,2)*(1-Math.pow(i,2)/Math.pow(ry,2)),0.5);
					w=Math.ceil(w);
					s=document.createElement('b');
					s.innerHTML='';
					s.style.width=w+"px";
					s.style.height=h+"px";
					s.style.overflow="hidden";
					s.style.backgroundColor=bck;
					s.style.display="block";
					source.appendChild(s);
				}
			break;
			case 'rt':
				for(i=-1*ry;i<=0;i+=h)
				{
					w=rx-Math.pow(Math.pow(rx,2)*(1-Math.pow(i,2)/Math.pow(ry,2)),0.5);
					w=Math.ceil(w);
					s=document.createElement('b');
					s.style.width=w+"px";
					s.style.height=h+"px";
					s.style.overflow="hidden";
					s.style.marginLeft=rx-w+"px";
					s.style.backgroundColor=bck;
					s.style.display="block";
					source.appendChild(s);
					
				}
			break;
			case 'lb':
				for(i=0;i<=ry;i+=h)
				{
					w=rx-Math.pow(Math.pow(rx,2)*(1-Math.pow(i,2)/Math.pow(ry,2)),0.5);
					w=Math.ceil(w);
					s=document.createElement('b');
					s.innerHTML='';
					s.style.width=w+"px";
					s.style.height=h+"px";
					s.style.overflow="hidden";
					s.style.backgroundColor=bck;
					s.style.display="block";
					source.appendChild(s);
					
				}
			break;
			case 'rb':
				for(i=0;i<=ry;i+=h)
				{
					w=rx-Math.pow(Math.pow(rx,2)*(1-Math.pow(i,2)/Math.pow(ry,2)),0.5);
					w=Math.ceil(w);
					s=document.createElement('b');
					s.innerHTML='';
					s.style.width=w+"px";
					s.style.height=h+"px";
					s.style.overflow="hidden";
					s.style.marginLeft=rx-w+"px";
					s.style.backgroundColor=bck;
					s.style.display="block";
					source.appendChild(s);
				}
			break;
		}
		source.style.width=rx+"px";
		source.style.height=ry+"px";
		source.style.backgroundColor="transparent";
		source.style.position="absolute";
		source.style.display="block";
		source.style.zIndex=zI;
		
		
		source.style.left=t_x+"px";
		source.style.top=t_y+"px";
		return source;
	}
	function round_corners(q,rx,ry,bck,corners)
	{
		var obj;
		if(!(obj=document.getElementById(q))) return false;
		var w=obj.offsetWidth;
		var h=obj.offsetHeight;
		var pos=getAbsolutePos(obj);
		var l=pos['x'];
		var t=pos['y'];
		var t_x={'lt':l,'rt':l+w-rx,'rb':l+w-rx,'lb':l};
		var t_y={'lt':t,'rt':t,'rb':t+h-ry-1,'lb':t+h-ry-1};
		
		//alert(t_x['lt']+' - '+obj.scrollTop);
		for(i in corners)
		{
			if(corners[i])
				{
					var targ=print_corner(rx,ry,bck,t_x[i],t_y[i],i);
					document.body.insertBefore(targ,document.getElementById('head_row'));
				}
		}
		
	}
	function getAbsolutePos(el)
	{
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent)
		{
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
		}
	return r;
	}


var move_m=0;
var menu_marg=0;
function move_menu(mode)
{
	move_m=mode;
	var menu=document.getElementById('menu_ul');
	var mup=document.getElementById('top_m').style;
	var mdwn=document.getElementById('bot_m').style;
	mup.cursor="pointer";
	mdwn.cursor="pointer";
	var step=2;
	step=step*mode;
	if((menu_marg>menu.parentNode.offsetHeight+4-menu.scrollHeight && mode<0) || (menu_marg<0 && mode>0))
		{
			menu_marg+=step;
			menu.style.marginTop=menu_marg+"px";	
			mdwn.visibility="visible";
			mup.visibility="visible";
			setTimeout("check_menu()",100);
		}
	if(menu_marg<=menu.parentNode.offsetHeight+4-menu.scrollHeight) {mdwn.visibility="hidden";}
	if(menu_marg>=0) {mup.visibility="hidden";}
}
function check_menu()
{
	if(move_m!=0) move_menu(move_m);
}

function get_scroll_pos()
{
	var obj;
	if(obj=document.getElementById('ab_text'))
	{
	obj=obj.parentNode;
	var Ratio_scroll=obj.offsetHeight/obj.scrollHeight;
	var scr_b=document.getElementById('ab_bar');
	var p_h=scr_b.parentNode.offsetHeight;
	var sb_h=Math.ceil(Ratio_scroll*p_h);
	scr_b.style.height=sb_h+"px";
	scr_b.style.marginTop="0px"
	}
}
var scr_m=0;
var num_marg=0;
var ob_n_marg=0;

function scroll(mode)
{
	
	scr_m=mode;
	var marg;
	var scrll=document.getElementById('ab_bar');
	var step=1;
	step=mode*step;
	var txt=document.getElementById('ab_text');
	var R_scr=txt.scrollHeight/scrll.parentNode.offsetHeight;
	if((ob_n_marg+step*R_scr>txt.parentNode.offsetHeight-txt.scrollHeight && mode>0) || (ob_n_marg<0 && mode<0)) 
	{
		num_marg+=step;
		if(num_marg<0)	num_marg=0;
		else if(num_marg>scrll.parentNode.offsetHeight-scrll.scrollHeight)	num_marg=scrll.parentNode.offsetHeight-scrll.scrollHeight;
		ob_n_marg-=step*R_scr;
		scrll.style.marginTop=num_marg+"px";
		txt.style.marginTop=ob_n_marg+"px";
		setTimeout("check_scrll()",100);
	}
}
function check_scrll()
{
if(scr_m!=0) scroll(scr_m);
}
function show_prev_picture(e,s)
{
	if(e.pageX || e.pageY)
	{
		x=e.pageX;
		y=e.pageY;
	}
	else
	{
		x=e.clientX+(document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
		y=e.clientY+(document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}
	var pic;
	if(document.getElementById('prev_pic'))
	{
		pic=document.getElementById('prev_pic');
		pic.style.left=x+15+"px";
		pic.style.top=y+15+"px";
	}
	else
	{
		pic=document.createElement("img");
		pic.style.position="absolute";
		pic.id='prev_pic';
		pic.src="/image100.php?image="+s;
		pic.style.width="126px";
		pic.style.height="95px";
		pic.style.left=x+15+"px";
		pic.style.top=y+15+"px";
		pic.style.zIndex="2000";
		document.body.appendChild(pic);
	}
}
function hide_prev_picture()
{
	if(document.getElementById('prev_pic')) document.body.removeChild(document.getElementById('prev_pic'));
}
function showCatList(m)
{
	lis=document.getElementById('cat_list_place_ul').childNodes;
	if(m==1)
	{
		for(i in lis)
		{
			if(lis[i].tagName=='LI') lis[i].style.display='list-item';
		}
		document.getElementById('ShCat_list_anch').href="javascript:showCatList(0)";
		document.getElementById('ShCat_list_anch').innerHTML="Скрыть список";
	}
	else
	{
		for(i in lis)
		{
			if(lis[i].tagName=='LI') lis[i].style.display='none';
		}
		document.getElementById('ShCat_list_anch').href="javascript:showCatList(1)";
		document.getElementById('ShCat_list_anch').innerHTML="Показать весь список";
	}
}