trans_bck=document.createElement('div');
trans_bck.className="fullbck";

function show_gallery()
{
	trans_bck.style.opacity="0.5";
	trans_bck.style.filter="alpha(opacity=50)";
	document.body.appendChild(trans_bck);
	document.getElementById('gallery').style.display="block";
}

function hide_gallery()
{
	document.getElementById('gallery').style.display="";
	document.body.removeChild(trans_bck);
}


var maxAppearM=0;
function show_prev_img(url,tx,w,h)
{
	trans_bck.style.opacity="0.5";
	trans_bck.style.filter="alpha(opacity=50)";
	document.body.appendChild(trans_bck);
	
	fs_im=document.getElementById('full_size_image');
	nw=(w+100<document.documentElement.clientWidth)?w:document.documentElement.clientWidth-100;
	nh=(h+100<document.documentElement.clientHeight)?h:document.documentElement.clientHeight-100;
	if(nw<w || nh<h)
	{
		if(nw<100) nw=100;
		if(nw>100 && nw<=300) nw=200;
		if(nw>300 && nw<=500) nw=400;
		if(nw>500 && nw<=700) nw=600;
		if(nw>700 && nw<=900) nw=800;
		if(nw>900 && nw<=1100) nw=1000;
		if(nh<100) nh=100;
		if(nh>100 && nh<=300) nh=200;
		if(nh>300 && nh<=500) nh=400;
		if(nh>500 && nh<=700) nh=600;
		if(nh>700 && nh<=900) nh=800;
		if(nh>900 && nh<=1100) nh=1000;
	
		
		prop=(nh/h<nw/w)?nh/h:nw/w;
		
		nsize=(nh/h<nw/w)?'x'+nh:nw+'x';
		w=Math.ceil(prop*w);
		h=Math.ceil(prop*h);
		url=url.replace('/usr/image/','/usr/image/convert/custom/'+nsize+'/');
		//alert(url);
	}
	//return false;
	fs_im.parentNode.style.width=w+"px";
	fs_im.style.width=w+"px";
	fs_im.parentNode.style.height=h+"px";
	fs_im.style.height=h+"px"
	//fs_im.parentNode.style.opacity="";
	//fs_im.parentNode.style.filter="alpha(opacity=65)";
	fs_tx=document.getElementById('prev_image_text');
	fs_tx.innerHTML=tx;
	fs_tx.style.width=w+"px";
	prev_img.style.display="block";
	
	maxAppearM=Math.round((document.documentElement.clientHeight)/2);
	def_top=-prev_img.clientHeight;
	prev_img.style.top=def_top+"px";
	prev_img.style.marginTop=-h/2-21+"px";
	prev_img.style.marginLeft=-w/2-52+"px";
	bufferTout("tout_appear('"+url+"',"+def_top+",0)",25);
}
function bufferTout(func,tout)
{
	tOut=setTimeout(func,tout);
}


function tout_appear(url,prev_top,bc)
{
	clearTimeout(tOut);
	bc+=0.1;
	prev_top+=50;
	
	//trans_bck.style.opacity=bc;
	//trans_bck.style.filter="alpha(opacity="+ bc*100 +")";
	
	prev_img.style.top=prev_top+"px";
	if(prev_top>=maxAppearM-50)
	{
		prev_img.style.top="";//maxAppearM+"px";
// 		prev_img.className='IeScroll';
		fs_im=document.getElementById('full_size_image');
		fs_im.src=url;
		
		fs_im.onload=function()
		{
			//this.parentNode.style.opacity="1";
			//this.parentNode.style.filter="alpha(opacity=100)";
			this.style.visibility="visible";
		}
	}
	else bufferTout("tout_appear('"+url+"',"+prev_top+","+bc+")",30);
}

function tout_disappear(prev_left,bc)
{
	clearTimeout(tOut);	
	prev_left-=100;
	bc-=0.06;
	prev_img.style.left=prev_left+"px";
// 		trans_bck.style.opacity=bc;
// 		trans_bck.style.filter="alpha(opacity="+ bc*100 +")";
	if(prev_left+document.documentElement.scrollLeft<=-prev_img.clientWidth)
	{
		prev_img.style.left="";
		fs_im=document.getElementById('full_size_image');
		fs_im.parentNode.style.width=0;
		fs_im.parentNode.style.height=0;
		fs_im.src='/usr/image/common/empty.gif';
		fs_im.style.visibility='';
		fs_tx=document.getElementById('prev_image_text');
		fs_tx.innerHTML='';
		prev_img.style.display="";
		document.body.removeChild(trans_bck);
	}
	else bufferTout("tout_disappear("+prev_left+","+bc+")",20);
}

