var jq = jQuery.noConflict();

jq(document).ready(function() {
	initNewsLink();
	initTsrNewsFader();
});

// remove the link from the news header and place it to the bottom of the teaserbox
function initNewsLink(){

	if(jq('div.news-list-container').length > 0){
		
		var text = jq('div.news-list-container').prev().find('a').text();
		var link = jq('div.news-list-container').prev().find('a').attr('href');
		jq('div.news-link').append('<a href="'+link+'">>alle News</a>');
	}
}


arTsrNewsFade = new Array();
function initTsrNewsFader() {

	if (jq('.tsrBrd2').length > 0) {

		var iCnt = 1;
		jq('.tsrBrd2').each(function() {

			jq(this).attr('id', 'tsrnews' + iCnt);
			iCnt++;

			arTsrNewsFade[jq(this).attr('id')] = 0;
			jq(this).find('.news-latest-item:eq(0)').css('display', 'block');
		});

		var timer = setInterval(fadeTsrNews, 5000);
	}
}

function fadeTsrNews() {

	jq('.tsrBrd2').each(function() {

		if (jq(this).find('.news-latest-item').length > 1) {

			jq(this).find('.news-latest-item').css('display', 'none');

			var newIdx = arTsrNewsFade[jq(this).attr('id')] + 1;
			if (newIdx == jq(this).find('.news-latest-item').length) {
				arTsrNewsFade[jq(this).attr('id')] = 0;
			}
			else {
				arTsrNewsFade[jq(this).attr('id')] = newIdx;
			}

			jq(this).find('.news-latest-item:eq(' + arTsrNewsFade[jq(this).attr('id')] + ')').fadeIn();
		}
	});
}

