/*-- spam protection --*/

	function getAdr(prefix, postfix, text) {
		document.write('<a href="mailto:' + prefix + '@' + postfix + '">' + (text ? text.replace(/&quot;/g, '"').replace(/%EMAIL%/, prefix + '@' + postfix) : prefix + '@' + postfix) + '</a>');
	}

/*-- swap image --*/

	function swapImage(element, newimage) {
		var oldsrc = element.src;
		element.src = newimage;
		if (!element.onmouseout) {
			element.onmouseout = function () {
				swapImage(this, oldsrc);
			}
		}
	}

/*-- popup --*/

	function popup(url, width, height) {
		window.open(url, 'Popup', 'width=' + width + ', height=' + height + ',scrollbars=1');
	    return false;
	}
	
	
/*-- display elements --*/

	(function($){
		$.fn.showElement = function(options){
			var SE_Settings = {
				handler: 'toggle',
				destination: '',
				animate: false
			};
			var SE_Settings = $.extend(SE_Settings, options);
			// hide href anchor destination
			if($(this).length){				
				if($(this).is('a')){
					var destination = ($(SE_Settings.destination).length) ? $(SE_Settings.destination) : $('#'+$(this).attr('href').split('#').pop());
				}
				else{
					$(this).wrapInner('<a href="#" />');
					var destination = $(SE_Settings.destination);
				}
				destination.hide();
				// show destination
				if(SE_Settings.handler == 'toggle'){
					// toogle destination
					$(this).toggle(
						function(){ (SE_Settings.animate) ? destination.animate(SE_Settings.animate, { duration: 'slow' }) : destination.show(); },
						function(){ (SE_Settings.animate) ? destination.animate(SE_Settings.animate, { duration: 'slow' }) : destination.hide(); }
					);
				}
				else if(SE_Settings.handler == 'mouseover'){
					// show destination on mouseover
					$(this).bind({
						click: function(){ return false; },
						mouseover: function(){ (SE_Settings.animate) ? destination.animate(SE_Settings.animate, { duration: 'slow' }) : destination.show(); },
						mouseout: function(){ (SE_Settings.animate) ? destination.animate(SE_Settings.animate, { duration: 'slow' }) : destination.hide(); }
					});
				}
			}
		};
	})(jQuery);


/*-- getElementsByClassName --*/

	function getElementsByClassName(strClass, strTag, objContElm) {
		strTag = strTag || "*";
		objContElm = objContElm || document;
		var objColl = objContElm.getElementsByTagName(strTag);
		if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
		var arr = new Array();
		var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
		var arrClass = strClass.split(delim);
		for (var i = 0, j = objColl.length; i < j; i++) {
			var arrObjClass = objColl[i].className.split(' ');
			if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
			var c = 0;
			comparisonLoop:
			for (var k = 0, l = arrObjClass.length; k < l; k++) {
				for (var m = 0, n = arrClass.length; m < n; m++) {
					if (arrClass[m] == arrObjClass[k]) c++;
					if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
						arr.push(objColl[i]);
						break comparisonLoop;
					}
				}
			}
		}
		return arr;
	}

/*-- slimbox --*/

	if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
		jQuery(function($) {
			$("a[rel^='lightbox']").slimbox({counterText: countertext, easing: "easeOutElastic"}, null, function(el) {
				return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
			});
		});
	}

