window.addEvent('domready', function() {
	if (!$('scroller')) return;
	var leftOffsets = [];
	var scrollLeft = 0;
	var outerHeight = 0;
	$$('.scroller_content').each(function(scrollerContent) {
		var c = scrollerContent.getCoordinates();
		scrollerContent.setStyles({
			position : 'absolute',
			left : scrollLeft + 'px'
		});
		outerHeight = Math.max(outerHeight, c.height);
		leftOffsets.push(scrollLeft);
		scrollLeft += c.width;
	});
	$('scroller_content_outer').setStyle('height', outerHeight + 'px');

	$$('#scroller_tabs li').each(function(scrollerTabButton) {
		scrollerTabButton.setStyle('cursor', 'pointer');
		scrollerTabButton.addEvent('click', function() {
			var tabIndex = 0;
			$$('#scroller_tabs li').each(function(otherScrollerTabButton) {
				if (otherScrollerTabButton == scrollerTabButton) {
					otherScrollerTabButton.addClass('selected');
					new Fx.Scroll($('scroller_content_outer'), {
						link : 'cancel'
					}).start(leftOffsets[tabIndex], 0);
				} else {
					otherScrollerTabButton.removeClass('selected');
				}
				++tabIndex;
			});
		});
	});
	
	if (Browser.Engine.trident) {
		var ieVersion = parseFloat(/MSIE ([0-9\.]+)/.exec(navigator.appVersion)[1]);
		if (ieVersion < 8) {
			window.addEvent('resize', function() {
				// Force IE to recalculate the layout by playing with the "position" style.
				$('scroller_content_outer').setStyle('position', 'absolute');
				$('scroller_content_outer').setStyle('position', 'relative');
			});
		}
	}
	
	document.getElement('#scroller_tabs li:first-child').fireEvent('click');

});