function hide_prev_img()
{
	prev_img.className='';
	bufferTout("tout_disappear("+document.documentElement.clientWidth/2+","+trans_bck.style.opacity+")",25);
}


var scrllMod=0;
	



var inDragin=false;
var mousePos;
var c_scrollThumbMarg=0;
var dragObj=null;
var dragPrnt=null;
var dragDest=null;
function startDrag(e)
{
	if(inDragin)
	{
		if(dragObj!=null && dragPrnt!=null && dragDest!=null && (dragDest.toUpperCase()=='X' || dragDest.toUpperCase()=='Y'))
		{
			if(mousePos==null) mousePos=e['client'+dragDest.toUpperCase()];
			
			m=e['client'+dragDest.toUpperCase()]-mousePos;
			mousePos=e['client'+dragDest.toUpperCase()];
			if(dragDest.toUpperCase()=='X')
			{
				dest=(m>0)?'right':'left';
				Ratio=document.getElementById(dragObj).clientWidth/document.getElementById(dragObj).parentNode.clientWidth;
			}
			else
			{
				dest=(m>0)?'bottom':'top';
				Ratio=document.getElementById(dragObj).clientHeight/document.getElementById(dragObj).parentNode.clientHeight;
			}
			scroll_content(1,dest,dragPrnt,dragObj,Math.abs(m/Ratio),null)
			return false;
		}
	}
	else return true;
}
var wheelMax=0;
function wheel(event,scrollObj,scrollThumb,step,ord)
{
	var wheelDelta = 0;
	var step =(step)?step : 45;
	var ord =(ord)?ord : 'Y';
	if (!event) event = window.event;
	if (event.wheelDelta) wheelDelta = -event.wheelDelta/120;
	else if (event.detail) wheelDelta = event.detail/3;
	if(ord=="X")dest=(wheelDelta>0)?'right':'left';
	if(ord=="Y")dest=(wheelDelta>0)?'bottom':'top';
	if(scroll_content(1,dest,scrollObj,scrollThumb,Math.abs(step*wheelDelta),null))
	{
		wheelMax=0
		if (event.preventDefault) event.preventDefault();
		event.returnValue = false;
		
	}
	else
	{
		wheelMax+=Math.abs(wheelDelta);
		if(wheelMax<4)
		{
			if (event.preventDefault) event.preventDefault();
			event.returnValue = false;
		}
		else wheelMax=4;
	}
}

