
var baekoProgramm = {
	
	initTabbedNav : function()
	{
		$$('ul.csc-menu-1').each(function(nav,iter) {
			if (iter==0) {
				nav.addClass('tabbed-nav-top');
			} else if (iter==1) {
				nav.addClass('tabbed-nav-bottom');
			}
			
			// Add Events to list items
			nav.getElements('li').each(function(listitem,i) {

				listitem.addClass('listitem-'+i);
				// Set first item as active
				if (i==0 && iter==0) {
					baekoProgramm.setActive(listitem);
				}
				
				listitem.addEvent('click', function(e) {
					e.stop();
					baekoProgramm.setActive(listitem);
				});
			});
		});
	},
	
	setActive : function(listitem)
	{
		$('tabbed-inner-content').fade('out',{
			'duration' : 100
		});
		(function() {$('tabbed-content').addClass('load')}).delay(200);
		
		var position = listitem.get('class').substr(listitem.get('class').indexOf('listitem-')+9,1);
		$$('ul.csc-menu-1').each(function(n) {
			n.getElements('li').each(function(el,i) {
				if (i==position) {
					el.addClass('active');
				} else {
					el.removeClass('active');
				}
			});
		});

		new Request({
			'url' : listitem.getChildren('a').get('href'),
			'onSuccess' : function(result) {
				$('tabbed-inner-content').set('html',result);
				$('tabbed-content').removeClass('load');
				var height = $('tabbed-inner-content').getCoordinates().height;
				$('tabbed-inner-content').tween('height', height);
				$('tabbed-inner-content').fade('in',{
					'duration' : 100
				});
			}
		}).send();
	}
};

window.addEvent('domready',function() {
	baekoProgramm.initTabbedNav();
});