$(document).ready(function() {
	
	// Search-Newsletter-Login Slider
	
	var boxTimeout = false;
	var boxLock = false;
	
	var hideBoxes = function() {
		boxLock = false;
		$('#SearchNewsletterLoginBoxes .SearchNewsletterLoginBox')
				.stop(true, true).hide();
		$('#SearchNewsletterLogin a.Hover').removeClass('Hover');
	};
	var clearBoxTimeout = function(lock) {
		if (lock) boxLock = true;
		window.clearTimeout(boxTimeout);
	};
	var setBoxTimeout = function(lock) {
		if (boxLock) return;
		clearBoxTimeout();
		boxTimeout = window.setTimeout(hideBoxes, 500);
	};
	
	$('#SearchNewsletterLogin a').hover(function() {
		clearBoxTimeout();
		hideBoxes();
		var selector = $(this).addClass('Hover').attr('href');
		var box = $(selector);
		box.stop(true, true).slideDown('fast');
	}, setBoxTimeout).click(function() {
		return false;
	});
	
	$('#SearchNewsletterLoginBoxes .SearchNewsletterLoginBox').hover(function() {
		clearBoxTimeout();
	}, setBoxTimeout);
	
	$('#SearchNewsletterLoginBoxes input').focus(function() {
		clearBoxTimeout(true);
	});
	
	
	// Search Box
	
	var $box = $('#SearchForm input.SearchTerm');
	var text = 'Suchbegriff';
	$box.focus(function() {
		if ($box.val() == text) {
			$box.val('');
		}
		$box.addClass('Focused');
	}).blur(function() {
		$box.removeClass('Focused');
		if ($box.val() == '') {
			$box.val(text);
		}
	});
	if ($box.val() == '') {
		$box.val(text);
	}
    
    
    // Logo Slider (Footer)
    
    var currentLogo = 0;
    var $currentLogo = $('#LogoFader img');
    window.setInterval(function() {
        currentLogo++;
        var nextSrc = logosForFader[currentLogo % logosForFader.length];
        
        var img = new Image();
        img.onload = function() {
            var $newLogo = $('<img src="'+this.src+'" />');
            $newLogo.css({zIndex: 10, opacity: 0});
            $currentLogo.parent().append($newLogo);
            $currentLogo.fadeOut(function() {
                $currentLogo.remove();
                $currentLogo = $newLogo;
            });
            $newLogo.animate({opacity: 1});
        };
        img.src = nextSrc;
    }, 6000);
	
});

