trans_bck=document.createElement('div');
trans_bck.className="fullbck";
var mailValidReg=new RegExp('^[A-Z0-9\\._%-]+@[A-Z0-9\\.-]+\.[A-Z]{2,4}$',"i");
//alert(mailValidReg);

function checkValue(type,inp,params)
{
	if(inp && inp.value!="")
	{
		switch(type)
		{
			case 'number':
			{
				var val	=	inp.value;
				val	=	parseInt(val.replace(/[^\-0-9]/gi,0));
				if(params)
				{
					if(params.min)
					{
						var minVal	=	parseInt(params.min);
						if(val<minVal)	val=minVal;
					}
					if(params.max)
					{
						var maxVal	=	parseInt(params.max);
						if(val>maxVal)	val=maxVal;
					}
				}
			}
		}
		inp.value=val;
	}
}

function	mousePagePos(ev)
{
	if(!ev) ev	=	window.event;
	var x,y;
	if(ev)
	{
		if(ev && (ev.pageX || ev.pageY))
		{
			x=ev.pageX;
			y=ev.pageY;
		}	
		else
		{
			x=ev.clientX+(document.documentElement.scrollLeft || document.body.scrollLeft);
			y=ev.clientY+(document.documentElement.scrollTop || document.body.scrollTop);
		}
	}
	return {'x':x,'y':y}

}

function sizeTo(objId,startW,startH,stopW,stopH,time,finishCall)
{
	obj=document.getElementById(objId);
	if(obj)
	{
		if(obj._sizing) clearTimeout(obj._sizing);
		
		if(!startW)			startW	=	obj.clientWidth;
		if(!startH)			startH	=	obj.clientHeight;
		if(!obj._width == undefined)		obj._width	=	startW;
		if(!obj._height == undefined)	obj._height	=	startH;
		
		var defW	=	stopW	-	startW;
		var defH	=	stopH	-	startH;
		
		//var def		=	(Math.abs(defW) > Math.abs(defH)) ? Math.abs(defW) : Math.abs(defH) ;
		
		if(time		==	undefined)	time	=	600;
		var mTOut	=	50;
		var stepW	=	defW/time*mTOut;
		var stepH	=	defH/time*mTOut;
		//var defR	=	
		var wR		=	stepW/Math.abs(stepW);
		var hR		=	stepH/Math.abs(stepH);
		var wCond	=	(wR*(obj._width+stepW)	<	wR*stopW);
		var hCond	=	(hR*(obj._height+stepH)	<	hR*stopH);
		if(wCond || hCond)
		{
			if(wCond)
			{
				obj._width		+=	stepW;
			}
			else
			{
				obj._width		=	stopW;
			}
			if(hCond)
			{
				obj._height		+=	stepH;
			}
			else
			{
				obj._height		=	stopH;
			}
			obj.style.width		=	obj._width+'px';
			obj.style.height	=	obj._height+'px';
			obj.parentNode.style.marginLeft	=	(obj._width+30)/-2 + 'px';
			obj.parentNode.style.marginTop	=	(obj._height+30)/-2 + 'px';
			obj._sizing	=	sizeTout("sizeTo('"+objId+"',"+startW+","+startH+","+stopW+","+stopH+","+time+",'"+finishCall+"')",mTOut);
		}
		else
		{
			obj.style.width		=	stopW	+	'px';
			obj.style.height	=	stopH	+	'px';
			if(finishCall)
			{
				eval(finishCall+"('"+objId+"')");
			}
		}
	}
}
function sizeTout(func,tout)
{
	return setTimeout(func,tout);
}