///////Скроллер////////
var scrollers=new Array(); //Массив всех скроллеров
var bodyMouseUp=function(){}; //функция body.onmouseup
var bodyMouseMove=function(){}; //функция body.onmousedown
var windowResize=function(){}; //функция body.onresize
//Создание скроллера
function createScroller(scrollerName)
{
	scrollers[scrollerName]=new contentScroller(scrollerName);
}
contentScroller=function(objName)
{
	//Переменные DOM
	this.scrollObject; //Блок с контентом
	this.scrollerButtonNegative; // Кнопка "влево" или "вверх", 
	this.scrollerButtonPositive; // Кнопка "вправо" или "вниз", 
	this.scrollerThumb; // Ползунок
	//Переменные объекта body и window (функции)
	//Общие переменные скроллинга
	this.scrollOrd="Y"; // Направление скроллирования ("x" или "y"). К регистру нечувствительно.
	var scrollRatio=1; // Соотношение видимой и невидимой области скроллируемого блока
	var thumbRatio=1;
	this.hideBar=true; // Соотношение видимой и невидимой области скроллируемого блока
	this.scrollTime=50; // Таймаут скроллинга(в мс)
	this.scrollStep=15; // Шаг скроллера
	this.scrollMode=false;
	//Переменные drag'n'drop
	this.inDragin=false;
	this.mousePos=null;
	//Переменные для колёсика мыши
	this.scrollWheel=true; // Применение колёсика мыши
	this.wheelStep=3; // количество шагов скроллинга на шаг колёсика мыши
	this.wheelMax=3; // Максимаьный холостой ход колёсика
	var wheelCount=0;
	//Переменные ошибок
	this.errors=new Array(); // массив ошибок
	this.errorHandler="alert"; // обработчик ошибок
	
	//Инициализация скроллера
	this.initScroller=function(scrollObject,scrollerButtonPositive,scrollerButtonNegative,scrollerThumb)
	{
		try
		{
			var ord,ordNegative,item,thumbPlace;
			this.scrollObject=document.getElementById(scrollObject);
			this.scrollerButtonPositive=document.getElementById(scrollerButtonPositive);
			this.scrollerButtonNegative=document.getElementById(scrollerButtonNegative);
			this.scrollerThumb=document.getElementById(scrollerThumb);
			if(this.scrollerThumb) thumbPlace=this.scrollerThumb.parentNode.parentNode;
			switch(this.scrollOrd.toLowerCase())
			{
				case 'x':
					ord="Left";
					ordNegative="right";
					item="Width";
				break;
				case 'y':
					ord="Top";
					ordNegative="bottom";
					item="Height";
				break;
			}
			scrollRatio=(this.scrollObject['scroll'+item]!=0)?this.scrollObject['client'+item]/this.scrollObject['scroll'+item]:1;
			if(this.scrollerThumb) thumbRatio=this.scrollerThumb.parentNode['client'+item]/this.scrollObject['scroll'+item]
			if(scrollRatio>=1)
			{
				if(this.hideBar && this.scrollerThumb) thumbPlace.style.visibility='hidden';
				scrollRatio=1;
			}
			else if(this.hideBar && this.scrollerThumb) thumbPlace.style.visibility='visible';
			if(this.scrollerButtonPositive) this.scrollerButtonPositive.onmousedown=function(){scrollers[objName].scrollContent(true,ord.toLowerCase(),true);}
			if(this.scrollerButtonPositive) this.scrollerButtonPositive.onmouseup=function(){scrollers[objName].scrollContent(false);}
			if(this.scrollerButtonPositive) this.scrollerButtonNegative.onmousedown=function(){scrollers[objName].scrollContent(true,ordNegative.toLowerCase(),true);}
			if(this.scrollerButtonNegative) this.scrollerButtonNegative.onmouseup=function(){scrollers[objName].scrollContent(false);}
			if(this.scrollerThumb)
			{
				this.scrollerThumb.onclick=function()
				{
					scrollers[objName].inDragin=false;
					return false;
				}
				this.scrollerThumb.onmouseout=function(){return true;}
				this.scrollerThumb.onmousemove=function(event)
				{
					scrollers[objName].startDrag(event);
					return false;
				}
				this.scrollerThumb.onmouseup=function()
				{
					scrollers[objName].inDragin=false;
					scrollers[objName].mousePos=null;
					return false;
				}
				this.scrollerThumb.onmousedown=function()
				{
					scrollers[objName].inDragin=true;
					return false;
				}
				document.body.onmouseup=function()
				{
					bodyMouseUp();
					for(i in scrollers)
					{
						scrollers[i].inDragin=false;
						scrollers[i].mousePos=null;
					}
					return false;
				}
				document.body.onmousemove=function(event)
				{
					bodyMouseMove();
					for(i in scrollers)
					{
						if(scrollers[i].startDrag(event));
					}
					return true;
				}
				window.onresize=function()
				{
					windowResize()
					for(i in scrollers)
					{
						scrollers[i].recheckScroller();
					}
				}
				if (thumbPlace.addEventListener)
	 			{
	 				thumbPlace.addEventListener('DOMMouseScroll',scrollers[objName].wheel, false);
	 			}
	 			thumbPlace.onmousewheel =function(event){scrollers[objName].wheel(event)};
			}
			
			if(this.scrollWheel)
			{
				if (this.scrollObject.addEventListener)
	 			{
	 				this.scrollObject.addEventListener('DOMMouseScroll',scrollers[objName].wheel, false);
	 			}
	 			this.scrollObject.onmousewheel =function(event){scrollers[objName].wheel(event)};
 			}
			if(this.scrollerThumb)
			{
				this.scrollerThumb.style[ord.toLowerCase()]=thumbRatio*this.scrollObject['scroll'+ord]+"px";
				this.scrollerThumb.style[item.toLowerCase()]=(Math.round(scrollRatio*this.scrollerThumb.parentNode['client'+item]))+"px";
			}
		}
		catch(e){ this.setError(prepareException(e));}
	}
	this.recheckScroller=function()
	{
		try
		{
			var thumbPlace=this.scrollerThumb.parentNode.parentNode;
			switch(this.scrollOrd.toLowerCase())
			{
				case 'x':
					ord="Left";
					ordNegative="right";
					item="Width";
				break;
				case 'y':
					ord="Top";
					ordNegative="bottom";
					item="Height";
				break;
			}
			if(this.scrollObject['scroll'+ord]+this.scrollObject['client'+item]>this.scrollObject['scroll'+item]) this.scrollObject['scroll'+ord]=this.scrollObject['scroll'+item]-this.scrollObject['client'+item];
			scrollRatio=(this.scrollObject['scroll'+item]!=0)?this.scrollObject['client'+item]/this.scrollObject['scroll'+item]:1;
			if(this.scrollerThumb) thumbRatio=this.scrollerThumb.parentNode['client'+item]/this.scrollObject['scroll'+item];
			if(scrollRatio>=1)
			{
				if(this.hideBar && this.scrollerThumb) thumbPlace.style.visibility='hidden';
				scrollRatio=1;
			}
			else
			{
				if(this.hideBar && this.scrollerThumb){ thumbPlace.style.visibility='visible';}
			}
			if(this.scrollerThumb)
			{
				this.scrollerThumb.style[ord.toLowerCase()]=thumbRatio*this.scrollObject['scroll'+ord]+"px";
				this.scrollerThumb.style[item.toLowerCase()]=(Math.round(scrollRatio*this.scrollerThumb.parentNode['client'+item]))+"px";
			}
		}
		catch(e){ this.setError(prepareException(e));}
	}
	//Основная функция скроллинга блока. Переменные mode(bool) - скроллить или нет, dest(string) - направление скроллинга, tOut(bool) - рекурсивность с таймаутом, step(float) - шаг скроллига(по умолчанию берётся из переменной this.scrollStep)
	this.scrollContent=function(mode,dest,tOut,step)
	{
		try
		{
			if(step==null) step=this.scrollStep;
			this.scrollMode=mode;
			if(this.scrollMode)
			{
				
				var ord,item;
				var listMarg;
				var r;
				switch(dest)
				{
					case 'left':
						ord="Left";
						item="Width";
						r=-1;
					break;
					case 'top':
						ord="Top";
						item="Height";
						r=-1;
					break;
					case 'right':
						ord="Left";
						item="Width";
						r=1;
					break;
					case 'bottom':
						ord="Top";
						item="Height";
						r=1;
					break;
				}
				listMarg=this.scrollObject['scroll'+ord];
				if(listMarg+r*step<=0)
				{
					this.scrollObject['scroll'+ord]=0;
					if(this.scrollerThumb) this.scrollerThumb.style[ord.toLowerCase()]="0px";
					return !(listMarg<=0);
				}
				if(listMarg + r* step>=this.scrollObject['scroll'+item]-this.scrollObject['client'+item])
				{
					this.scrollObject['scroll'+ord]=this.scrollObject['scroll'+item]-this.scrollObject['client'+item];
					if(this.scrollerThumb) this.scrollerThumb.style[ord.toLowerCase()]=this.scrollObject['scroll'+ord]*thumbRatio+"px";
					return !(listMarg>=this.scrollObject['scroll'+item]-this.scrollObject['client'+item]);
				}
				this.scrollObject['scroll'+ord]=listMarg+r*step;
				if(this.scrollerThumb) this.scrollerThumb.style[ord.toLowerCase()]=this.scrollObject['scroll'+ord]*thumbRatio+"px";
				
				if(tOut) setTimeout("scrollers['"+objName+"'].timeoutContScrll('"+dest+"',true)",this.scrollTime);
				return true;
			}
		}
		catch(e){ this.setError(prepareException(e));}
	}
	// Функция вызова рекурсии скроллинга по таймауту
	this.timeoutContScrll=function(dest,tOut)
	{
		if(this.scrollMode) this.scrollContent(this.scrollMode,dest,tOut);
	}
	//Обработка метода drag'n'drop.
	this.startDrag=function(e)
	{
		try
		{
			if(!e) e=window.event;
			if(this.inDragin)
			{
				if(this.mousePos==null) this.mousePos=e['client'+this.scrollOrd.toUpperCase()];
				m=e['client'+this.scrollOrd.toUpperCase()]-this.mousePos;
				this.mousePos=e['client'+this.scrollOrd.toUpperCase()];
				if(this.scrollOrd.toUpperCase()=='X')
				{
					dest=(m>0)?'right':'left';
					item="Width";
				}
				else
				{
					dest=(m>0)?'bottom':'top';
					item="Height";
				}
				//this.scrollerThumb.style.top=parseFloat(this.scrollerThumb.style.top)+m+"px";
				this.scrollContent(true,dest,false,Math.abs(m/thumbRatio));
				//this.scrollContent(true,dest,false,m);
				return false;
			}
			else return true;
		}
		catch(e){ this.setError(prepareException(e));}
	}
	//Обработка колёсика мыши
	this.wheel=function(event)
	{
		try
		{
			var wheelDelta;
			var dest='';
			if (!event) event = window.event;
			if (event.wheelDelta) wheelDelta = -event.wheelDelta/120;
			else if (event.detail) wheelDelta = event.detail/3;
			if(scrollers[objName].scrollOrd.toUpperCase()=="X") dest=(wheelDelta>0)?'right':'left';
			if(scrollers[objName].scrollOrd.toUpperCase()=="Y") dest=(wheelDelta>0)?'bottom':'top';
			if(scrollers[objName].scrollContent(true,dest,false,scrollers[objName].wheelStep*scrollers[objName].scrollStep))
			{
				wheelCount=0;
				if (event.preventDefault) event.preventDefault();
				event.returnValue = false;
			}
			else
			{
				wheelCount+=Math.abs(wheelDelta);
				if(wheelCount<=scrollers[objName].wheelMax)
				{
					if (event.preventDefault) event.preventDefault();
					event.returnValue = false;
				}
				else wheelCount=scrollers[objName].wheelMax;
			}
		}
		catch(e){ scrollers[objName].setError(prepareException(e));}
	}
	//Обработка ошибок
	function prepareException(e)
	{
		filename=(e.fileName)?e.fileName.substring(7,e.fileName.length):'';
		return filename+': '+e.name+' at line '+e.lineNumber+': '+e.message;
	}
	this.printErrors=function()
	{
		if(this.errors.length!=0){for(i=0;i<this.errors.length;i++){eval(this.errorHandler+"('"+this.errors[i]+"')");}}
	}
	this.setError = function(eType)
	{
		switch(eType)
		{
			default:this.errors.push("Object: "+objName+". Error "+eType);break;
		}
		this.printErrors();
	}
	//Уничтожение объекта
	this.destruct=function()
	{
		try
		{
			if(this.scrollerButtonPositive)
			{
				this.scrollerButtonPositive.onmousedown="";
				this.scrollerButtonPositive.onmouseup="";
			}
			if(this.scrollerButtonNegative)
			{
				this.scrollerButtonNegative.onmousedown="";
				this.scrollerButtonNegative.onmouseup="";
			}
			if(this.scrollerThumb)
			{
				this.scrollerThumb.onclick="";
				this.scrollerThumb.onmouseout="";
				this.scrollerThumb.onmousemove="";
				this.scrollerThumb.onmouseup="";
				this.scrollerThumb.onmousedown="";
				document.body.onmouseup=function(event){bodyMouseUp()};
				document.body.onmousemove=function(event){bodyMouseMove()};
				window.onresize=function(event){windowResize()};
				if (this.scrollerThumb.parentNode.parentNode.addEventListener)
	 			{
	 				this.scrollerThumb.parentNode.parentNode.removeEventListener('DOMMouseScroll',scrollers[objName].wheel, false);
	 			}
	 			this.scrollerThumb.parentNode.parentNode.onmousewheel = "";
			}
			
			if(this.scrollWheel)
			{
				if (this.scrollObject.removeEventListener)
	 			{
	 				this.scrollObject.removeEventListener('DOMMouseScroll',scrollers[objName].wheel, false);
	 			}
	 			this.scrollObject.onmousewheel ="";
				}
				
			delete scrollers[objName];
		
		}
		catch(e){ alert(e);this.setError(prepareException(e));}
	}
}

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;
}

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;
}