﻿var _ulSupports, _galleryMaxScrollLeft, _galleryScrollDir, _galleryScrollTimer;

function InitializeScroll() {
	_ulSupports = document.getElementById('ulSupports');
	if(_ulSupports) {
		var liGallery = _ulSupports.getElementsByTagName('li');
		var galleryScrollWidth = 120 * liGallery.length * 2;
		
		_ulSupports.innerHTML += _ulSupports.innerHTML;
		
		_ulSupports.style.width = galleryScrollWidth + 'px';
		
		_galleryMaxScrollLeft = 0 - (galleryScrollWidth / 2) + 1;
		
		_galleryScrollDir = 'left';
		_ulSupports.style.left = '0px';
		
		liGallery = _ulSupports.getElementsByTagName('li');
		for(var i=0;i < liGallery.length; i++) {
			liGallery[i].onmouseover = StopGalleryScroll;
			liGallery[i].onmouseout = StartGalleryScroll;
		}
		
		StartGalleryScroll();
	}
}

function StartGalleryScroll() {
	if(_galleryScrollDir != 'right') {
		_ulSupports.style.left = ((parseInt(_ulSupports.style.left) <= _galleryMaxScrollLeft) ? '0' : (parseInt(_ulSupports.style.left) - 1)) + 'px';
	}
	else {
		_ulSupports.style.left = ((parseInt(_ulSupports.style.left) >= 0) ? _galleryMaxScrollLeft : (parseInt(_ulSupports.style.left) + 1)) + 'px';
	}
	
	if(!_galleryScrollTimer)
		_galleryScrollTimer = setInterval(function() { StartGalleryScroll(); }, 40);
}

function StopGalleryScroll(){
  clearInterval(_galleryScrollTimer);
}

function ChangeGalleryDirection(dir) {
	if(dir.toLowerCase() == 'left') {
		_galleryScrollDir = 'left';
	}
	else {
		_galleryScrollDir = 'right';
	}

	StopGalleryScroll();
	StartGalleryScroll();
}