function fadeThis(objId,start,stop,time,finishCall)
{
	obj=document.getElementById(objId);
	if(obj)
	{
	if(obj._fading) clearTimeout(obj._fading);
	//if(andRemove && obj.__parentNode && !obj.parentNode) obj.__parentNode.appendChild(obj);
	//if(obj._fading)
	if(start	==	undefined) start	=	1;
	if(stop		==	undefined)	stop	=	0;
	if(time		==	undefined)	time	=	600;
	var mTOut=50;
	var step=(stop-start)/time*mTOut;
	if(!obj.style.opacity) obj.style.opacity=start;
	var op	=	parseFloat(obj.style.opacity);
	
	if(step/Math.abs(step)*(op+step)<stop)
	{
		op+=step;
		obj.style.opacity=op;
		obj.style.filter="alpha(opacity="+Math.floor(op*100)+")";
		//obj.style.width="100px";
		if(finishCall) finishCall="'"+finishCall+"'";
		obj._fading	=	fadeTout("fadeThis('"+objId+"',"+start+","+stop+","+time+","+finishCall+")",mTOut);
	}
	else
	{
		obj.style.opacity=stop;
		obj.style.filter=(stop==1)?"none":"alpha(opacity="+Math.floor(stop*100)+")";
		if(finishCall)
		{
			eval(finishCall+"('"+objId+"')");
		}
	}
	}
}
function fadeTout(func,tout)
{
	return setTimeout(func,tout);
}
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 prevImgSeq=new Array;
var prevImgSeqCurrent=0;
var prevImgSeqSrc=new Array;
function change_prev_pic(dest)
{
	if(!prevImgSeq || prevImgSeqCurrent==null || prevImgSeq.length<=1) return false;
	m=0;
	switch(dest)
	{
		case 'left': m=-1; break;
		case 'right': m=1; break;
	}
	//alert(m);
	var nextImg=new Array;
	var ind=prevImgSeqCurrent+m;
	if(ind>prevImgSeq.length-1) ind=0;
	if(ind<0) ind=prevImgSeq.length-1;
	prevImgSeqCurrent=ind;
	nextImg=prevImgSeq[ind];
	if(nextImg && nextImg[0] && nextImg[1] && nextImg[2])
	{
		show_prev_img(nextImg[0],'',nextImg[1],nextImg[2]);
	}
}
var maxAppearM=0;
var prevImgIsShown=false;

function inArray(val,arr)
{
	var rI = -1;
	for(var i in arr)
	{
		if(arr[i]	===	val)
		{
			rI	=	i;
			break;
		}
	}
	return rI;
}

function extend(Child, Parent) {
	var F = function() { }
	F.prototype = Parent.prototype
	Child.prototype = new F()
	Child.prototype.constructor = Child
	Child.superclass = Parent.prototype
}

function createElemnt(type,attrs)
{
	var elem	=	document.createElement(type);
	if(elem)
	{
		if(attrs)
		{
			for(var aName in attrs)
			{
				var	aVal	=	attrs[aName];
				
				switch(aName)
				{
					case 'class':
						elem.className	=	aVal;
						break;
					case 'src':
						elem.src	=	aVal;
						break;
					default:
						elem.setAttribute(aName,aVal);
						break;
				}
			}
		}
		return elem;
	}
	return false;
}

function insElem(elem,trg,mode,mark)
{
	if(!elem)
	{
		alert("NoELem!");
		return false;
	}
	if(!trg)
		trg	=	document.body;
	
	var dMode	=	"last";
	if(!mode) mode	=	dMode;
	mode	=	mode.toUpperCase();
	var modesT	=	['LAST','FIRST','AFTER','BEFORE'];
	if(inArray(mode,modesT) == -1) mode	=	dMode.toUpperCase();
	
	if(trg.childNodes.length==0) mode	=	"LAST";
	
	if(mode	==	"LAST")
	{
		trg.appendChild(elem);
	}
	else
	{
		if(!mark) mark	=	trg.lastChild();
		switch(mode)
		{
			case 'FIRST': mark	=	taget.firstChild();
			case 'AFTER': mark	=	mark.nextSibling();
		}
		if(!mark)	trg.appendChild(elem);
		else
		{
			trg.insertBefore(elem,mark);
		}
	}
}

