// Miscellaneous stuff.
$(function()
{
	$.localScroll({ duration: 'slow' });
	$('#footer .back-to-top').css('opacity', 0.5).hover(function()
	{
		$(this).stop().fadeTo('fast', 1);
	}, function()
	{
		$(this).stop().fadeTo('fast', 0.5);
	});
});

// Top rota.
$(function()
{
	var rota = $('#rota-image-list');
	var rotaPreviousLink = $('#rota-previous a');
	var rotaNextLink = $('#rota-next a');
	var rotaNavigation = $('<ul id="rota-navigation" />').appendTo(rota.parent());
	var items = rota.children();
	
	items.each(function(index)
	{
		var item = $('<li />').appendTo(rotaNavigation);
		var link = $('<a href="#" />').appendTo(item);
		link.text($(this).find('img').attr('alt'));
		link.click(function()
		{
			rota.slideToItem(index);
			updateRotaInterface();
			return false;
		});
	});
	
	rota.slideWindow({ vertical: false, slideSpeed: 'slow' });
	rotaPreviousLink.click(function()
	{
		rota.slidePrevious();
		updateRotaInterface();
		return false;
	});
	rotaNextLink.click(function()
	{
		rota.slideNext();
		updateRotaInterface();
		return false;
	});
	
	updateRotaInterface(true);
	
	function updateRotaInterface(doNotAnimate)
	{
		var index = items.index(rota.currentItem());
		var item = rotaNavigation.children().eq(index);
		
		//item.stop().addClass('current', 1000);
		//item.siblings().stop().removeClass('current', 'fast');
		if (doNotAnimate)
		{
			item.find('a').css({ 'color': '#fff' });
			item.siblings().find('a').css({ 'color': '#c3bdb7' });
		}
		else
		{
			item.find('a').stop().animate({ 'color': '#fff' });
			item.siblings().find('a').stop().animate({ 'color': '#c3bdb7' });
		}
		
		if (!($.browser.msie)) {
		if (index === 0)
		{
			//rotaPreviousLink.addClass('disabled');
			rotaPreviousLink.css('cursor', 'default')
			if (doNotAnimate)
			{
				rotaPreviousLink.css('opacity', 0.5);
			}
			else
			{
				rotaPreviousLink.fadeTo('medium', 0.5);
			}
		}
		else
		{
			//rotaPreviousLink.removeClass('disabled');
			rotaPreviousLink.css('cursor', 'pointer').fadeTo('fast', 1);
			if (doNotAnimate)
			{
				rotaPreviousLink.css('opacity', 1);
			}
			else
			{
				rotaPreviousLink.stop().fadeTo('medium', 1);
			}
		}
		
		
		if (index === items.length - 1)
		{
			//rotaNextLink.addClass('disabled');
			rotaNextLink.css('cursor', 'default').fadeTo('fast', 0.5);
			if (doNotAnimate)
			{
				rotaNextLink.css('opacity', 0.5);
			}
			else
			{
				rotaNextLink.stop().fadeTo('medium', 0.5);
			}
		}
		else
		{
			//rotaNextLink.removeClass('disabled');
			rotaNextLink.css('cursor', 'pointer').fadeTo('fast', 1);
			if (doNotAnimate)
			{
				rotaNextLink.css('opacity', 1);
			}
			else
			{
				rotaNextLink.stop().fadeTo('medium', 1);
			}
		}
		}
	}
});

// Thumbnails.
$(function()
{
	var thumbnailItems = $('#thumbnails').children();
	thumbnailItems.each(function()
	{
		$(this).find('a').hover(function()
		{
			//$(this).parent().addClass('active', 'fast');
			$(this).find('.overlay').stop().animate({ 'right': '0px' }, 'fast');
		}, function()
		{
			//$(this).parent().removeClass('active', 'fast');
			$(this).find('.overlay').stop().animate({ 'right': '20px' }, 'fast');
		});
	});
});
