	var rightregion = false, leftregion = false, menuflag = false, ulflag = false, notstop = false;
	var WidthMonitor, dx = 0, pagenext, pagenextWidth, offset, ul, ulWidth, countright, countleft, timeright, timeleft, menuWidth, menu, lastLi, ulPadding = 15;
	
	

	function dx_pagenext()
	{
		dx = (ulWidth - (ulWidth + (ul.offset().left - (menu.offset().left + menuWidth)))) - menuWidth;
		pagenext = dx + pagenextWidth;
	}
	
	$(function(){
		// для ширины слайдера
		WidthMonitor = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
		var WS = (WidthMonitor - 62) * 0.95;
			WS = Math.round(WS);
		var WD = (WS * 0.95);
			WD = Math.round(WD);
		document.getElementById('scroling').style.width = WS+'px';
		document.getElementById('div').style.width = WD+'px';
		//------------------------------------------------------------------
		
		
		menu = $('div.sc_menu');
		var scroling = $('body');
		var pos;
		menuWidth = menu.width();

		ul = $('ul.sc_menu');
	
		lastLi = ul.find('li:last-child');
		var buttons_count = Math.round(menuWidth/lastLi.outerWidth());
		pagenextWidth = lastLi.outerWidth()*buttons_count;
		pagenext = pagenextWidth;
		
		
		//количество кнопок
		var col = Math.floor(WD/lastLi.outerWidth());
		setCookie('button_count_screen',col,7000 * 86400,'/');
		//-------------------------------------
		
		
		ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth();
		offset = ulWidth-menuWidth;	
		menu.css({overflow: 'hidden'});
	
		menu.mouseover(function(e){
			menuflag = true;  
			
			pos = e.pageX-menu.offset().left;
			dx_pagenext();
				
					if (pos >= (menuWidth - 100) && pos <= menuWidth)
					{
							if (rightregion == false)
							{
								rightregion = true;
								menu.stop().scrollTo({left: offset}, timeright, {axis:'x'}); notstop = false;
								//pagenext = dx + pagenextWidth;
							}
					}
					else if (pos > 100 && pos < (menuWidth - 100))
					{
						
							rightregion = false;
							leftregion = false;
							menu.stop();
					}
					else if (pos >= 0 && pos <= 100) 
					{
						if (leftregion == false)
						{
							leftregion = true;
							menu.stop().scrollTo({left: 0}, timeleft, {axis:'x'}); notstop = false;
						}
					}
		});
		
		menu.mouseout(function(){
			
			menuflag = false;
		});
		
		ul.mouseover(function(e){
			ulflag = true;
			//dx = (ulWidth - (ulWidth + (ul.offset().left - (menu.offset().left + menuWidth)))) - menuWidth;
			dx_pagenext();
			countright = (ulWidth + (ul.offset().left - (menu.offset().left + menuWidth))) / lastLi.outerWidth();
			//countleft = (ulWidth + (ul.offset().left - menu.offset().left + menuWidth + menuWidth)) / lastLi.outerWidth();
			countleft = (0-(ul.offset().left-menu.offset().left)) / lastLi.outerWidth();
			timeright = countright*1500;
			timeleft = countleft*1500;
			//myText.innerText = "DX = " + dx + "     pagenext = " + pagenext;
			//alert(menu.offset().left);
		});
		
		ul.mouseout(function(){
			
			ulflag = false;
		});
		
		scroling.mouseover(function(){ 
			if (menuflag == false && ulflag == false)
			{
				if (notstop != true) menu.stop();
				
				rightregion = false;
				leftregion = false; 
			}
		});
		
		menu.mousemove(function(e){
			pos = e.pageX-menu.offset().left;
			if (pos > 100 && pos < (menuWidth - 100))
					{
						
							rightregion = false;
							leftregion = false;
							menu.stop();
					}
			dx_pagenext();
		});
		
		ul.mousemove(function(e){
			dx_pagenext();
		});
	});
	
	function next()
	{
		dx_pagenext();
		notstop = true;
		if ((ulWidth - pagenext) > pagenextWidth)
		{	
			var  sc = (pagenext/lastLi.outerWidth());
			     //sc = Math.floor(sc)*lastLi.outerWidth();
			     sc = Math.round(sc)*lastLi.outerWidth();
				//var sc1 = pagenext;
			//menu.stop().scrollTo({left: pagenext}, 100, {axis:'x'});
			menu.stop().scrollTo({left: sc}, 1000, {axis:'x'});
			pagenext += pagenextWidth; 
		}
		else
		{
			menu.stop().scrollTo({left: offset}, 1000, {axis:'x'}); 
		}
		//notstop = false;
		
		//myText.innerText = "DX = " + dx + "     pagenext = " + pagenext;
		
		//myText1.innerText = "pagenext = " + sc1 + "     pagenext1 = " + sc;		
	}
	

	function prev()
	{
		dx_pagenext();
		notstop = true;
		if (pagenext > 2*pagenextWidth)
		{	
			pagenext -= (2*pagenextWidth);
			var  sc = (pagenext/lastLi.outerWidth());
			     //sc = Math.floor(sc)*lastLi.outerWidth();
			     sc = Math.round(sc)*lastLi.outerWidth();
				var sc1 = pagenext;
			//menu.stop().scrollTo({left: pagenext}, 100, {axis:'x'});
			menu.stop().scrollTo({left: sc}, 1000, {axis:'x'});
		}
		else
		{
			menu.stop().scrollTo({left: 0}, 1000, {axis:'x'});
		}
		
		//myText.innerText = "DX = " + dx + "     pagenext = " + pagenext;
		
		//myText1.innerText = "pagenext = " + sc1 + "     pagenext1 = " + sc;
	}
	
	
	function start()
	{
		notstop = true;
		menu.stop().scrollTo({left: 0}, 500, {axis:'x'});		
	}
	
	function finish()
	{
		notstop = true;
		var fin = offset;
		menu.stop().scrollTo({left: fin}, 500, {axis:'x'});		
	}
