var ITCD = window.ITCD || {};

// a few global vars...
var x;
var tabBarWidth = 570;

ITCD.scrollTabs = function(direction) {
	x = 0;
	if(direction == 'back') {
		ITCD.scrollBack();
	} else if (direction == 'fullback') {
		ITCD.scrollFullBack();
	} else {
		ITCD.scrollForward()
	}
}
ITCD.scrollBack = function () {
	x++;
	if(x>=6) {
		ITCD.updateButtonStates();
	 	return false;
	}
	$('speakers-slide').scrollLeft = $('speakers-slide').scrollLeft-115;
	//585
	setTimeout('ITCD.scrollBack()', 1);
	ITCD.updateButtonStates();
}
ITCD.scrollFullBack = function () {
	$('speakers-slide').scrollLeft = 0;
	ITCD.updateButtonStates();
}
ITCD.scrollForward = function () {
	x++;
	if(x>=6) {
		ITCD.updateButtonStates();
		return false;
	} 
	$('speakers-slide').scrollLeft = $('speakers-slide').scrollLeft+115;
	//585
	setTimeout('ITCD.scrollForward()', 1);
}

ITCD.updateButtonStates = function () {
	//console.log(tabBarWidth);
	//console.log($('roleTabs').scrollLeft);
	if($('speakers-slide').scrollLeft <= 0) {
		$('left-arrow').hide();
	} else {
		$('left-arrow').show();
	}
	
	if($('speakers-slide').scrollLeft+$('speakers-slide').getWidth() >= tabBarWidth) {
		$('right-arrow').hide();
	} else {
		$('right-arrow').show();
	}
}

ITCD.initTabScroll = function() {
	tabBarWidth = 0;
	$$('#speakers-slide li').each(function (elm) {
		tabBarWidth += $(elm).getWidth()+5;
	});
	
	if(tabBarWidth > $('speakers-slide').getWidth()) {
		$('right-arrow').show();
		$('left-arrow').show();
		ITCD.updateButtonStates()

	}
	//console.log(tabBarWidth);
}


Event.observe(window, 'load', function() {
	if($('speakers-slide')) {
		ITCD.initTabScroll();
	}
});
