$(document).ready(function() {
	// Headerbilder durchfaden
	$('#headerimages img:first-child').show();
	var images = $('#headerimages img');
	if (images.length > 1) {
		window.setInterval("headerimagesSlideshow()", 5000);
		headerimagesSlideshow();
	}

	// Suchbox auf Klick leeren
	var searchbox = $('#search form input#sword');
	if (searchbox.length > 0) {
		searchbox.attr('title', searchbox.attr('value'));
		searchbox.focus(function() {
			if (searchbox.attr('value') == searchbox.attr('title'))
			  searchbox.attr('value', '');
			  searchbox.css('background-color', '#ffffff');
			  searchbox.css('color', '#000000');
		});

		searchbox.blur(function() {
			if (searchbox.attr('value') == '')
			  searchbox.attr('value', searchbox.attr('title'));
			  searchbox.css('background-color', '#003942');
			  searchbox.css('color', '#ffffff');
		});
	}

	// Liste-Hover
	$('.lists .list').mouseenter(function() { $(this).css('background-color', '#d9e1e3') });
	$('.lists .list').mouseleave(function() { $(this).css('background-color', '#ffffff') });
	// Listen-Hover fuer Links
	$('.lists .list .link img').mouseenter(function() { $(this).attr('src', $(this).attr('src').split('.gif').join('_orange.gif')); });
	$('.lists .list .link img').mouseleave(function() { $(this).attr('src', $(this).attr('src').split('_orange.gif').join('.gif')); });

	// Mitarbeitertabelle hover
	$('.tx-mitarbeitertabelle-pi1 table tr[class!="tx-mitarbeitertabelle-pi1-MA_header"]').mouseenter(function() { $(this).addClass('hover') });
	$('.tx-mitarbeitertabelle-pi1 table tr').mouseleave(function() { $(this).removeClass('hover') });

	// Newsletter-Formular bei focus leeren, wenn default-text
	$('div.newsletter form input[type="text"]').focus(function() {
		if ($(this).val() == $(this).attr('title')) { $(this).val(''); }
	});
	// Newsletter-Formular wieder fuellen mit default-text, wenn leer
	$('div.newsletter form input[type="text"]').blur(function() {
		if ($(this).val() == '') { $(this).val($(this).attr('title')); }
	});
	
	
	/*var mail_old = $('a.mail').html();
	var mail_new = mail_old.replace(/\(at\)/,'<img alt="(at)" src="fileadmin/templates/img/layout/2010/at_grey.gif" />');
	var mail_old = '';
	$('a.mail').html(mail_new);*/
	
	$('a.mail').each(function() {
		var mail_old = $(this).html();
		var mail_new = mail_old.replace(/\(at\)/,'<img alt="(at)" src="fileadmin/templates/img/layout/2010/at_grey.gif" />');
		$(this).html(mail_new);
	});
			
	
	$('a.mail').mouseenter(function() {
		var mail_grey = $(this).html();
		var mail_orange = mail_grey.replace(/fileadmin\/templates\/img\/layout\/2010\/at_grey.gif/,'fileadmin/templates/img/layout/2010/at_orange.gif'); 
		$(this).html(mail_orange);
	})
	
	$('a.mail').live('mouseleave',function() {
		var mail_orange = $(this).html();
		var mail_grey = mail_orange.replace(/fileadmin\/templates\/img\/layout\/2010\/at_orange.gif/,'fileadmin/templates/img/layout/2010/at_grey.gif'); 
		$(this).html(mail_grey);
	})
	
});

function headerimagesSlideshow() {
	var images = $('#headerimages img');
	if (images.length > 1) {
		for (var imageCounter=0; imageCounter<images.length; imageCounter++) {
			var image = $(images[imageCounter]);
			if (image.css('display') != 'none') {
				image.addClass('active');
				var myImageCounter = imageCounter + 1;
			}
		}
		if (myImageCounter >= images.length) myImageCounter = 0;
		$('#headerimages img.active').fadeOut(1500, function() {
			$(this).removeClass('active');
		});
		$(images[myImageCounter]).fadeIn(1500);
	}
}
