var g_lastPhotoGallery = null;

window.addEvent("domready", function()
{
	var photoSetWidth = 578;	
	var photoSets = $('scrollingThumbnails').getElementsBySelector('.photoSet');
	$('scrollingThumbnails').setStyle('width', (photoSetWidth*photoSets.length)+'px');
	
	var scroll = new Fx.Scroll('photoThumbnails', 
	{
		wait: false,
		duration: 1000,
		transition: Fx.Transitions.Quad.easeInOut
	});
	
	$$('#photoMenu li').each(function(item, index)
	{
		var indexF = new String(index<10?'0'+(index+1):(index+1));
		item.opened = false;
		if (!index)
		{
			item.opened = true;
			item.setStyles({"background":"#5f5f5f", "color":"#ffffff"});
			g_lastPhotoGallery = item;
			scroll.scrollTo(0);
		}
		
		item.addEvent("mouseover", function(e)
		{
			if (!item.opened)
			{
				item.setStyles({"background":"#5f5f5f", "color":"#ffffff"});
			}
		});
		
		item.addEvent("mouseout", function(e)
		{
			if (!item.opened)
			{
				item.setStyles({"background":"#4d4d4d", "color":"#ffffff"});
			}
		});
		
		item.addEvent("click", function(event)
		{
			event = new Event(event).stop();
			
			scroll.scrollTo(index*photoSetWidth);
			
			if (g_lastPhotoGallery==item)
			{
				item.setStyles({"background":"#5f5f5f", "color":"#ffffff"});
				item.opened = true;
			}
			else
			{
				if (!item.opened)
				{
					item.setStyles({"background":"#5f5f5f", "color":"#ffffff"});
					item.opened = true;
					
					if (g_lastPhotoGallery)
					{
						g_lastPhotoGallery.setStyles({"background":"#4d4d4d", "color":"#ffffff"});
						g_lastPhotoGallery.opened = false;
					}
				}
			}
			
			g_lastPhotoGallery = item;
		});
	});
});