

var bSS2 = false;
var iScrollTimeout2 = 1;
var iTimeOut2 = window.addEventListener ? iScrollTimeout2 * 2 : iScrollTimeout2;
var iScrollKoef2 = 8;
var iCW2, iTW2, iTL2, iTR2, iDiff2;
var oContainer2 = null;
var oThumbs2 = null;
var oLeftArr2 = null;
var oRightArr2 = null;


function initScrollVars2(){
	iCW2 = oContainer2.offsetWidth;
	iTW2 = oThumbs2.offsetWidth;
	iTL2 = oThumbs2.offsetLeft;
	iDiff2 = iTW2 - iCW2;
	iTR2 = -(iTL2 + iDiff2);
}

function scrollInit2(){
	if(oContainer2 = document.getElementById('gn_container2')){
	if(oThumbs2 = document.getElementById('gn_thumbs2')){
	if(oLeftArr2 = document.getElementById('gn_arr_left2')){
	if(oRightArr2 = document.getElementById('gn_arr_right2')){
		if(oContainer2.attachEvent){
			oContainer2.attachEvent("onmousewheel", mousescrollThumbs2);
		} else {
			oContainer2.addEventListener("DOMMouseScroll", mousescrollThumbs2, true);
		}
		if(window.addEventListener){
			window.addEventListener('resize', resizeThumbs2, false);
		} else {
			window.attachEvent('onresize', resizeThumbs2);
		}
		checkScrollButtons2();
		//checkSelectedPosition2();
		resizeThumbs2();
	}
	}
	}
	}
}

function checkSelectedPosition2(){
	if(oThumbs2){
		var i = 0;
		var num = 0;
		oSelThumb = null;
		for (i = 0; i < a.length; i++) {
			if(oThumb = document.getElementById('th' + a[i])) {
				if(oThumb.className == 'sel'){
					oSelThumb = oThumb;
					num = i;
				}
			}
		}
		iLeft2 = Math.round(iCW2 / 2 - (iTW2 / a.length) * (num + 1/2));
		iLeft2 = iLeft2 + iTW2 < iCW2 ? iCW2 - iTW2 : iLeft2;
		iLeft2 = iLeft2 > 0 ? 0 : iLeft2;
		oThumbs2.style.left = iLeft2 + 'px';
	}
}

function checkScrollButtons2(){
	initScrollVars2();
	if(iDiff2 > 0){
		bRA2 = iTR2 < 0 ? true : false;
		bLA2 = iTL2 < 0 ? true : false;
	} else {
		bLA2 = false; bRA2 = false;
	}

	oLeftArr2.style.visibility = bLA2 ? '' : 'hidden';
	oRightArr2.style.visibility = bRA2 ? '' : 'hidden';
}

function resizeThumbs2(){
	if(oThumbs2){
		initScrollVars2();
		if(iTL2 < 0){
			if(iDiff2 < 0) {
				oThumbs2.style.left = '0px';
			} else if(iDiff2 > 0) {
				if(iTR2 >= 0){
					oThumbs2.style.left = -iDiff2 + 'px';
				}
			}
		} else {
			oThumbs2.style.left = '0px';
		}
		checkScrollButtons2();
	}
}

function scrollThumbs2(sSS, sDirection){
	bSS2 = sSS == 'start' ? true : false;
	iDirection2 = sDirection == 'left' ? -1 : 1;
	_scroll2(iDirection2);
}

function mousescrollThumbs2(evt){
	if(!evt) evt = window.event;
	if(evt.wheelDelta) {
		delta = evt.wheelDelta / 120;
		if(window.opera) delta = -delta;
	} else if (evt.detail) {
		delta = -evt.detail / 3;
	}
	iDirection2 = delta > 0 ? -1 : 1;
	_scroll2(iDirection2, delta * 5);
	if (evt.preventDefault) evt.preventDefault();
	evt.returnValue = false;
	return false;
}

function _scroll2(iDirection2, iKoef2){
	var iMultiplier2 = !isNaN(iKoef2) ? Math.abs(iKoef2) : 1;
	var iShift2 = iScrollKoef2 * iMultiplier2 * iDirection2;

	initScrollVars2();
	if(oThumbs2 && iCW2 > 0){
		if(iDiff2 > 0) {
			if(iTL2 > iShift2) {
				oThumbs2.style.left = '0px';
			} else { 
				if((iDiff2 + iTL2) < iShift2) {
					oThumbs2.style.left = -iDiff2 + 'px';	
				} else {
					oThumbs2.style.left = (iTL2 - iShift2) + 'px';
					if(bSS2){
						setTimeout('_scroll2(' + iDirection2 + ')', iTimeOut2);
					}
				}
			}
		}
	}
	checkScrollButtons2();
}
