$(document).ready(function() {
	$('.topNav ul ul.children').each(function() {
		$(this).css({'height': $(this).outerHeight(), 'width': $(this).outerWidth() }).hide();
	});
	// nav
	$('.topNav > ul > li').hover(function() {
		$(this).find('ul.children').stop(true, true).fadeIn('fast');
	}, function() {
		$(this).find('ul.children').stop(true, true).fadeOut('slow');
	});
	// nach oben
	$("a[href^='#']").not("a[href^='#print']").click(function(){
		$('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top }, 'slow');
		return false;
	});
	// drucken
	$("a[href^='#print']").click(function(){
		window.print();
		return false; 
	});
	// externe links
	$('a.extern').attr('target','_blank')
	// suchformular
	if($('#searchform input[type=text]').length > 0 && $('#searchform input[type=text]').val() == '') {
		$('#searchform input[type=text]').val('Ihr Suchwort');
	}
	$('#searchform input[type=text]').focus(function() {
		if($(this).val() == 'Ihr Suchwort') {
			$(this).val('');
		}
	}).blur(function() {
		if($(this).val() == '') {
			$(this).val('Ihr Suchwort');
		}
	});
	$('form').submit(function() {
		var ae = $(this);
		var error = 0;
		ae.find('.error').removeClass('error');
		ae.find('.errorText').remove();
		ae.find('p.required').each(function() {
			$(this).find('textarea, input[type=text]').each(function() {
				if($(this).hasClass('www')) {
					if($(this).val() != '') {
						error++;
					}
				} else if($(this).val() == '') {
					error++;
					$(this).parent().addClass('error');
				}
			});
		});
		if(error == 0) {
			return true;
		} else {
			ae.prepend('<div class="errorText">Bitte f&uuml;llen Sie alle Pflichtfelder aus</div>');
			$('html, body').animate({ scrollTop: ae.offset().top }, 'slow');
		}
		return false;
	});
	// li:hover
	$('li.recentcomments').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	}).click(function() {
		location.href = $(this).find('a').attr('href');
	});
	// colorbox
	$("a[href*='.jpg'], a[href*='.png'], a[href*='.gif']").each(function() {
		$(this).attr('rel', 'colorbox[g]');
	});
	if($('a[rel="colorbox[g]"]').length > 0) {
		$('a[rel="colorbox[g]"]').colorbox({
			maxHeight: '80%',
			maxWidth: '80%'
		});
	}
	// reset
	$('input[type="reset"]').click(function() {
		$(this).parents('form').find('.error').removeClass('error');
		$(this).parents('form').find('.errorText').remove();
	});
	// submit
	if($.browser.msie) {
		$('#searchform input#searchsubmit').val('');
	}
});
