
var topNewsItems = new Array();
var topNewsItemsAuto = new Array();
var left;
var autoClick;
var temp;

jQuery(document).ready(function (){
	
	
	left = 0;
	jQuery('#top-news .mod_newslist .main_news_item').each(function() {
		topNewsItems[jQuery(this).attr('data-newsid')] = left;
		topNewsItemsAuto.push(jQuery(this).attr('data-newsid'));
		left = left - 640;
	});
	
	jQuery('#top-news-preview .mod_newslist .smallimg:first').addClass('active');
	jQuery('#top-news-preview .mod_newslist .smallimg').click(function() {
		
		if(jQuery(this).hasClass('active')) {
			return true;
		}
		window.clearInterval(autoClick);
		jQuery('#top-news .main_news_top').stop();
		jQuery('#top-news .main_news_top').animate({marginLeft: topNewsItems[jQuery(this).attr('data-newsid')]},1000);
		jQuery('#top-news-preview .mod_newslist .smallimg').removeClass('active');
		jQuery(this).addClass('active');
		
		return false;
		
	});
	
	autoClick = window.setInterval("autoPlay()", 7500);
	
	$("div.fancybox a:not(.nofancy), .fancybox table td a:not(.nofancy), ul.fancybox a:not(.nofancy)").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200,
		'overlayColor'  :   '#000',
		'overlayOpacity':   0.5
	});
	
	jQuery('iframe').each(function() {
		var url = jQuery(this).prop("src");
		jQuery(this).prop("src",url+"?wmode=transparent");
	});
	
	jQuery('.jugend_spielplan table tr').each(function() {
		if(jQuery(this).find('.col_2').html()!='ESV Kaufbeuren' && jQuery(this).find('.col_3').html()!='ESV Kaufbeuren') {
			jQuery(this).hide();
		}
	});

});

function autoPlay() {
	temp = topNewsItemsAuto.shift();
	jQuery('#top-news .main_news_top').stop();
	jQuery('#top-news .main_news_top').animate({marginLeft: topNewsItems[temp]},1000);
	jQuery('#top-news-preview .mod_newslist .smallimg').removeClass('active');
	jQuery('#top-news-preview .mod_newslist .smallimg_'+temp).addClass('active');
	topNewsItemsAuto.push(temp);
}
