

var bSS1 = false;
var iScrollTimeout1 = 1;
var iTimeOut1 = window.addEventListener ? iScrollTimeout1 * 2 : iScrollTimeout1;
var iScrollKoef1 = 8;
var iCW1, iTW1, iTL1, iTR1, iDiff1;
var oContainer1 = null;
var oThumbs1 = null;
var oLeftArr1 = null;
var oRightArr1 = null;


function initScrollVars1(){
	iCW1 = oContainer1.offsetWidth;
	iTW1 = oThumbs1.offsetWidth;
	iTL1 = oThumbs1.offsetLeft;
	iDiff1 = iTW1 - iCW1;
	iTR1 = -(iTL1 + iDiff1);
}

function scrollInit1(){
	if(oContainer1 = document.getElementById('gn_container1')){
	if(oThumbs1 = document.getElementById('gn_thumbs1')){
	if(oLeftArr1 = document.getElementById('gn_arr_left1')){
	if(oRightArr1 = document.getElementById('gn_arr_right1')){
		if(oContainer1.attachEvent){
			oContainer1.attachEvent("onmousewheel", mouseScrollThumbs1);
		} else {
			oContainer1.addEventListener("DOMMouseScroll", mouseScrollThumbs1, true);
		}
		if(window.addEventListener){
			window.addEventListener('resize', resizeThumbs1, false);
		} else {
			window.attachEvent('onresize', resizeThumbs1);
		}
		checkScrollButtons1();
		//checkSelectedPosition1();
		resizeThumbs1();
	}
	}
	}
	}
}

function checkSelectedPosition1(){
	if(oThumbs1){
		var i = 0;
		var num = 0;
		oSelThumb1 = null;
		for (i = 0; i < a.length; i++) {
			if(oThumb = document.getElementById('th' + a[i])) {
				if(oThumb.className == 'sel'){
					oSelThumb1 = oThumb;
					num = i;
				}
			}
		}
		iLeft1 = Math.round(iCW1 / 2 - (iTW1 / a.length) * (num + 1/2));
		iLeft1 = iLeft1 + iTW1 < iCW1 ? iCW1 - iTW1 : iLeft1;
		iLeft1 = iLeft1 > 0 ? 0 : iLeft1;
		oThumbs1.style.left = iLeft1 + 'px';
	}
}

function checkScrollButtons1(){
	initScrollVars1();
	if(iDiff1 > 0){
		bRA1 = iTR1 < 0 ? true : false;
		bLA1 = iTL1 < 0 ? true : false;
	} else {
		bLA1 = false; bRA1 = false;
	}

	oLeftArr1.style.visibility = bLA1 ? '' : 'hidden';
	oRightArr1.style.visibility = bRA1 ? '' : 'hidden';
}

function resizeThumbs1(){
	if(oThumbs1){
		initScrollVars1();
		if(iTL1 < 0){
			if(iDiff1 < 0) {
				oThumbs1.style.left = '0px';
			} else if(iDiff1 > 0) {
				if(iTR1 >= 0){
					oThumbs1.style.left = -iDiff1 + 'px';
				}
			}
		} else {
			oThumbs1.style.left = '0px';
		}
		checkScrollButtons1();
	}
}

function scrollThumbs1(sSS, sDirection){
	bSS1 = sSS == 'start' ? true : false;
	iDirection1 = sDirection == 'left' ? -1 : 1;
	_scroll1(iDirection1);
}

function mouseScrollThumbs1(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;
	}
	iDirection1 = delta > 0 ? -1 : 1;
	_scroll1(iDirection1, delta * 5);
	if (evt.preventDefault) evt.preventDefault();
	evt.returnValue = false;
	return false;
}

function _scroll1(iDirection1, iKoef1){
	var iMultiplier1 = !isNaN(iKoef1) ? Math.abs(iKoef1) : 1;
	var iShift1 = iScrollKoef1 * iMultiplier1 * iDirection1;

	initScrollVars1();
	if(oThumbs1 && iCW1 > 0){
		if(iDiff1 > 0) {
			if(iTL1 > iShift1) {
				oThumbs1.style.left = '0px';
			} else { 
				if((iDiff1 + iTL1) < iShift1) {
					oThumbs1.style.left = -iDiff1 + 'px';	
				} else {
					oThumbs1.style.left = (iTL1 - iShift1) + 'px';
					if(bSS1){
						setTimeout('_scroll1(' + iDirection1 + ')', iTimeOut1);
					}
				}
			}
		}
	}
	checkScrollButtons1();
}
