$(document).ready(function() {

	function toggleLangSelector() {
		var div = $("#lang"),
			ul = div.find("ul").hide();
			toggle = $("#langToggle");
			
		toggle.click(function() {
			ul.slideToggle();
			return false;
		});
	}
	
	function newsTeaserTabs() {
		if ($("#newsTeaser").length) {
			var container = $("#newsTeaser"),
				buttons = container.find("#tabNav li").css({ cursor: "pointer" }),
				tabs = container.find("div.tab");
			buttons.click(function() {
				$(this).addClass("active").siblings().removeClass("active");
				var href = $(this).find("h4 a").attr("href");
				tabs.hide().filter(href).fadeIn("fast");
				return false;
			}).eq(0).click();
		}
	}
	
	toggleLangSelector();
	newsTeaserTabs();

});

$(window).load(function() {

	function positionLogos() {
		var tallest = 0,
			imagesTotalWidth = 0,
			list = $("ul#customerLogos"),
			listWidth = list.width(),
			images = list.find("img"),
			imagesAll = images.length;
		images.each(function(i, el) {
			var imgHeight = $(el).height(),
				imgWidth = $(el).width();
			imagesTotalWidth += imgWidth;
			if (imgHeight > tallest) {
				tallest = imgHeight;
			}
			if (imgHeight < tallest) {
				$(el).css({
					marginTop: ((tallest - imgHeight)/2) + "px"
				});
			}
		});
		var extantSpace = listWidth - imagesTotalWidth;
		images.not(":eq(0)").css({
			marginLeft: (extantSpace/(imagesAll - 1)) + "px"
		});
	}

	positionLogos();

});


function checkInputs() {
  var form = document.getElementById('contactform');
  var inputs = form.getElementsByTagName('input');
  for (var i=0; i<inputs.length; i++) {
    var value = inputs[i].value;
    if (value == '') {
      var warningPara = document.createElement('p');
      var warningText = document.createTextNode('Bitte die erforderlichen Felder ausf&uuml;llen.');
      warningPara.appendChild(warningText);
      warningPara.setAttribute('class', 'warning');
      var required = document.getElementById('required');
      var parent = required.parentNode;
      parent.insertBefore(warningPara, required);
      return false;
    }
  }
};

