var lastOpen = 0;
var mainObj = 0;

jQuery(window).load(function () {
	setPrintHeight ();
	
	var lastActiveLi = jQuery (jQuery('.teaser1 .mainmenu li')[0]);
	var lastActiveA = jQuery (jQuery('.teaser1 .mainmenu li')[0]).children('a');
	var teaserMainMenu = jQuery('.teaser1 .mainmenu li');
	
	lastActiveLi.addClass ('active');
	lastActiveA.addClass ('active');
	jQuery (jQuery('.teaser1 .submenu .subproducts')[0]).show ();
	
	teaserMainMenu.each (function (index) {
		jQuery (this).click (function () {
			if (typeof (jQuery('.teaser1 .submenu .subproducts')[index]) != 'undefined')
			{
				var obj = jQuery (jQuery('.teaser1 .submenu .subproducts')[index]);
				if (index > 2)
				{
					if  (jQuery.browser.msie && jQuery.browser.version == '7.0')
						obj.css ('marginTop', (jQuery('.teaser1 .submenu').height() - obj.height ()) + 20);
					else
						obj.css ('marginTop', (jQuery('.teaser1 .submenu').height() - obj.height ()));
				}
				
				if (lastActiveA != null)
					lastActiveA.removeClass ('active');
				if (lastActiveLi != null)
					lastActiveLi.removeClass ('active');
				
				lastActiveLi = jQuery (this);
				lastActiveLi.addClass ('active');
				lastActiveA = jQuery (this).children('a');
				lastActiveA.addClass ('active');
				
				jQuery('.teaser1 .submenu .subproducts').hide ();
				
				obj.show ();
				return false;
			}						   
		});										 
	});
	
	jQuery('.mainnavi li').each (function (index) {
			jQuery(this).mouseover (function () {
				jQuery(this).css ('backgroundColor', '#ffffff');
				if (typeof (jQuery('.subnavi')[index]) != 'undefined' && index != 4) // 4 = presse
				{
					showSubNavi (jQuery('.subnavi')[index], $(this));
				}
			});
			
			jQuery(this).mouseout (function() {				
				if (index == 4) // remove hover from Presse // 4 = presse
				{
					mainObj = jQuery(this);
					mainObj.css ('backgroundColor', '');
				}
				else
				{
					hideSubNavi ();
				}
			});
	});
	
	jQuery('.subnavi').each (function (index) {
		jQuery(this).mouseover (function () {
			showSubNavi (jQuery(this), mainObj);
			jQuery(this).show ();
		});
		jQuery(this).mouseout (function() {
			hideSubNavi ();
			jQuery(this).hide ();
		});					  
	});
	
	jQuery('.serviceboxcontent .dropdownheadline').click (function () {
		var rootelem = jQuery(this);
		var elem = jQuery('.serviceboxcontent .dropdowntext');
    	if (jQuery(elem).is(':hidden')) 
    	{
			rootelem.addClass ('active');
        	elem.slideDown("slow");
    	}
    	else 
    	{
			rootelem.removeClass ('active');
        	elem.slideUp ('slow', function() {
            	elem.hide ();
        	}); 
    	}
	});
		
	if (jQuery('#coda-slider-1').length != 0) {
		jQuery('#coda-slider-1').codaSlider({
			dynamicArrowLeftText: "",
			dynamicArrowRightText: "",
			dynamicTabsPosition: "bottom",
			slideEaseDuration: 2000,
			autoSlide: true,
			autoSlideInterval: 5000,
			autoSlideStopWhenClicked: true,
			autoHeight: false,
			dynamicArrows: false
		});
		// jQuery('div#slider2').codaSlider()
		// etc, etc. Beware of cross-linking difficulties if using multiple sliders on one page.
	}
	
	jQuery ('.thridnavi a').each (function () {
		jQuery (this).attr ('href', jQuery(this).attr ('href') + '#thirdnavi');
	});
	
	showManagementPotrait (0);
});

function changePic (obj, method)
{
	var images = jQuery(obj).children('img');
	
	if (method == 0)
	{
		jQuery(images[0]).removeClass ('hover');
		jQuery(images[1]).addClass ('hover');
	}
	else
	{
		jQuery(images[0]).addClass ('hover');
		jQuery(images[1]).removeClass ('hover');
	}
}

function showSubNavi (mainobj, listobj) 
{
	mainObj = jQuery(listobj);
	mainObj.css ('backgroundColor', '#ffffff');
	
	var obj = jQuery(mainobj);
		
	if (typeof (obj) != 'undefined')
	{
		if (lastOpen != 0)
			lastOpen.hide ();
			
		obj.show();
		lastOpen = obj;
	}
}

function hideSubNavi ()
{
	if (mainObj == 0)
		return false;
		
		
	mainObj.css ('backgroundColor', '');

	if (lastOpen != 0)
		lastOpen.hide();
}

function setPrintHeight () 
{
	var leftobj= jQuery('.printmiddleright');
	var rightobj = jQuery('.printmiddleleft');
	var top = Math.round ((jQuery(document).height () - leftobj.height ()) / 2);
	
	leftobj.css ('top', top);
	rightobj.css ('top', top);
}

function resizeIFrame (height)
{
	jQuery ('iframe').height (height);
	if ( jQuery.browser.msie ) {
		jQuery ('iframe').css ('height', height);
	}
	jQuery ('#mb_center').height (height + 8);
}

function lightbox (open) // 0 is open // 1 is close
{
	if (open == 0)
	{
		jQuery('.managementlightbox').show();
		jQuery('.aboutus_slider').hide();
	}
	if (open == 1)
	{
		jQuery('.managementlightbox').hide();
		jQuery('.aboutus_slider').show();
	}
}

function showManagementPotrait (no) 
{
	if (jQuery ('.managementlightbox .contentitem').length != 0) {
		jQuery('.managementlightbox .contentitem').each (function (index) {
			if (index == no)
			{
				jQuery ('.bild_'+(index+1)).addClass ('active');
				jQuery (this).show ();
			}
			else
			{
				jQuery ('.bild_'+(index+1)).removeClass ('active');
				jQuery (this).hide();
			}
		});
	}
}