/*-- validform --*/

	function init_forms() {
		var content = document.getElementById('content');
		if(content) {
			var forms = content.getElementsByTagName('form');
			for(f=0; f<forms.length; f++) {
				init_form(forms[f]);
			}
		}
		var email_empfaenger;
		var inputs = document.getElementsByTagName('*');
		for(i=0; i < inputs.length; i++) {
			if(inputs[i].name) {
				if(inputs[i].name == 'email_empfaenger') {
					email_empfaenger = inputs[i];
				}
			}
		}
		if(email_empfaenger) {
			if(email_empfaenger.tagName.toLowerCase() == 'select') {
				var options = email_empfaenger.getElementsByTagName('option');
				for(o=0; o<options.length; o++) {
					options[o].value = options[o].value.replace(/\+at\+/g, '@');
				}
				email_empfaenger.onchange = function() {
					var options = this.getElementsByTagName('option');
					for(o=1; o<options.length; o++) {
						if(options[o].selected) {
							var location_data = $($('.form_locations>div')[o-1]).find('span');
							var form = this.parentNode;
							while(form.tagName.toLowerCase() != 'form') {
								form = form.parentNode;
							}
							for(i=0; i<location_data.length; i++) {
								if(location_data[i].title != 'location_id') {
									form['to_' + location_data[i].title].value = location_data[i].innerHTML;
								}
							}
						}
					}
				}
				email_empfaenger.onchange();
			}
			else {
				email_empfaenger.value = email_empfaenger.value.replace(/\+at\+/g, '@');
			}
		}

		// check for form_application
		var url = document.location.href;
		if(url.indexOf('job_title') > -1 && document.getElementById('form_application')) {
			var spliturl = url.split('?');
			var splitparams = spliturl[1].split('&');
			var params = new Object();
			for(i=0; i<splitparams.length; i++) {
				var splitvalues = splitparams[i].split('=');
				params[splitvalues[0]] = splitvalues[1];
			}

			if(params['job_title'] && params['location_id'] && $("select[name='email_empfaenger']").length > 0) {
				$('.job input')[0].value = params['job_title'];
				$('.form_locations>div').each(function(i) {
					$(this).find('span').each(function(s) {
						if(this.title == 'location_id' && this.innerHTML == params['location_id']) {
							$("select[name='email_empfaenger'] option")[i+1].selected = true;
							$("select[name='email_empfaenger']")[0].disabled = true;
						}
					});
				});
				$("select[name='email_empfaenger']")[0].onchange();
			}
		}
	}

	function init_form(form) {
		var required = getElementsByClassName('required', '*', form);
		for(i=0; i<required.length; i++) {
			required[i].oldformonblur = required[i].onblur;
			required[i].onblur = function() {
				validate(this);
				if(this.oldformonblur)
					this.oldformonblur();
			}
		}
		form.onsubmit = function() {
			var doSubmit = true;
			var list = new Array();
			var required = getElementsByClassName('required', '*', this);
			for(v=0; v<required.length; v++) {
				if(! validate(required[v])) {
					doSubmit = false;
					list.push(required[v]);
				}
			}
			var checkboxeles = getElementsByClassName('required_checkbox', '*', this);
			for(i=0; i<checkboxeles.length; i++) {
				valid = false;
				checkboxes = checkboxeles[i].getElementsByTagName('input');
				for(c=0; c<checkboxes.length; c++) {
					if(checkboxes[c].type == 'checkbox') {
						checkboxeles[i].name = checkboxes[c].name; // we need the name to check for custom_required_texts
						if(checkboxes[c].checked)
							valid = true;
					}
				}
	
				if(valid == false) {
					doSubmit = false;
					set_msg(checkboxeles[i], valid_checkbox);
					list.push(checkboxeles[i]);
				} 
				else {
					clear_msg(checkboxeles[i]);
				}
			}
			var radioeles = getElementsByClassName('required_radio', '*', this);
			for(i=0; i<radioeles.length; i++) {
				valid = false;
				radios = radioeles[i].getElementsByTagName('input');
				for(c=0; c<radios.length; c++) {
					if(radios[c].type == 'radio') {
						radioeles[i].name = radios[c].name; // we need the name to check for custom_required_texts
						if(radios[c].checked)
							valid = true;
					}
				}
	
				if(valid == false) {
					doSubmit = false;
					set_msg(radioeles[i], valid_radio);
					list.push(radioeles[i]);
				} 
				else {
					clear_msg(radioeles[i]);
				}
			}

			if(doSubmit == false) {
				show_error(list);
				return doSubmit;
			}
		}
	}

	function validate(el) {
		var valid = true;
		clear_msg(el);
		switch(el.type) {
			case 'text':
			case 'textarea':
			case 'select-one':
				if(el.value != '') {
					if(el.className.indexOf('email') > -1) {
						var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
						if(el.value.toUpperCase().match(regEmail)){
							valid = true;
						}
						else {
							valid = false;
							set_msg(el, valid_email);
						}
					}
					if(el.className.indexOf('number') > -1) {
						if(el.value == Math.round(el.value)) {
							valid = true;
						}
						else {
							valid = false;
							set_msg(el, valid_postal_code);
						}
					}
				}
				else {
					valid = false;
					set_msg(el);
				}
				break;
		}
	
		return valid;
	}

	function set_msg(el, msg) {
		if(msg == undefined) {
			msg = el.parentNode.getElementsByTagName('span')[0].innerHTML.replace(' *', '') + ' ' + valid_required;
		}

		if(custom_required_text[el.name])
			msg = custom_required_text[el.name];

		el.errorMessage = msg;
		if(el.parentNode.className.indexOf('error') == -1)
			el.parentNode.className += ' error';
	}

	function clear_msg(el) {
		var classes = el.parentNode.className.split(' ');
		for(e=0; e<classes.length; e++) {
			if(classes[e].indexOf('error') > -1)
				classes[e] = "";
		}
		el.parentNode.className = classes.join(' ');
		el.errorMessage = "";
	}

	function show_error(list) {
		errorlist = '<ul>';
		for(i=0; i<list.length; i++) {
			el = list[i];
			if(el.errorMessage != undefined)
				errorMessage = el.errorMessage;
			else
				var errorMessage = el.parentNode.getElementsByTagName('span')[0].innerHTML.replace(' *', '') + ' ' + valid_required;
	
			errorlist += '<li>' + errorMessage + '</li>';
		};
		errorlist += '</ul>';
	
		var validationMessage = document.getElementById('validationMessage');
		validationMessage.innerHTML = '<h2 title="' + valid_error + '">' + valid_error + '</h2>' + errorlist;
		document.location.href = '#validationMessage';
	}

	$(function() {
		init_forms();
	});


