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 = '';
			$('desc-'+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 = '';
			$('desc-'+id).style.display = '';
		});
	});
	
	$$('ul#categories li a').each(function(a) {
		a.addEvent('click', function(e) {
			new Event(e).stop();
			resetClass();
			var p = a.getParent();
			p.addClass('current');
			var id = getID(p.id);
			$('content_'+id).style.display = '';	
		});
	});
	
});

function resetClass ()
{
	$$('ul#categories li').each(function(a) {
		a.removeClass('current');
		$('content_'+getID ( a.id )).style.display = 'none';		
	});
}

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';
		$('desc-' +	getRotatorID(p.id)).style.display = 'none';
	});
}

function getRotatorID ( o )
{
	return o.replace ( /link\-/i, '');
}