var customPopToolbar     = "0";
var customPopLocation    = "0";
var customPopDirectories = "0";
var customPopStatus      = "0";
var customPopMenubar     = "0";
var customPopMenubar2    = "no";
var customPopScrollbars  = "1";
var customPopResizable   = "1";
var customPopCopyhistory = "0";
var customPopHeight      = "450";
var customPopWidth       = "480";
var customPopTop         = "0";
var customPopLeft        = "0";

function wopen(url,wtitle,wParams)
{
  nwin = window.open(url,wtitle,wParams);
  nwin.focus();
  return false;
}
$(document).ready(function($){

	// ie < 7.0 kann kein li:hover
	if ($.browser.msie && $.browser.version < '7') {
	    var ie6navigation = function (e) {
			if (this.hovering) {
				this.hovering = false;
			} else {
				this.hovering = true;
			}
			$(this).toggleClass('hover');
		};
		function buttonHover(e) {
			ie6navigation.call(this, e);
			$(this.parentNode).toggleClass(this.className);
		}
		function hideInputs(e) {
			ie6navigation.call(this, e);
			$(this).nextAll().find('input, select').toggle();
		}
		$('ul.nav > li').hover(ie6navigation, ie6navigation);
		//$(' ul.nav li.first > a').hover(ie6navigation, ie6navigation);
		//$(' ul.nav ul li > a').hover(ie6navigation, ie6navigation);
		//$('.homePage .Navigation').hover(ie6navigation, ie6navigation);
		//$('.branchen .Navigation').hover(ie6navigation, ie6navigation);
		$('div.einstieg > div.tipp, div.einstieg > div.suchfeld').hover(ie6navigation, ie6navigation);
		$('.buttonGo').hover(ie6navigation, ie6navigation);
		
		
	}
	function defaultDelay()
  {
    r = 1000;
    if(typeof(customDelay) == "function")
    {
      r = customDelay();
    }
    return r;
  }
  function defaultFade()
  {
    r = 3000;
    if(typeof(customFade) == "function")
    {
      r = customFade();
    }
    return r;
  }
	function toggleTeaser(elements, delay, fade) {
		delay = delay || defaultDelay();
		fade = fade || defaultFade();
    
		var homeTeaser = $(elements);
		homeTeaser.filter(':eq(0)').show();
		homeTeaser.filter(':not(:eq(0))').hide();
		var current;
		var last;
		var paused = false;
		function toggle(i) {
			if (paused) {
				return false;
			}
			current = i % homeTeaser.length;
			homeTeaser.filter(':not(:eq(' + last + '))').hide();
			homeTeaser.filter(':eq(' + last + ')').css({'z-index': 9, position:'static'});
			last = current;
			homeTeaser.filter(':eq(' + current + ')').css({'opacity':0, 'z-index': 10, position: 'absolute', top: 0, left:0}).animate({'opacity': 1.0}, delay).fadeIn(fade, function () {toggle(current + 1)} );
			return true;
		};
		toggle.pause = function () {
			paused = true;
		}
		toggle.start = function () {
			last = 0;
			paused = false;
			toggle(1);
		}
		return toggle;
	};
	var toggleHomeTeaser = toggleTeaser('.buehne #section-0 .buehneImg', defaultDelay(), defaultFade());
	toggleHomeTeaser.start();

function getViewUrl(mode)
{
  var l = window.location.href;
  var sTerm = "viewMode=";
  if(l.indexOf(sTerm) > -1)
  {
    var l = l.replace(/.viewMode=.../g,"");
  }
  var s = "?";
  if(l.indexOf("?") > -1)
  {
    s = "&";
  }
  return l + s + sTerm + mode;
}

var minLocation = getViewUrl("min");
var maxLocation = getViewUrl("max");
var stdLocation = getViewUrl("std");
/*
  if (document.cookie) {
  mode = document.cookie;
  
  if(mode.indexOf("ShowModeMinus") > -1)
  {
    $("body").addClass("minus");
    $("body").removeClass("standard");
		$("body").removeClass("plus");
  }
  else if(mode.indexOf("ShowModePlus") > -1)
  {
    $("body").addClass("plus");
    $("body").removeClass("standard");
		$("body").removeClass("minus");
  }
  else
  {
    $("body").addClass("standard");
    $("body").removeClass("minus");
		$("body").removeClass("plus");
  }
  } */
	// schriftgrößen
	$("a#toggleMinus").bind('click', function(){
		/*$("body").addClass("minus");
    document.cookie = ("ShowModeMinus");
		$("body").removeClass("standard");
		$("body").removeClass("plus");*/
    window.location.href = minLocation;
		return false;
	});
	$("a#toggleStandard").bind('click', function(){
		/*$("body").addClass("standard");
    document.cookie = ("ShowModeStandard");
		$("body").removeClass("minus");
		$("body").removeClass("plus");*/
    window.location.href = stdLocation;
		return false;
	});
	$("a#togglePlus").bind('click', function(){
		/*$("body").addClass("plus");
    document.cookie = ("ShowModePlus");
		$("body").removeClass("standard");
		$("body").removeClass("minus");*/
    window.location.href = maxLocation;
		return false;
	});
	

    // Klappfunktion
    $(".klapp a.klappA ").bind("click", function(e) {
    	$this = $(this);
        $this.parents('.klapp').find(".klappDiv").toggleClass($this.parents('.homePage, .branchen, .application').length ? 'aktivHome' : "aktiv");
		$this.parents('.klapp').find(".h3Plus").toggleClass("klappaktiv");
		if ($.browser.msie && $.browser.version < '7') {
			$('body').toggleClass('iedummy');
		}
        return false;
    });
    
	// ticker
    $('ul.ticker').each(function (i, item) {
		var $this = $(this).css({width:'auto', whiteSpace:'nowrap'});
		
		var li = $this.children();
		var liheight = li.height();
		$this.wrap('<div class="tickerdiv" style="height:' + liheight + 'px"/>');
		var ulwidth = $this.width();
    var divwidth = $this.parent().width() + 30;
		function scroll() {
			$this.css({left:divwidth + 'px'}).animate({left:'-=' + (divwidth + ulwidth) + 'px'}, Math.ceil(ulwidth / 20 * 1000), 'linear', scroll);
		};
		scroll();
	});
	
	// zuklappen
  
        // alle Klapp-Links einmal anklicken, um sie zu schließen
        $(".sitemap.klapp :not(.klappaktiv) a.klappA, .rechteSpalte .klapp a.klappA").click();
        // Klapp-Links in der Marginalspalte für Startseite, 1. Ebene, Anwendungen und alle Elemente mit der Klasse immerOffen nochmals anklicken, um sie wieder zu öffnen
        $(".homePage .rechteSpalte .klapp a.klappA, .branchen .rechteSpalte .klapp a.klappA, .application .rechteSpalte .klapp a.klappA, .rechteSpalte .immerOffen a.klappA").click();
/*
	$(".sitemap.klapp :not(.klappaktiv) a.klappA, :not(.homePage) .rechteSpalte .klapp :not(.klappaktiv) a.klappClose").click();
	$(".sitemap.klapp :not(.klappaktiv) a.klappA, :not(.branchen) .rechteSpalte .klapp :not(.klappaktiv) a.klappClose").click();
	$(".sitemap.klapp :not(.klappaktiv) a.klappA, :not(.application) .rechteSpalte .klapp :not(.klappaktiv) a.klappClose").click();
*/
  
	
	
	// print-links
	$('*.fn-print').click(function (e) {
		e.preventDefault && e.preventDefault();
		e.returnValue = false;
		self.print();
		return false;
	});
	
	
	// formulare reiter-nav
	var formReiter = $('ul.formReiter');
	var formReiterContent;
  if(!formReiter.hasClass("dontRegister"))
  {
    formReiterContent = formReiter.siblings('.formular');
	  formReiter = formReiter.children('li');
	  formReiter.each(function (i, item) {
		$(this).find('a').click(function (e) {
			formReiter.children('a').removeClass('aktuell');
			$(this).addClass('aktuell');
			formReiterContent.hide().filter(':eq(' + i + ')').show();
			return false;
		  });	
	  });
	}
	var buehne = $("div.buehne > div")
	$('ul.reiter').mouseout(function (e) {
		buehne.hide().filter(':eq(0)').show();
		return false;
	}).children().each(function (i, item) {
		$(this).find('a').mouseover(function (e) {
			buehne.filter(':eq(' + (i + 1) + ')').show().siblings().hide();
			return false;
		});
	});
	
       
        if(typeof $('.date-pick').datePicker == "function")
        {
	$('.date-pick').datePicker({createButton:true}).each(function (i, item) {
		$this = $(this);
		$this.siblings('.dp-choose-date').mouseover(function (e) {
			$this.dpDisplay(this);
		});
	
	});
        }

	function umfangOnChange() {
		switch (this.value) {
		case 'Teilzeit':
			$(this).siblings('input.showZeiten').attr('disabled', false).removeClass('disabled');
			$(this).siblings('label.showZeiten').removeClass('disabled');
			break;
		default:
			$(this).siblings('input.showZeiten').attr('disabled', true).addClass('disabled');
			$(this).siblings('label.showZeiten').addClass('disabled');
		}
	}
	$('.Aktivieren').change(umfangOnChange);
	
	
	// popup-fenster
	var mini;
        
function popPrint(){
  var a = window.location.href;
    if(a.indexOf("?") > -1)
    {
      if(a.indexOf("popup=true") > -1)
      {
        a += "&print=true";
      }
      else
      {
        a += "&popup=true&print=true";
      }
    }
    else
    {
      a += "?popup=true&print=true"; 
    }
    
		mini=window.open(a,'PopPrint','toolbar=0,location=0,directories=0,status=0, menubar=0,menubar=no,scrollbars=1,resizable=1,copyhistory=0,height=724,width=720,top=0,left=0');
		mini.focus();
		return false;
	}
	$('a.popupPrint').click(popPrint);

    
	function pop(){
		var a = this.href;
    if(a.indexOf("?") > -1)
    {
      a += "&popup=true";
    }
    else
    {
      a += "?popup=true";
    }
    
		mini=window.open(a,'Pop','toolbar=0,location=0,directories=0,status=0,menubar=0,menubar=no, scrollbars=1,resizable=1,copyhistory=0,height=724,width=700,top=0,left=0');
		mini.focus();
		return false;
	}
	$('a.popup').click(pop);
		
	
	function popKlein(){
		var a = this.href;
    if(a.indexOf("?") > -1)
    {
      a += "&popup=true";
    }
    else
    {
      a += "?popup=true";
    }
		mini=window.open(a,'PopKlein','toolbar=0,location=0,directories=0,status=0,menubar=0,menubar=no, scrollbars=1,resizable=1,copyhistory=0,height=450,width=480,top=0,left=0');
		mini.focus();
		return false;
	}
	$('a.popupKlein').click(popKlein);
	
  function popCustom(){
		var a = this.href;
    if(a.indexOf("?") > -1)
    {
      a += "&popup=true";
    }
    else
    {
      a += "?popup=true";
    }
    var customPopParams = "";
    
    customPopParams += ("toolbar=" + customPopToolbar);
    customPopParams += (",location=" + customPopLocation);
    customPopParams += (",directories=" + customPopDirectories);
    customPopParams += (",status=" + customPopStatus);
    customPopParams += (",menubar=" + customPopMenubar);
    customPopParams += (",menubar=" + customPopMenubar2);
    customPopParams += (",scrollbars=" + customPopScrollbars);
    customPopParams += (",resizable=" + customPopResizable);
    customPopParams += (",copyhistory=" + customPopCopyhistory);
    customPopParams += (",height=" + customPopHeight);
    customPopParams += (",width=" + customPopWidth);
    customPopParams += (",top=" + customPopTop);
    customPopParams += (",left="+ customPopLeft);
    
    
		mini=window.open(a,'PopCostom',customPopParams);
		mini.focus();
		return false;
	}
  
  
	$('a.popupCustom').click(popCustom);
	
		
	function popLarge(){
		var a = this.href;
    if(a.indexOf("?") > -1)
    {
      a += "&popup=true";
    }
    else
    {
      a += "?popup=true";
    }
    mini=window.open(a,'PopLarge','toolbar=0,location=0,directories=0,status=0,menubar=0,menubar=no, scrollbars=1,resizable=1,copyhistory=0,height=550,width=935,top=0,left=0');
		mini.focus();
		return false;
	}
	$('a.popupLarge').click(popLarge);
});