/*-- display elements onmouseover --*/

	var hover_links = new Array();
	hover_links.push(new Array('info_func', 'info_text'));
	// To add more links, follow the same pattern
	// hoverLinks.push(new Array('linkid', 'elementid'));

	function init_show_elements() {
		for (i = 0; i < hover_links.length; i++) {
			var link = document.getElementById(hover_links[i][0]);
			if (link) {
				link.el = document.getElementById(hover_links[i][1]);
				if (link.el) {
					link.onmouseover = function() {
						this.el.style.display = 'block';
					};
					link.onmouseout = function() {
						this.el.style.display = 'none';
					}
					link.onclick = function() {
						return false;
					}
				}
			}
		}
	}

	$(function() {
		init_show_elements();
	});

	
	/*-- active menu --*/	
	
	function activenav(){
		if (document.getElementById('nav')) {
			navelements = document.getElementById('nav').getElementsByTagName('LI');

			for (i=0; i<navelements.length; i++) {

				if (navelements[i].className.indexOf('active') != -1 ) {
					if (navelements[i].getElementsByTagName('IMG')[0] && document.getElementById('activenavimage')){
						navelements[i].getElementsByTagName('IMG')[0].src = document.getElementById('activenavimage').href;
					}
				}
			}
		}
	}

	$(function() {
		activenav();
	});
	
	
	
	
/* border-radius plugin */

	// Last modification: 04/12/2010

	$.fn.borderRadius = function(radius){
		return this.each(function(e){
			$(this).css({
				"border-radius": radius,
				"-moz-border-radius": radius,
				"-webkit-border-radius": radius
			});
		});
	};
	
	
