var collection;
var index = 0;
var dir = 'fw';

document.observe('dom:loaded',function()
{
	collection = $$('li.hp_photo');
	if(collection.length > 1)
	{
		$$('#hp_gallery img.blur').each(function(el){
//			Pixastic.process(el, "blurfast", {amount:0.5});
		});
		collection.each(function(el)
		{
			el.setStyle('display: none');
//			el.down('span.hp_desc').setStyle('display: none');
			el.down('img').observe('mouseover',function()
			{
				el.down('span.hp_desc').toggle();
			});
			el.down('img').observe('mouseout',function()
			{
				el.down('span.hp_desc').toggle();
			});
		});
		executor = new PeriodicalExecuter(__rotate,4);
		collection.first().setStyle('display: inline');
	}
	
	$('hp_back').observe('click',function(ev)
	{
		ev.stop();
		executor.stop();
		dir = 'rw';
		__rotate();
		dir = 'fw';
		executor = new PeriodicalExecuter(__rotate,4);
	});

	$('hp_next').observe('click',function(ev)
	{
		ev.stop();
		executor.stop();
		dir = 'fw';
		__rotate();
		executor = new PeriodicalExecuter(__rotate,4);
	});

	$('hp_stop').observe('click',function(ev)
	{
		ev.stop();
		executor.stop();
	});
});

function __rotate()
{
	Effect.Fade(collection[index], { duration: 1 } );
	if(dir == 'fw')
	{
		if(index == collection.length - 1) index = 0; else index++;
	}
	else
	{
		if(index == 0) index = collection.length - 1; else index--;
	}
	Effect.Appear(collection[index], { duration: 1 } );
}
