// Javascript for the article page

function size(id,fontsize,textalign) {
	if ( document.getElementById(id) ) {
		document.getElementById(id).style.fontSize  = fontsize + 'px';
		document.getElementById(id).style.textAlign = textalign;
	}
}
function size1() {
	size('article',12,'justify');
	size('thumbnail',10,'left');
	setCookie('articlesize',1,7);
}
function size2() {
	size('article',16,'left');
	size('thumbnail',12,'left');
	setCookie('articlesize',2,7);
}
function size3() {
	size('article',18,'left');
	size('thumbnail',16,'left');
	setCookie('articlesize',3,7);
}

function initialize_article() {
	if ( getCookie('articlesize') != '' ) {
		var size = getCookie('articlesize');
		if ( size == 3 ) {
			size3();
		}
		else if ( size == 2 ) {
			size2();
		}
		else {
			size1();
		}
	}
}

function hide(id) {
	if ( document.getElementById(id) ) {
		document.getElementById(id).style.display = 'none';
	}
}
function show(id) {
	if ( document.getElementById(id) ) {
		document.getElementById(id).style.display = 'block';
	}
}
function hide_all(arr) {
	for ( i = 0 ; i < arr.length ; i++ ) {
		hide('summary_'+arr[i]);
	}
}
function switchto(id) {
	currentArticle = id;
	hide_all(guids);
	show('summary_'+id);
}
function next() {
	for ( i = 0 ; i < guids.length ; i++ ) {
		if ( guids[i] == currentArticle ) {
			if ( i >= guids.length - 1 ) {
				switchto(guids[0]);
			}
			else {
				switchto(guids[i+1]);
			}
			if ( rotation != -1 ) {
				pause();
				play();
			}
		}
	}
	renumber_article();
}
function pause() {
	clearInterval(rotation);
	rotation = -1;
	hide('pause');
	show('play');
}
function play() {
	rotation = setInterval('next();',10000);
	hide('play');
	show('pause');
}
function previous() {
	for ( i = 0 ; i < guids.length ; i++ ) {
		if ( guids[i] == currentArticle ) {
			if ( i == 0 ) {
				switchto(guids[guids.length-1]);
			}
			else {
				switchto(guids[i-1]);
			}
			if ( rotation != -1 ) {
				pause();
				play();
			}
		}
	}
	renumber_article();
}
function renumber_article() {
	if  ( document.getElementById('article_numbering') ) {
		for ( i = 0 ; i < guids.length ; i++ ) {
			if ( guids[i] == currentArticle ) {
				document.getElementById('article_numbering').innerHTML = (i+1) + '/' + guids.length;
			}
		}
	}
}

// Code taken from w3schools.com
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}


