var currentSubjectElement;
var currentAuthorElement;
var currentUserElement;

var next_enabled_img = '/assets/images/icons/next-icon.gif';
var prev_enabled_img = '/assets/images/icons/prev-icon.gif';

var next_disabled_img = '/assets/images/icons/next-icon-disabled.gif';
var prev_disabled_img = '/assets/images/icons/prev-icon-disabled.gif';

function init_random_quotes()
{
	// random subjects
	currentSubjectElement = $('random_subject_quotes').getFirst();

	// set the container to the size of the first quote
	$('random_subject_quotes').setStyle('height', currentSubjectElement.getSize().y);
	
	// disable the previous button
	$('random_subject_prev_img').setProperty('src', prev_disabled_img);

	$('random_subject_next').addEvent('click', function(){
		
		if( currentSubjectElement.getNext() )
		{
			currentSubjectElement = currentSubjectElement.getNext();
			scroll_quote( currentSubjectElement, 'random_subject_quotes', 'random_subject_prev_img', 'random_subject_next_img' );
		}
	});
	
	$('random_subject_prev').addEvent('click', function(){
		
		if( currentSubjectElement.getPrevious() )
		{
			currentSubjectElement = currentSubjectElement.getPrevious();
			scroll_quote( currentSubjectElement, 'random_subject_quotes', 'random_subject_prev_img', 'random_subject_next_img' );
		}
	});
	
	
	
	// random authors
	currentAuthorElement = $('random_author_quotes').getFirst();

	// set the container to the size of the first quote
	$('random_author_quotes').setStyle('height', currentAuthorElement.getSize().y);
	
	// disable the previous button
	$('random_author_prev_img').setProperty('src', prev_disabled_img);

	$('random_author_next').addEvent('click', function(){
		
		if( currentAuthorElement.getNext() )
		{
			currentAuthorElement = currentAuthorElement.getNext();
			scroll_quote( currentAuthorElement, 'random_author_quotes', 'random_author_prev_img', 'random_author_next_img' );
		}
	});
	
	$('random_author_prev').addEvent('click', function(){
		
		if( currentAuthorElement.getPrevious() )
		{
			currentAuthorElement = currentAuthorElement.getPrevious();
			scroll_quote( currentAuthorElement, 'random_author_quotes', 'random_author_prev_img', 'random_author_next_img' );
		}
	});
	
	
	
	// random users
	currentUserElement = $('random_user_quotes').getFirst();

	// set the container to the size of the first quote
	$('random_user_quotes').setStyle('height', currentUserElement.getSize().y);
	
	// disable the previous button
	$('random_user_prev_img').setProperty('src', prev_disabled_img);

	$('random_user_next').addEvent('click', function(){
		
		if( currentUserElement.getNext() )
		{
			currentUserElement = currentUserElement.getNext();
			scroll_quote( currentUserElement, 'random_user_quotes', 'random_user_prev_img', 'random_user_next_img' );
		}
	});
	
	$('random_user_prev').addEvent('click', function(){
		
		if( currentUserElement.getPrevious() )
		{
			currentUserElement = currentUserElement.getPrevious();
			scroll_quote( currentUserElement, 'random_user_quotes', 'random_user_prev_img', 'random_user_next_img' );
		}
	});
}

function scroll_quote( quote, container, prev_img, next_img )
{
	if( quote == $(container).getLast() )
	{
		$(next_img).setProperty('src', next_disabled_img);
		/*
		var heightChange = new Fx.Style(container, 'height', { duration: 200, onComplete: function(){
			
			var scrollChange = new Fx.Scroll(container);
			scrollChange.toElement( quote );
		}});
		heightChange.start($(container).getSize().size.y, quote.getSize().size.y);
		*/
		var scrollChange = new Fx.Scroll(container);
		scrollChange.toElement( quote );

		var heightChange = new Fx.Style(container, 'height', { onComplete: function(){
			
			var scrollChange2 = new Fx.Scroll(container, {duration: 300});
			scrollChange2.toElement( quote );
		}});
		heightChange.start($(container).getSize().y, quote.getSize().y);
	}
	else
	{
		$(next_img).setProperty('src', next_enabled_img);
		var scrollChange = new Fx.Scroll(container);
		scrollChange.toElement( quote );

		var heightChange = new Fx.Style(container, 'height');
		heightChange.start($(container).getSize().y, quote.getSize().y);
	}
	
	if( quote == $(container).getFirst() )
	{
		$(prev_img).setProperty('src', prev_disabled_img);
	}
	else
	{
		$(prev_img).setProperty('src', prev_enabled_img);	
	}
}

window.addEvent('domready', init_random_quotes );