var loginLang = new Array(), currentTopNews = -1, topNewsTimeout, allNewsBanners;
loginLang['ws_user'] = "Benutzername";
loginLang['pwd'] = "Passwort";

var RecaptchaOptions = {
   theme : 'white',
   tabindex : 2
};

function rotateBanner() {
	if(!allBanners.length) return;
	currentBanner++
	if(currentBanner >= allBanners.length) currentBanner = 0;
	
	$("#bAdsRot").attr('href', 'out.php?bannerID='+allBanners[currentBanner][0]);
	$("#bAdsRot img").attr('src', 'images/bannerrotation/'+allBanners[currentBanner][1]);
	$("#bAdsRot img").attr('alt', allBanners[currentBanner][2]);
}
function rotateNewsBanner() {
	if(!allNewsBanners.length) return;
	currentNewsBanner++
	if(currentNewsBanner >= allNewsBanners.length) currentNewsBanner = 0;
	
	$("#bAdsNewsRot").attr('href', 'out.php?bannerID='+allNewsBanners[currentNewsBanner][0]);
	$("#bAdsNewsRot img").fadeTo('normal', 0, function() {
		$("#bAdsNewsRot img").attr('src', 'images/bannerrotation/'+allNewsBanners[currentNewsBanner][1]);
		$("#bAdsNewsRot img").attr('alt', allNewsBanners[currentNewsBanner][2]);
		$("#bAdsNewsRot img").fadeTo('normal', 1);
		setTimeout("rotateNewsBanner();", 10000);
	});
	new Image().src = 'images/bannerrotation/'+allNewsBanners[currentNewsBanner][1];
}
function displayTopNews(i) {
	clearTimeout(topNewsTimeout);
	if(i == 'n') {
		if($("#topNews .n"+(currentTopNews+1)).length) {
			i = currentTopNews + 1;
		}
		else {
			i = 0;
		}
		topNewsTimeout = setTimeout("displayTopNews('n');", 5000);
	}
	
	$("#topNews .tNews.n"+currentTopNews).removeClass('active');
	$("#topNews .tNews.n"+i).addClass('active');
	currentTopNews = i;
	$("#topActive").fadeOut(function() {
		$("#topActive .tPic").attr("src", topNews[i]["pic"]);
		$("#topActive .subheadline").text(topNews[i]['subheadline']);
		$("#topActive .headline").text(topNews[i]['headline']);
		//$("#topActive .vhr").attr("class", 'vhr n'+i);
		$("#topActive .content").html(topNews[i]["content"]);
		$("#topActive").fadeIn();
	});
}
var headboxTimeout, activeBox = 0;
function headboxRotation(i) {
	clearTimeout(headboxTimeout);
	if(i == 'a') {
		if(activeBox) {
			activeBox = 0; 
		}
		else {
			activeBox = 1;
		}
		headboxTimeout = setTimeout("headboxRotation('a');", 9000);
	}
	else {
		if(activeBox == i) return;
		activeBox = i;
	}
	if(activeBox == 1) rotateBanner();
	
	var activeA = $("#bTabs > a").get(activeBox);
	var newActive = $(activeA).attr('href');
	if($(newActive).css('display') != 'block') {
		$("#bTabs > div").fadeOut();
		setTimeout('$("'+newActive+'").fadeIn();', 410);
	}
	$("#bTabs a").removeClass('active');
	$(activeA).addClass('active');
}

$(document).ready(function(){
	headboxTimeout = setTimeout("headboxRotation('a');", 9000);
    $("a#topLink").click(function(event){
        $('html, body').animate({
            scrollTop: 0
        }, 'slow');
        event.preventDefault();
    });
	$("#login input").bind("focus", function(event){
		if($(this).val() == loginLang['ws_user'] || $(this).val() == loginLang['pwd'])
		{
			$(this).val("");
		}
	});
	$("#login input").bind("blur", function(event){
		if($(this).val() == "")
		{
			$(this).val(loginLang[$(this).attr('name')]);
		}
	});
	
	$("#bTabs a:eq(0)").click(function(event) {
		event.preventDefault();
		headboxRotation(0);
	});
	$("#bTabs a:eq(1)").click(function(event) {
		event.preventDefault();
		headboxRotation(1);
	});
	
	$("#n"+$("#navigation a.selected").text()).show();
	$("#navigation a").mouseover(function() {
		$(".subNavi").hide();
		$("#navigation a").removeClass('selected');
		$(this).addClass('selected');
		$("#n"+$(this).text()).show();
	});
	
	displayTopNews('n');
	$("#topNews .tNews").click(function() {
		displayTopNews($(this).attr('class').replace('tNews n', '').replace(' active', ''));
	});
	$("#topActive").live('click', function() {
		window.location = $("#topActive .content a").attr('href');
	});
	
	$("#loginForm").keyup(function(e) {
		if(e.which == 13) {
			$("#loginForm").submit();
		}
	});
	
	$(".content.shorten").each(function() {
		if($(this).height() > 117) {
			$(this).height(117);
		}
		else {
			$(this).find("a.more").hide();
		}
	});
	
	if(allNewsBanners != undefined) {
		setTimeout("rotateNewsBanner();", 10000);
		new Image().src = 'images/bannerrotation/'+allNewsBanners[currentNewsBanner][1];
	}
});