var prevImgCont =	function()
{
	var	container;
	var	closebut;
	var	imgPlace;
	var cImg;
	var tImg;
	var	width;
	var	height;
	
	this.iniState	=	false;
	this.showState	=	false;
	
	this.init	=	function()
	{
		container	=	createElemnt('div',{'id':"_prevImgContainer",'class':"prevImgCont"});
		closebut	=	createElemnt('div',{'class':"close"});
			insElem(closebut,container);
		imgPlace	=	createElemnt('div',{'id':"_prevImgPlacer",'class':"imgPlace"});
			insElem(imgPlace,container);
		cImg			=	new Image();
		cImg.src		=	"/usr/image/common/empty.gif";
		cImg._extend	=	this;
		cImg.width		=	50;
		cImg.height		=	50;
			insElem(cImg,imgPlace);		
		tImg			=	new Image();
		tImg._extend	=	this;
		tImg.onload	=	function()
		{
			alert(this.width+'x'+this.height);
		}
		this.iniState	=	false;
	}
	
	this.setPicture	=	function(url)
	{
		tImg.src	=	url+"?recache="+Math.random();
	}
	
	this.show	=	function()
	{
		if(!this.showState)
		{
			insElem(container,document.body);
		}
	}
}
var _tmpPrevImgCont	= new prevImgCont();



function show_prev_img__(url,tx)
{
	var cont	=	_tmpPrevImgCont;
	if(!cont.iniState) cont.init();
	cont.show();
	cont.setPicture(url);
	i=0;
	//var cont	=	new prevImgCont(url);
	//cont.init();
}

function show_prev_img(url,tx,w,h)
{
	if(!w || !h || !url) return false;
	w=parseFloat(w);
	h=parseFloat(h);
	trans_bck.style.opacity="0.5";
	trans_bck.style.filter="alpha(opacity=50)";
	trans_bck.onclick=function()
	{
		hide_prev_img();
	}
	document.body.appendChild(trans_bck);
	
	prev_img.className=prev_img.className.replace(/\s?noSeq/gi,'');
	
	prev_img.onclick=function()
	{
		hide_prev_img();
	}
	
	if(!prevImgSeq || prevImgSeqCurrent==null || prevImgSeq.length<=1) prev_img.className+=" noSeq";
	
	fs_im=document.getElementById('full_size_image');
	var scl=0;
	var sclStep=100;
	var sclWset=false,sclHset=false;
	var sclMax=1500;
	nw=(w+sclStep<document.documentElement.clientWidth)?w:document.documentElement.clientWidth-sclStep
	nh=(h+sclStep<document.documentElement.clientHeight)?h:document.documentElement.clientHeight-sclStep;
	if(nw<w || nh<h)
	{
		if(nw>sclMax)
		{
			nw=sclMax-Math.round(sclStep/2);
			sclWset=true;
		}
		if(nh>sclMax)
		{
			nh=sclMax-Math.round(sclStep/2);
			sclHset=true;
		}
		if(!sclWset || !sclHset)
		{
			for(scl=0;scl<=sclMax-sclStep;scl+=sclStep)
			{
				if(!sclWset && nw>scl && nw<=scl+sclStep)
				{
					nw=scl+Math.round(sclStep/2);
					sclWset=true;
				}
				if(!sclHset && nh>scl && nh<=scl+sclStep)
				{
					nh=scl+Math.round(sclStep/2);
					sclHset=true;
				}
				if(sclWset && sclHset) break;
			}
		}
		
		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/wcustom/'+nsize+'/');
		//alert(url);
	}
	/*else
	{
		url=url.replace('/usr/image/','/usr/image/convert/woriginal/');
	}*/
	//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.style.visibility="hidden";
	//fs_im.parentNode.style.opacity="";
	//fs_im.parentNode.style.filter="alpha(opacity=65)";
	fs_tx=document.getElementById('prev_image_text');
	if(tx=='') fs_tx.style.visibility="hidden";
	fs_tx.innerHTML=tx;
	fs_tx.style.width=(w-8)+"px";
	prev_img.style.display="block";
	
	maxAppearM=Math.round((document.documentElement.clientHeight)/2);
	if(prev_img.currentStyle && prev_img.currentStyle.position=='absolute'){ maxAppearM = parseInt(prev_img.currentStyle.top);};
	def_top=(prevImgIsShown)?maxAppearM:-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='prevImgCont';
	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;
}
