//Declarations of some variables
var scroll;
var childCount;
var ids;
var id;
var childs;

function begin()
{
	childCount = $('posts').getElements('div');   
	ids = childCount.get('id');
	childs = childCount.length -1;
    if (childCount.length > 1)
    {
        scroll = new Fx.Scroll('cites_container', {wheelStops: false, duration: 500, transition: Fx.Transitions.Quad.easeInOut }); 
			$$('.next').addEvent('click', function(e) {
				e.stop();
				toNext();
			})
			$$('.prev').addEvent('click', function(e) {
				e.stop();
				toPrev();
			})	
			scroll.toElement($$('#posts .active')[0]);
	}

}

function toNext()
{
	var active = $($('posts').getElement('.active').get('id'));
	id = ids.indexOf(active.get('id'));
	if (id < childs) id++; else id = 0;
	target = $('cite_'+id);
	active.removeClass('active');
	scroll.toElement(target);
	target.addClass('active');
}

function toPrev()
{
    var active = $($('posts').getElement('.active').get('id'));
	id = ids.indexOf(active.get('id'));
	if (id < childs && id > 0) id--; else id = 0;
	target = $('cite_'+id);
	active.removeClass('active');
	scroll.toElement(target);
	target.addClass('active');
}

window.addEvent('domready', begin);