$(document).ready(function() {
		
	/* Home-Box */
	showHomeTeaser( getRandomNumber( 3 ) );
	
	/* Setup Accordion Teaser Menu on the right */
	$( ".rightTeaserAccordion" ).accordion({
		header: 'div.header'
	});
	$( ".rightTeaserAccordion .item:first-child" ).addClass('active');

	$('#divTeaserContainer').bind('accordionchangestart', function(event, ui) {
		ui.newHeader.parent('div').toggleClass('active');
		ui.oldHeader.parent('div').toggleClass('active');
	});

	$('.divContentBody').bind('accordionchangestart', function(event, ui) {
		ui.newHeader.parent('div').toggleClass('active');
		ui.oldHeader.parent('div').toggleClass('active');
	});

	/* Menu Box Toggling */
	$('.menuBoxOrange .entry .entryHeader, .menuBoxBlue .entry .entryHeader, .menuBoxGrey .entry .entryHeader').click(function() {
		$(this).parent('div').toggleClass('active');
		$(this).siblings(".subMenu").slideToggle({
			speed: "fast"/*,
			easing : "swing"*/
		});
	});

	/* Top Navigation */
	var topNavigation = $( "#divTopNavigation" );
	$('#divTopNavigation a').each( function() {
		var topNavigationMenu = $( "#topNavigationMenu" + $( this ).attr( 'rel' ) );

		if ( $( "div", topNavigationMenu ).length > 1 ) {
			var left = topNavigation.position().left + $( this ).position().left + ( $( this ).width() / 2 ) - ( topNavigationMenu.width() / 2 );
		} else {
			var left = topNavigation.position().left + $( this ).position().left - 23;
		}

		topNavigationMenu.css({
            top: topNavigation.position().top + 20,
            left: left
		});

		$(this).mouseover(function() {
			$('.topNavigationMenu').hide();
			topNavigationMenu.show();
		});

		$("#divCompleteContainer").mouseover(function() {
			topNavigationMenu.hide();
		});
	});	
});




function showHomeTeaser(id) {

	var homeTeasers = $(".startbox_image");
	for (var i = 0; i < homeTeasers.length ; i++) {
		if (i == id) {
			$(homeTeasers[i]).fadeIn( "def" );
			$("#homeTeaserSwitchButton" + i).addClass("active");
			$("#homeTeaserSwitchButton" + i).removeClass("inactive");
		} else {
			$(homeTeasers[i]).hide();
			$("#homeTeaserSwitchButton" + i).removeClass("active");
			$("#homeTeaserSwitchButton" + i).addClass("inactive");
		}
	}
	
}

function getRandomNumber(max) {
	return parseInt( Math.random() * max ) 
}

