var fadeDuration = 3000;
var fadeSpeed = 1500;
var currentBanner;

$(document).ready(function(){
	//menu
	if($('ul#menu > li.hasSub').length > 0){
		$('ul#menu > li.hasSub').each(function(){
			$(this).mouseenter(function(){
				var myHeight = 0;
				$(this).find('li').each(function(){
					myHeight += $(this).height();
				});
				$(this).children('ul.sub').stop().animate({ height: myHeight }, 150);
			}).mouseleave(function(){
				$(this).children('ul.sub').stop().animate({ height: 0 }, 150);
			});
		});
	}
	
	//init shadowbox
	Shadowbox.init();
	
	//suche
	if($('#sword')){
		var origText = $('#sword').attr('value');
		//alert(origText);
		
		$('#sword').focus(function(){
			if($('#sword').attr('value') == origText) $('#sword').attr('value', '');
		}).blur(function(){
			if($('#sword').attr('value') == '') $('#sword').attr('value', origText);
		});
	}
	
	//banner faden
	if($('#banner img').length > 1){
		setTimeout(function(){
			currentBanner = $('#banner img').length-1;
			$($('#banner img')[currentBanner]).css({ 'z-index': 15 });
			fadeBanner($('#banner img'));
		}, fadeDuration);
	}
});

function fadeBanner(images){
	var next = currentBanner-1;
	if(next < 0) next = images.length-1;
	$(images[next]).css({ 'z-index': 10, opacity: 1 });
	$(images[currentBanner]).fadeTo(fadeSpeed, 0, function(){
		$(images[next]).css({ 'z-index': 15 });
		$(images[currentBanner]).css({ 'z-index': 5 });
		
		currentBanner = next;
		
		setTimeout(function(){
			fadeBanner(images);
		}, fadeDuration);
	});
}
