Ape.tabs = function(){
	
	var that = this;
	
	this.start = function(){
		
		aktivateTabs();
	};
	
	function aktivateTabs(){
		
		$('div.tabs_teaser .tabbutton, div.tabs_box .tabbutton, div.tabs .tabbutton').each(function(){
			
			$(this).unbind('click.tabbutton').bind('click.tabbutton', function(){
				
				var bezeichner = $(this).attr('id').split('__').pop();
				
				var key = bezeichner.split('_').shift();
				var item = bezeichner.split('_').pop();
				
				
				//Alle Tabs auf inaktiv setzen
				$('.tab__'+key).removeClass('aktiv').each(function(){
					
					var title_a = $(this).children('a').html();
					var title_span = $(this).children('span').html();
					
					$(this).children('span').remove();
					$(this).children('a').remove();
					
					if(title_a !== null){
						var title = title_a;
					}else{
						var title = title_span;
					}
					
					$(this).append('<a href="javascript:;">'+title+'</a>');
				});
				
				//den angeklickten tab als aktiv markieren
				$(this).addClass('aktiv');
				var title = $(this).children('a').html();
				$(this).children('a').remove();
				$(this).append('<span>'+title+'</span>');
				
				//alle tabcontent blöcke ausblenden
				$('.tabcontent__'+key).hide();
				//den passenden content zum tab anzeigen
				$('#tabcontent__'+bezeichner).show();
				
				
				//alle tabextra blöcke ausblenden
				$('.tabextra__'+key).hide();
				//den passenden extracontent zum tab anzeigen
				$('#tabextra__'+bezeichner).show();
				
				if($(this).parent().children('.ivw').length > 0){
					var alternativeAgofCode = $(this).parent().children('.ivw').html();
					content_click(alternativeAgofCode, prod, wm_page_name, wm_group_name);
				}else{
					if(typeof globalAgofCode != 'undefined'){
						content_click(globalAgofCode, prod, wm_page_name, wm_group_name);
					}
				}
				
				
				//console.debug('tab '+bezeichner);
			});
			
		});
		
		//console.debug('neue tabfunktion geladen');
	}
};

$(document).ready(function(){
	var globaltabs = new Ape.tabs();
	globaltabs.start();
});