/*-- iframe popup --*/

	// Last modification: 04/13/2010

	// Settings
	var IP_Settings = {
		open: '.popup', // <a> tag with this class open as popup
		margin: 20, // Margin from the iframe popup
		width: 700, // Default popup width
		height: 500, // Default popup height
		borderradius: '10px'  // Popup border-radius
	};

	// Close popup
	function closeIframePopup(){
		$('body').css('overflow', bodyOverflow);
		$('html').css('overflow', htmlOverflow);
		$('.ip_popup').hide();
		$('.ip_overlay').fadeOut('slow');
		$(window).unbind('resize');
		// Remove tabindex="-1"
		$('.tabindex').each(function(){
			$(this).removeClass('tabindex').removeAttr('tabindex');
		});
	}

	// Keyboard events
	function keyDown(event) {
		var code = event.keyCode;
		return ($.inArray(code, [27,88,67]) >= 0) ? closeIframePopup() : true;
	}

	// Create iframe popup
	function createIframePopup(){
		$('body').append(
			$([
				ip_overlay = $('<div class="ip_overlay" />').click(closeIframePopup)[0],
				ip_popup = $('<div class="ip_popup" />').append([
					ip_close = $('<a class="close" href="#" title="'+close+' [ESC]">'+close+'</a>').click(closeIframePopup)[0],
					ip_title = $('<h2 class="title" />')[0],
					$('<div class="ip_content" />').append([
						ip_iframe = $('<iframe src="" frameborder="0" />')[0]
					])[0]
				])[0]
			]).hide()
		);
		$([
			bodyOverflow = $('body').css('overflow'),
			htmlOverflow = $('html').css('overflow')
		])
	}

	// Initialize iframe popup
	function initIframePopup(IP_Settings){
		if(IP_Settings.open.length){
			// Create iframe popup
			createIframePopup();
			// Open iframe popup
			$(IP_Settings.open).click(function(){
				// Hide scrollbar and fadein overlay
				$('body, html').css('overflow', 'hidden');
				$(ip_overlay).fadeTo('slow', 0.8);
				// Set tabindex="-1" to content
				$('a, input, textarea, select, button').not('.close').each(function(){
					$(this).addClass('tabindex').attr('tabindex', '-1');
				});
				// Get popup size from rel attribut
				var popupHeight = this.rel.split(',')[1];
				var popupWidth = this.rel.split(',')[0];
				if(popupWidth == null || popupHeight == null){
					popupWidth = IP_Settings.width;
					popupHeight = IP_Settings.height;
				}
				// Set popup size
				var NormalCSS = {
					'bottom': 'auto',
					'height': popupHeight+'px',
					'left': '50%',
					'margin-left' : Math.floor(-(popupWidth)/2)+'px',
					'margin-top': Math.floor(-(popupHeight)/2)+$(window).scrollTop()+'px',
					'max-height': popupHeight+'px',
					'top': '50%',
					'width' : popupWidth+'px'
				};
				var FlexibleCSS = {
					'bottom': IP_Settings.margin+'px',
					'height': 'auto',
					'margin-top': 0,
					'top': IP_Settings.margin+'px'
				};
				// Normal iframe popup size
				$(ip_popup).css(NormalCSS).borderRadius(IP_Settings.borderradius).show();
				// Flexible iframe popup size
				$(window).resize(function(){
					($(this).height() <= ($(ip_popup).height()+2*IP_Settings.margin)) ? $(ip_popup).css(FlexibleCSS) :	$(ip_popup).css(NormalCSS);
				});
				// Insert iframe title
				$(ip_title).html(this.title);
				// Insert iframe content
				$(ip_popup).addClass('ip_loading');
				$(ip_iframe).attr('src', this);	
				// Preloader
				$(ip_iframe).css('visibility', 'hidden');
				$(ip_iframe).load(function(){
					$(ip_popup).removeClass('ip_loading');
					$(ip_iframe).css('visibility', 'visible');
				});
				return false;
			});
			$(document).bind('keydown', keyDown);
		}
	}

	$(function(){
		initIframePopup(IP_Settings);
	});


/*-- Starttext --*/
 
  var starttextinterval;
  var starttextshown = false;
  
  function showStarttext(){
     $('#contentstart').fadeTo('slow', 1);
  }
  
  $(function(){
    if (!starttextshown)
    { 
      starttextinterval = setInterval('showStarttext()', 1500);
      starttextshown = true;  

    }
    $('#sujetstart').mouseenter(function(){ 
      $('#contentstart').fadeTo('slow', 1); 

		});
		$('#contentstart').mouseleave(function (){
		  $('#contentstart').fadeOut(300,0);
		  if (starttextshown){
        clearInterval(starttextinterval);
      }
    });            
   });



