window.addEvent('domready', function() {

	changeClass.periodical(8000);

	function changeClass () {
		$$('ul#links li a.current-slide').each(function(e) {
			var el = e.getParent();
			var current = getRotatorID(el.id);
			if (current == 4) {
				var next = 1;
			} else if (current == 3) {
				var next = 4;
			} else if (current == 2) {
				var next = 3;
			} else if (current == 1) {
				var next = 2;
			} else {
				var next = 1;
			}
			nextlink = $$('ul#links li#link-'+next+' a');
			resetRotatorClass();
			nextlink.addClass('current-slide');
			$('image-'+next).style.display = '';
		});
	}

	$$('ul#links li a').each(function(a) {
		a.addEvent('click', function(e) {
			new Event(e).stop();
			resetRotatorClass();
			a.addClass('current-slide');
			var p = a.getParent();
			var id = getRotatorID(p.id);
			$('image-'+id).style.display = '';
		});
	});


});

function getID ( o )
{
	return o.replace ( /link\_/i, '');	

}

function resetRotatorClass ()
{
	$$('ul#links li a').each(function(a) {
		a.removeClass('current-slide');
		var p = a.getParent();
		$('image-' + getRotatorID(p.id)).style.display = 'none';
	});
}

function getRotatorID ( o )
{
	return o.replace ( /link\-/i, '');
}
