$(document).ready( function() {
	/*===========================
	*	
	* Date Created: 21/01/2010
	* Last Update: 21/01/2010
	* Description: Submenu
	*
	*===========================*/	
	
	objPrevious = null;

	$("ul.mainnavi li").hover( function() {
		$('.submenu',this).show();
		//$('a', this).addClass('active');
	}, function() {
		$('.submenu',this).hide();
		//$('a', this).removeClass('active');
	});

	$('a.level2-href').hover( function() {
		if (objPrevious != null) $('ul.level3',objPrevious.parent()).hide();
		$('ul.level3', $(this).parent()).show();

		$(objPrevious).removeClass('active');

		objPrevious = $(this);

		$(this).addClass('active');
	}, function() {});

	objPrevious1 = null;
	$('a.level3-href').hover( function() {
		if (objPrevious1 != null) $('ul.level4',objPrevious1.parent()).hide();
		$('ul.level4', $(this).parent()).show();

		$(objPrevious1).removeClass('active');

		objPrevious1 = $(this);

		$(this).addClass('active');
	}, function() {});
	
	objPrevious2 = null;
	$('a.level4-href').hover( function() {
		if (objPrevious2 != null) $(objPrevious2).removeClass('active');
		objPrevious2 = $(this);

		$(this).addClass('active');
	}, function() {});

	/**
	 * Following lines are for fullsize sliderboxes defined by backend user.
	 */
	slideCount = $('div.slideshow-inner', $('div.subheader')).length;
	slideShowTabDiv = '<div class="slideshow-tabs">';
	for (i=0; i<slideCount; i++) {
		slideShowTabDiv += '<a href="#"></a>';
	}
	slideShowTabDiv += '</div>';
	$('.subheader-inner', $('div.subheader')).append(slideShowTabDiv);
	/** end **/

	/**
	 * Build menue vor tabbed content.
	 */
	tabNumbers = 1;
	$('.panels .tab-content').each(function() {
		tabName = $('span.tab-name', $(this)).html();
		$('span.tab-name', $(this)).remove();
		
		tab = '<li><a title='+tabName+' href="#'+tabNumbers+'"><span>'+tabName+'</span></a></li>';
		
		$('.tab-navi ul').append(tab);
		tabNumbers++;
	});
	/** end **/
	
	if ( $.browser.msie ) {
		$(".slideshow-tabs").tabs(".slideshow-inner", { 		
			effect: 'default',		
			fadeOutSpeed: 500,
			fadeInSpeed: 500,		
			rotate: true 			
			}).slideshow({
				autoplay: true,
				interval: 8000
		});
	} else {
		$(".slideshow-tabs").tabs(".slideshow-inner", {
			effect: "fade",		
			fadeOutSpeed: 2000,
			fadeInSpeed: 3000,		
			rotate: true
		}).slideshow({
			autoplay: true,
			interval: 8000
		});
	}

	if ($.browser.msie) {  
		$(".tab-navi ul").tabs(".panels .tab-content", {
			effect: 'default',
			fadeOutSpeed: 200,
			fadeInSpeed: 500
		});
	} else {
		$(".tab-navi ul").tabs(".panels .tab-content", {
			effect: 'fade',
			fadeOutSpeed: 200,
			fadeInSpeed: 1000
		});
	}

	if ($.browser.msie) {
		$("a.button-register").tabs(".panel-schulung .tab-content-schulung", {
			effect: 'default',
			fadeOutSpeed: 200,
			fadeInSpeed: 500
		});

		$(".tab-schulung ul").tabs(".panel-schulung .tab-content-schulung", {
			effect: 'default',
			fadeOutSpeed: 200,
			fadeInSpeed: 500
		});
	} else {
		$("a.button-register").tabs(".panel-schulung .tab-content-schulung", {
			effect: 'fade',
			fadeOutSpeed: 200,
			fadeInSpeed: 1000
		});

		$(".tab-schulung ul").tabs(".panel-schulung .tab-content-schulung", {
			effect: 'fade',
			fadeOutSpeed: 200,
			fadeInSpeed: 1000
		});
	}

	$('.activate-discipline-preview').hover(function() {
		var id = $(this).attr('rel');
		console.log(id);
		if (id != "") {
			$('#discipline-default').css('display', 'none');
			$('#discipline-'+id).css('display', 'block');
		}
	}, function() {
		id = $(this).attr('rel');
		if (id != "") {
			$('#discipline-default').css('display', 'block');
			$('#discipline-'+id).css('display', 'none');
		}
	});
	
	$('ul.level3').each(function(){
		if ($('li', $(this)).not('ul.level4 li').length > 9){
			var elements = '';
			$('li', $(this)).not('ul.level4 li').each(function(i){
				if (i+1 > 9){
					elements += '<li class="sub2">'+$(this).html()+'</li>';
					$(this).remove();
				}
			});
			$(this).parent().append('<ul class="level3" style="margin-left:215px">'+elements+'</ul>')
		}
	});
});