/*-- content accordion --*/

  $(document).ready(function() {
    
   
    //========ACCORDION============//
    $('div.accHead').click(function() {
      if ( $(this).hasClass('active') ) {
        $('.accCont').slideUp('normal');	  
    		$(this).removeClass("active");	
      }
      else {
        $('div.accCont').slideUp('normal');	
    		$(this).next().slideDown('normal');  
    		$(this).siblings().removeClass("active");
    		$(this).addClass("active");		     

      }	     
  	});	
	  $("div.accCont").hide();
	  $('div.firstaccCont').show();
	});
  
  
/*-- was sollten Sie ... --*/
  
  
  $(function(){
    
    $('#info_func').mouseenter(function(){ 
      $('#info_text').css('display', 'block'); 
         
		});
    
    $('#info_func').mouseleave(function(){ 
      $('#info_text').mouseenter(function(){ 
        $('#info_text').css('display', 'block'); 
           
  		});
      $('#info_text').mouseleave(function(){ 
        $('#info_text').css('display', 'none'); 
           
  		});       
		});  
  });
  
  
/*-- alternativ x-menu --*/

	// -- change any of the following settings to true or false, depending on your preferred animation style -- //
	var navAnimateSettings = {
		slide_vertical: false,
		slide_horizontal: true,
		opacity: false
	};

	// -- change the following value for animation speed (in milliseconds) -- //
	var navAnimationSpeed = 0;

	// -- don't change anything below this line! -- //
	var navImagesNormal = new Array();
	var navImagesHover = new Array();
	var navPrevOpened;
	var navInterval;
	var defaultSettings = {
		paddingTop: 0,
		paddingBottom: 0,
		paddingLeft: 0,
		paddingRight: 0
	};
	
	if(navAnimateSettings['slide_vertical']) defaultSettings['height'] = 0;
	if(navAnimateSettings['slide_horizontal']) defaultSettings['width'] = 0;
	if(navAnimateSettings['opacity']) defaultSettings['opacity'] = 0;

	function nav_close_prev_opened(){
		if(navPrevOpened && navPrevOpened.opened){
			if(navInterval)
				clearInterval(navInterval);

			// when there's no subnav, remove class now
			if($(navPrevOpened).children('ul').length == 0){
				$(navPrevOpened).removeClass('hover');
			}
			else {
				$(navPrevOpened).children('ul').stop().animate(defaultSettings, navAnimationSpeed, function(){
					$(this).css('display', 'none');
					$(this).parent('li').removeClass('hover');
					this.parentNode.opened = false;
				});
			}

			var img = navPrevOpened.getElementsByTagName('img');
			if(img[0] && navImagesNormal[navPrevOpened.number])
				img[0].src = navImagesNormal[navPrevOpened.number];
		}
	}

	function init_nav(){
		if(document.getElementById('nav')){
			var nav = document.getElementById('nav');
			var lis = nav.getElementsByTagName('li');
			for(var i = 0; i < lis.length; i++){
				if(lis[i].parentNode.id == 'nav'){
					$(lis[i]).addClass('hover'); // to see what it looks like on hover
					lis[i].ulHeight = $(lis[i]).find('ul').height();
					lis[i].ulWidth = $(lis[i]).find('ul').width();
					lis[i].ulPaddingTop = $(lis[i]).find('ul').css('padding-top');
					lis[i].ulPaddingBottom = $(lis[i]).find('ul').css('padding-bottom');
					lis[i].ulPaddingLeft = $(lis[i]).find('ul').css('padding-left');
					lis[i].ulPaddingRight = $(lis[i]).find('ul').css('padding-right');
					$(lis[i]).removeClass('hover'); // remove class hover, we know what it should look like

					$(lis[i]).children('ul').css(defaultSettings);
					$(lis[i]).children('ul').css({
						visibility: 'visible',
						display: 'none',
						overflow: 'hidden',
						minWidth: 0,
						minHeight: 0
					});
					lis[i].number = i;
					$(lis[i]).mouseenter(function(){
						nav_close_prev_opened();
						navPrevOpened = this;
						navPrevOpened.opened = true;

						var animationObject = {
							height: this.ulHeight + 'px',
							width: this.ulWidth + 'px',
							paddingTop: this.ulPaddingTop,
							paddingBottom: this.ulPaddingBottom,
							paddingLeft: this.ulPaddingLeft,
							paddingRight: this.ulPaddingRight
						}

						if(navAnimateSettings['opacity']){
							animationObject.opacity = 1;
						}

						$(this).addClass('hover');
						$(this).find('ul').stop().animate(animationObject, navAnimationSpeed);

						var img = this.getElementsByTagName('img');
						if(img[0] && navImagesHover[this.number])
							img[0].src = navImagesHover[this.number];
					});
					$(lis[i]).mouseleave(function(){
						navInterval = setInterval('nav_close_prev_opened()', 1000);
					});
					var img = lis[i].getElementsByTagName('img');
					if(img[0] && img[0].onmouseover){
						navImagesNormal[i] = img[0].src;
						img[0].onmouseover();
						navImagesHover[i] = img[0].src;
						img[0].onmouseout();
						img[0].onmouseover = function(){};
						img[0].onmouseout = function(){};
					}
					var anchors = lis[i].getElementsByTagName('A');
					for(j=0; j<anchors.length; j++){
						anchors[j].title = '';
					}
				}
			}
		}
	}

	$(function(){
		init_nav();
	});

