var homeHeadlinePosition = 2;
var homeHeadlineTimer;
var homeHeadlineAutoTimer;

function homeHeadlineAuto() {
	var moveTo
	var el = document.getElementById('articleList').getElementsByTagName('li');
	for (i=0; i<el.length; i++)
		if (el[i].className == 'active') moveTo = i+1;
	if (moveTo >= el.length) moveTo = 0;
	homeHeadlineHover(el[moveTo]);
}
function homeHeadlineHover(active) {
	clearTimeout(homeHeadlineTimer);
	clearTimeout(homeHeadlineAutoTimer);
	homeHeadlineAutoTimer = setInterval('homeHeadlineAuto()',4000);
	var listLeft = active.parentNode.parentNode.getElementsByTagName('ul')[0].getElementsByTagName('li');
	var listRight = active.parentNode.getElementsByTagName('li');
	for(i=0; i<listRight.length; i++) {
		if (listRight[i] == active) {
			listRight[i].className = 'active';
			listLeft[i].className = 'active';
			homeNewsActiveChange(i*40+2);
		} else {
			listRight[i].className = '';
			listLeft[i].className = '';
		}
	}
}
function homeNewsChange(active) {
	var listTabs = document.getElementById('tabs').getElementsByTagName('li');
	var listDisp = document.getElementById('contentBody').getElementsByTagName('ul');
	for(i=0; i<listTabs.length; i++) {
		if (listTabs[i] == active) {
			listTabs[i].className = 'active';
			listDisp[i].className = 'newsWide active';
		} else {
			listTabs[i].className = '';
			listDisp[i].className = 'newsWide';
		}
	}
}
function homeNewsActiveChange(c) {
	var a = homeHeadlinePosition;
	var b = Math.round((c-a)/5);
	homeNewsActiveMove(a,b,c);
}
function homeNewsActiveMove(a,b,c) {
	if ((a<c && a+b>=c) || (a>c && a+b<=c)) a = c;
	else a += b; homeHeadlinePosition = a;
	document.getElementById('articleList').style.backgroundPosition = '0px ' + a + 'px';
	if(a != c) homeHeadlineTimer = setTimeout('homeNewsActiveMove('+a+','+b+','+c+')',20);
}

function scoresMonthChange(current,change) {
	var number;
	var container = current.parentNode;
	var month = container.getElementsByTagName('li');
	for (i=0; i<month.length; i++) {
		if (month[i] == current) number = i;
		month[i].className = '';
	}
	number += change;
	if (number < 0) number = 0;
	if (number > month.length - 1) number = month.length - 1;
	container.getElementsByTagName('li')[number].className = 'active';
}
function scoresDaySlide(container,direction) {
	if (container.getElementsByTagName('a').length > 12) {
		var change = direction * 3 * 51;
		var parentWidth = container.parentNode.offsetWidth;
		var width = container.offsetWidth;
		var position = container.offsetLeft;
		var newPosition = position + change;
		if (newPosition > 0) newPosition = 0;
		else if (width + newPosition < parentWidth) newPosition = (width - parentWidth) * -1;
		if (position != newPosition)
			scoresDaySlideGo(container,newPosition,direction);
	}
}
function scoresDaySlideGo(container,newPosition,direction) {
	var movePosition = container.offsetLeft + direction * 5;
	if (direction < 0 && movePosition < newPosition ) movePosition = newPosition;
	if (direction > 0 && movePosition > newPosition ) movePosition = newPosition;
	container.style.left = movePosition + 'px';
	if(movePosition != newPosition)
		setTimeout(function() {scoresDaySlideGo(container,newPosition,direction)},10);
}

//Admin

function deleteRankingConfirm(id) {
	var response = confirm('Are you should you want to delete this?');
	if(response) window.location = 'script_deleteRanking.php?id=' + id;
}
function recalcRankingConfirm(id) {
	var response = confirm('Are you should you want to recalculate this?');
	if(response) window.location = 'script_compileRankings.php?id=' + id;
}
function articleEditExternalToggle(box) {
	if (box.checked) {
		document.getElementById('body').style.display = 'none';
		document.getElementById('bodyh5').style.display = 'none';
	} else {
		document.getElementById('body').style.display = 'inline-block';
		document.getElementById('bodyh5').style.display = 'block';
	}
}
function ajaxAction(url) {
	if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();
	else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
}