(function(){
	var params = [];
	var timer = 25;
	var step = 5;
	var defsumm = 0;
	var summ = defsumm;
	var percent = 60;
	var limit = 512;
	var listingTimer = 5;
	var scrolling = false;
	var listing = false;
	var generalBlock, scrollBlock, leftButton, rightButton, scrollWidth, blockWidth, leftSCroll, curPath, curStart, pointsCur;
	if (typeof window.onload == "function") var oldOnload = window.onload;
	window.onload = function () {
		if (typeof oldOnload == "function") oldOnload();
		initServices();
	};
	
	initServices = function() {
		generalBlock = document.getElementById("serviceBlock");
		if(generalBlock == null) return false;
		scrollingBlock = generalBlock.getElementsByTagName("div")[0];
		scrollBlock = generalBlock.getElementsByTagName("div")[0].firstChild;
		leftButton = generalBlock.getElementsByTagName("i")[0];
		rightButton = generalBlock.getElementsByTagName("b")[0];

		
		scrollWidth = scrollBlock.offsetWidth;
		blockWidth = scrollWidth/4;
		scrollingBlock.scrollLeft = currentSection*blockWidth;
		if(isMain == true) {
			pointsCur = document.getElementById("points").getElementsByTagName("b")[0];
			var pointsList = document.getElementById("points").getElementsByTagName("i");
			for(i=0;i<pointsList.length;i++) {
				pointsList[i].onclick = function(n){return function(){serviceScrollingPoint(n)}; return false;}(i);
			}
			if (window.addEventListener)
			generalBlock.addEventListener('DOMMouseScroll', wheel, false);
			generalBlock.onmousewheel = wheel;
			leftButton.onclick = function(){serviceScrolling(-1)};
			rightButton.onclick = function(){serviceScrolling(1)};
			leftButton.style.visibility = "visible";
			rightButton.style.visibility = "visible";
			listing = setInterval("serviceScrolling(1)", listingTimer*1000);
		}
	};
	
	wheel = function(event){
		var delta = 0;
		if (!event)
		event = window.event;
		if (event.wheelDelta) {
			delta = event.wheelDelta/120;
			/*if (window.opera)
			delta = -delta;*/
		} else if (event.detail) delta = -event.detail/3;
		if (delta)
		serviceScrolling(delta*-1)
		if (event.preventDefault)
		event.preventDefault();
		event.returnValue = false;
	};
 
	serviceScrollingPoint = function (position) {
		if(scrolling != false) return false;
		if(scrollingBlock.scrollLeft==scrollWidth*position) return false;
		var path = (scrollingBlock.scrollLeft<blockWidth*position) ? 1 : -1;
		leftSCroll = blockWidth*position;
		if(leftSCroll<0) return false;
		clearInterval(listing);
		curPath = path;
		curStart = scrollingBlock.scrollLeft;
		pointsCur.style.left = 5+(leftSCroll/blockWidth)*21+"px";
		scrolling = setInterval(serviceMoving, timer);
	};
	
	serviceScrolling = function(path) {
		if(scrolling != false) return false;
		var next = scrollingBlock.scrollLeft+blockWidth*path;
		//if(next<0) return false;
		clearInterval(listing);
		leftSCroll = (next>=scrollWidth) ? 0 : (next<0) ? scrollWidth-blockWidth : next;
		curPath = (next>=scrollWidth || next<0) ? path*-1 : path;
		curStart = scrollingBlock.scrollLeft;
		pointsCur.style.left = 5+(leftSCroll/blockWidth)*21+"px";
		scrolling = setInterval(serviceMoving, timer);
	};
	serviceMoving = function() {
		summ = ((leftSCroll-scrollingBlock.scrollLeft)*curPath  >  (leftSCroll-curStart)*(1-percent/100)*curPath) ? ((summ+step*curPath)*curPath<(limit*curPath)*curPath) ? summ+step*curPath : summ : ((summ-step*curPath)*curPath<2*curPath*curPath) ? summ : summ-step*curPath;
		var stop = ((scrollingBlock.scrollLeft+summ)*curPath>=leftSCroll*curPath) ? true : false;
		scrollingBlock.scrollLeft = (stop == true) ? leftSCroll : scrollingBlock.scrollLeft+summ;
		if(stop == true) {
			step = 2;
			summ = defsumm;
			clearInterval(scrolling);
			scrolling = false;
			listing = setInterval("serviceScrolling(1)", listingTimer*1000);
		}
		
		
	};
})();