/* Create onchange select plugin
------------------------------------------------------------------------------------------------ */

(function($){
    $.fn.createOnchangeSelect = function(options){
        var settings = $.extend({
            'label': false,
            'group': false,
            'id': 'selection'
        }, options);

        return this.each(function(){
            var el = this;
            if(!$('li a', el).length)
                return;
            if(settings.group){
                // Create form and select
                $(el).append(
                    form = $('<form>').attr('action', '').append(
                        select = $('<select>').attr({
                            'id': settings.id,
                            'name': settings.id
                        }).addClass($(this).attr('class'))
                    )
                );
                // Create optgroup
                $(settings.group, el).each(function(){
                    $(select).append(
                        optgroup = $('<optgroup>').attr('label', $(this).text())
                    );
                    // Fill select with options
                    $.fn.createOnchangeSelect.fillSelect($(this).next('ul'), optgroup);
                });
            }
            else{
                $('ul, ol', el).each(function(){
                    // Create form and select
                    $(this).after(
                        form = $('<form>').attr('action', '').append(
                            select = $('<select>').attr({
                                'id': settings.id,
                                'name': settings.id
                            }).addClass($(this).attr('class'))
                        )
                    );
                    // Fill select with options
                    $.fn.createOnchangeSelect.fillSelect(el, select);
                });
            }
            // Onchange
            $(select).change(function(){
                location.href=this.value;
            });
            // Create label
            if(settings.label){
                $(form).prepend(
                    label = $('<label>').attr('for', settings.id).text($(settings.label).text())
                );
            }
            // Remove non javascript html code
            $('ul, ol, '+settings.group, el).remove();
            $(settings.label).remove();
        });
    }

    // Fill select with options
    $.fn.createOnchangeSelect.fillSelect = function(el, select){
        $('li a', el).each(function(){
            $(select).append(
                option = $('<option>').val(this.href).text($(this).text())
            );
            if($(this).hasClass('active'))
                $(option).attr('selected', 'selected');
        });
    }
})(jQuery);

/* DOM
------------------------------------------------------------------------------------------------ */

$(document).ready(function() {
    // News object

    $('#news_selection').createOnchangeSelect({
        'label' : '#news_selection h3'
    });
    
    /*$('#dbluebottom #more_info img').css('opacity', '0');
    
    $('#dbluebottom #more_info img').animate({
        opacity: 0,
        width: '0'
    }, 2000, function(){
        $('#dbluebottom #more_info img').animate({
            opacity: 1,
            width:'132px'
        }, 1000, function(){
            //alert("End");
        });
    });*/
});	
