function initMainNavigation() {
	$('ul#mainNavigation > li').hover(
			function() {
				$(this).children('ul.secondLevel').stop().height('auto')
						.slideDown(300);
			}, function() {
				$(this).children('ul.secondLevel').stop().slideUp(10);
			});

}
function initContactform() {
	$("#kontaktformular")
			.validate(
					{
						rules : {
							customerName : {
								required : true,
								minlength : 2
							},
							customerEmail : {
								required : true,
								email : true
							},
							customerNachricht : {
								required : true,
								minlength : 3
							}
						},
						messages : {
							customerName : {
								required : 'Bitte geben Sie Ihren Namen ein!',
								minlength : jQuery
										.format('Bitte geben Sie mindestens {0} Zeichen ein!')
							},
							customerEmail : {
								required : 'Bitte geben Sie eine gültige E-Mail-Addresse an!',
								email : 'Bitte geben Sie eine gültige E-Mail-Addresse an!'
							},
							customerNachricht : {
								required : 'Bitte geben Sie eine Nachricht an uns ein!',
								minlength : jQuery
										.format('Bitte geben Sie mindestens {0} Zeichen ein!')
							}
						},
						// the errorPlacement has to take the table layout into
						// account
						errorPlacement : function(error, element) {
							(error).insertAfter($(element));
						},
						// specifying a submitHandler prevents the default
						// submit, good for the demo
						submitHandler : function() {
							submit();
						}
					});
}
var newsItemHeight = 0;
var aktiveNewsSwitch = false;
function initNewsSwitch() {
	$("#newsSwitch").css('position', 'relative');
	$("#newsSwitch .newsItem").each(function() {
		if ($(this).height() > newsItemHeight) {
			newsItemHeight = $(this).height();
		}
		$(this).css('position', 'absolute');
		$(this).hide();
	});
	$("#newsSwitch").height(newsItemHeight+20);
        $("#newsSwitch .newsItem").height(newsItemHeight+20);
	$("#newsSwitch .newsItem:first").show();
	aktiveNewsSwitch = window.setInterval('newsSwitcher("next")', 10000);
        $('.tickercounter .tickerplay').click(function(){
           if($(this).hasClass('tickerstopped')){
               aktiveNewsSwitch = window.setInterval('newsSwitcher("next")', 10000);
               $('.tickercounter .tickerplay').removeClass('tickerstopped')
           } else {
               window.clearInterval(aktiveNewsSwitch);
               $('.tickercounter .tickerplay').addClass('tickerstopped')
           }
        });
        $('.tickercounter .tickernext').click(function(){
            newsSwitcher('next');
        });
        $('.tickercounter .tickerprev').click(function(){
            newsSwitcher('prev');
        });
}
function newsSwitcher(direction) {
	actItem = $("#newsSwitch .newsItem:visible");
	actItem.fadeOut('slow');
        if(direction == 'next'){
            if (actItem.next('.newsItem').length > 0) {
                    actItem.next('.newsItem').fadeIn('slow');
            } else {
                    $("#newsSwitch .newsItem:first").fadeIn('slow');
            }
        } else {
            if (actItem.prev('.newsItem').length > 0) {
                    actItem.prev('.newsItem').fadeIn('slow');
            } else {
                    $("#newsSwitch .newsItem:last").fadeIn('slow');
            }
        }
}

$(document).ready(function() {
	initMainNavigation();
	if ($("#kontaktformular").length > 0) {
		initContactform();
	}
	if ($("#newsSwitch").length > 0) {
		initNewsSwitch();
	}
});

