var timer
$(document).ready( function() {
	if ($('#frontnews').length) {
		$('#frontnews div.thumbs article:first-child').addClass('active')
		$('#frontnews div.slider article:first-child').addClass('active').siblings('article').css('top',439)
		timer = setInterval(frontnews_next,6000)
	} else if ($('#leaguenews').length) {
		timer = setInterval(leaguenews_next,6000)
	}
	if ($('table.standingssmall')) {
		$('table.standingssmall:odd').addClass('even')
	}
	$('.stripe>*:odd, ul.scores>li:odd').addClass('even')
	$('section.top table.standingssmall:odd').addClass('even')
	$('aside.bottom h1').each( function() {
		$(this).css('top',(80 - $(this).height())/2)
	})
})
function frontnews_activate(el) {
	clearInterval(timer)
	$(el).addClass('active').siblings().removeClass('active')
	$('#frontnews div.thumbs').get(0).style.backgroundPosition = '0px '+(-28 * $(el).index())+'px'
	$('#frontnews div.slider article').eq($(el).index())
	var old = $('#frontnews div.slider article.active')
	var active = $('#frontnews div.slider article').eq($(el).index())
	if (!active.hasClass('active')) {
		active.css({top:-70,opacity:1}).animate({top:0},300)
		old.animate({top:439, opacity:0},400, function() { active.addClass('active'); old.removeClass('active') })
	}
	timer = setInterval(frontnews_next,6000)
}
function frontnews_next() {
	var index = $('#frontnews div.thumbs article.active').index() + 1
	if (index == 6) index = 0
	$('#frontnews div.thumbs article').eq(index).click()
}

function news_filter(lg,q) {
	$('#news').load('/dev/ajax/news_filter.php?lg='+lg+'&q='+q)
}

function gamecenter(dir) {
	var scroller = $('#gamecenter')
	var scrollTo = scroller.scrollLeft() + dir * 85
	scroller.animate({scrollLeft: scrollTo}, 200);
}

function scores(dir) {
	var scroller = $('#scores .slider')
	var scrollTo = scroller.scrollLeft() + dir * 924
	scroller.animate({scrollLeft: scrollTo}, 600);
}

function leaguenews(el) {
	clearInterval(timer)
	var scrollTo = $(el).index() * 640
	$(el).addClass('active').siblings().removeClass('active')
	$('#leaguenews div.articles').animate({scrollLeft: scrollTo},400)
	timer = setInterval(leaguenews_next,6000)
}
function leaguenews_next(){
	var index = $('#leaguenews ul.thumbs li.active').index() + 1
	if (index == 6) index = 0
	$('#leaguenews ul.thumbs li').eq(index).click()
}

