// JavaScript Document
function getBodyScrollTop(){return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);};
function vslide(idParent,title){
	var d1=todo.create('div',null,null,{position:'absolute',top:'30px',left:'140px',padding:'0 0 0 9px',width:'195px',background:'url(images/bg_slider.gif) no-repeat 0 0',fontSize:'9px',fontFamily:'Arial, Helvetica, sans-serif'}),
		d2=d1.appendChild(todo.create('div',null,null,{background:'url(images/bg_slider.gif) no-repeat 100% 0',padding:'9px 0 0 0'})),
		d3=d2.appendChild(todo.create('div',null,null,{background:'url(images/bg_slider.gif) no-repeat 100% 100%'})),
		d4=d3.appendChild(todo.create('div',null,null,{background:'url(images/bg_slider.gif) no-repeat 0 100%',padding:'0 0 10px 10px',position:'relative',left:'-9px'})),
		h3=d4.appendChild(todo.create('h3',null,null,{padding:'5px 0 10px 0',margin:'0',color:'#375555',fontSize:'11px',fontWeight:'bold',fontFamily:'Arial, Helvetica, sans-serif'}))
		ul=d4.appendChild(todo.create('ul',null,null,{listStyle:'none',padding:'0',margin:'0'}));
		div=d4.appendChild(todo.create('div',null,'Убрать "быстрый переход"',{background:'url(images/ico_slider_stop.gif) no-repeat 100% 100%',cursor:'pointer',color:'#38534e',fontSize:'11px',fontWeight:'bold',padding:'5px 15px 0 0'}));
	h3.innerHTML='Быстрый переход<br/>по каталогу "'+title+'"';
	div.onclick=function(){
		if(document._vs._isOn()){
			document._vs._stop();
			this.style.background='url(images/ico_slider_start.gif) no-repeat 100% 100%';
			this.innerHTML='Запустить "быстрый переход"';
		}else{
			document._vs._start();
			this.style.background='url(images/ico_slider_stop.gif) no-repeat 100% 100%';
			this.innerHTML='Убрать "быстрый переход"';
		}
	};
	this.e=todo.get(idParent).appendChild(d1);
	this.e._buttonStop=div;
	this.e._list=ul;
	this.e._addItem=function(_anchor,_text){
		var li=this._list.appendChild(todo.create('li',null,null,{padding:'0',margin:'0'})),
			href=location.href,
			pos=href.indexOf('#');
		if(-1!=pos)href=href.substr(0,pos);
		var a=li.appendChild(todo.create('a',{href:href+'#'+_anchor},_text,{textDecoration:'none',color:(location.hash=='#'+_anchor ? '#c7621e' : '#31302b')}));
		a.onclick=function(){
			var a=this.parentNode.parentNode.getElementsByTagName('a');
			for(var i=0,l=a.length;i<l;i++)a[i].style.color='#31302b';
			this.style.color='#c7621e';
		}
	};
	this.e._addItem2=function(_href,_text){
		if(!this._list2)this._list2=this._buttonStop.parentNode.insertBefore(todo.create('ul',null,null,{listStyle:'none',padding:'10px 0 0 0',margin:'0'}),this._buttonStop);
		var li=this._list2.appendChild(todo.create('li',null,null,{padding:'0',margin:'0'}));
		li.appendChild(todo.create('a',{href:_href},_text,{textDecoration:'none',color:'#d24e00',fontSize:'11px'}));
	};
	this.e._step=5;
	this.e._interval=20;
	this.e._y=parseInt(this.e.style.top);
	this.e._startPos = this.e._y;
	this.e._slide=function(){
		var top=parseInt(this.style.top),
			pos=this._y+getBodyScrollTop(),
			repeat=false,
			tmp=(this._startPos-pos)-(this._startPos-top);
		if(tmp<0)tmp*=-1;
		
		if(top>pos){
			top=top-Math.ceil(tmp/this._step);
			if(top<pos)this._startPos=top;
			else repeat=true;
			this.style.top=top+'px';
		}else if(top<pos){
			top=top+Math.ceil(tmp/this._step);
			if(top>pos)this._startPos=top;
			else repeat=true;
			this.style.top=top+'px';
		};
		
		if(repeat && !this._timerId){
			this._timerId=window.setInterval(function(e){return function(){e._slide()}}(this),this._interval);
			this._startPos=top;
		}else if(!repeat && this._timerId){
			window.clearInterval(this._timerId);
			this._timerId=null;
		}
	};
	this.e._suspendedSlide=function(f){
		if(f && !this._suspendTimerId){
			this._suspendTimerId=window.setInterval(function(e){return function(){e._suspendedSlide(false)}}(this),300);
		}else if(!f && this._suspendTimerId){
			window.clearInterval(this._suspendTimerId);
			this._suspendTimerId=null;
			this._slide();
		}
	};
	this.e._stop=function(){
		window.onscroll=null;
		this.style.top=(this._y-200)+'px';
		this._state=false;
	};
	this.e._start=function(){
		if(!document._vs)document._vs=this;
		window.onscroll=function(){document._vs._suspendedSlide(true);}
		this._state=true;
	};
	this.e._isOn=function(){return this._state;};
	this.e._start();
};
