window.addEvent('domready', function() {
	if ($('sub-nav')) {
		var list = $ES('li','sub-nav');
		var elements = new Array();
		elements[0] = new Array();
		elements[1] = new Array();

		list.each(function(toggle) {
			if ($('slide-' + toggle.id)) {
				toggle.fx = new Fx.Slide('slide-' + toggle.id);
				elements[0].push(toggle.id);
				elements[1].push(toggle);

				toggle.addEvent('mouseenter', function(e) {
					for (i = 0; i < elements[0].length; i++) {
						if (elements[0][i] != this.id) {
							elements[1][i].fx.slideOut();
						}
					}

					this.fx.slideIn();
				});

				// Collapse unused menus
				var menuLinks = toggle.getElements('a');
				// Default is to hide all menus
				var collapse = true;

				menuLinks.each(function(el) {
					// If a link in the menu matches the window location, do not collapse it
					if (window.location.href.match(el.getProperty('href'))) {
						collapse = false;
					}
				});

				// Collapse only when needed to
				if (collapse) {
					toggle.fx.hide();
				}
			}
		});
	}

	if ($('region-tabs')) {
		regionTabs = new mootabs('region-tabs', {
			width:'490px',
			height:'280px',
			changeTransition:'none'
		});
	}

	if ($('vertical-ticker')) {
		var vertical = new Ticker('vertical-ticker',{
			speed:1000,
			delay:2000,
			direction:'vertical'
		});
	}

	if ($('horizontal-ticker')) {
		var horizontal = new Ticker('horizontal-ticker',{
			speed:500,
			delay:1500,
			direction:'horizontal'
		});
	}
	
	$('header2').getElements('li').each(function(el) {
		if (el.getElements('a.active').length > 0) {
			el.addClass('active');
		}	
	});

	/*
	if ($('.scroll-horizontal')) {
		var hTimers = new Array();
		$('.scroll-horizontal').each(function(i) {
			timers[i]
		});
	}*/

	/*/ Horizontal scroller
	$$('.scroll-horizontal').each(function(el) {
		var width = el.getSize().size.x;
		el.setStyle('position', 'relative');
		var e = el;
		var hOffset = 0;
		var hAnimate = true;

		var hScroll = function() {
			// Reset position
			if (hOffset <= (width * -1) * 2) {
				hOffset = 0;
			}
			// Animate
			if (hAnimate) {
				e.setStyle('left', --hOffset + 'px');
			}
		}
		// Begin and loop
		hScroll.periodical(10);

		// Stop on hover
		el.addEvent('mouseover', function() {
			hAnimate = false;
		});
		el.addEvent('mouseout', function() {
			hAnimate = true;
		});
	});
	// Vertical scroller
	$$('.scroll-vertical').each(function(el) {
		var height = el.getSize().size.y;
		el.setStyle('position', 'relative');
		var e = el;
		var vOffset = 0;
		var vAnimate = true;

		var vScroll = function() {
			// Reset position
			if (vOffset <= (height * -1) * 2) {
				vOffset = 0;
			}
			// Animate
			if (vAnimate) {
				e.setStyle('top', --vOffset + 'px');
			}
		}
		// Begin and loop
		vScroll.periodical(10);

		// Stop on hover
		el.addEvent('mouseover', function() {
			vAnimate = false;
		});
		el.addEvent('mouseout', function() {
			vAnimate = true;
		});
	});*/
});