(function($){
	$.fn.slideShow = function(options){
		var settings = $.extend({
			interval: 5000
		}, options);
		
		$(this).each(function(){
			var imageContainer = $(this).find('.image'), 
					image = imageContainer.find('img'),
					thumbs = $(this).find('.thumb a'),
					currentIndex = 0;

			$(thumbs).each(function(i){
				var fullImage = $(image).clone().attr('src', $(this).attr('href'));

				$(this).click(function(){
					currentIndex = i;
					
					imageContainer.fadeOut('fast', function(){
						imageContainer.html(fullImage);
					}).fadeIn();
					
					thumbs.children().mouseleave();
					
					$(this).children().mouseenter();
					
					return false;
				});
			});
			
			var updateImage = function(){
				var nextIndex;
				
				if(currentIndex < (thumbs.length - 1)){
					nextIndex = currentIndex + 1;
					currentIndex = nextIndex;
				} else {
					nextIndex = 0;
					currentIndex = 0;
				}
				
				$(thumbs[nextIndex]).click();
			};
			
			if(thumbs.length > 1){
				var periodicUpdater = setInterval(updateImage, settings.interval);
			}
		});
	},
	
	$.fn.hoverFade = function(options){
		var settings = $.extend({
			to: 1,
			from: 0.75,
			duration: 200
		}, options);
		
		$(this).each(function(){
			$(this).css('opacity', settings.from);
		});
		
		$(this).mouseenter(function(){
			$(this).animate({
				opacity: settings.to
			}, settings.duration);
		}).mouseleave(function(){
			$(this).animate({
				opacity: settings.from
			}, settings.duration);
		});
	},
	
	$.fn.subNavigation = function(){
		$(this).each(function(){
			$(this).mouseenter(function(){
				$(this).addClass('hover');
			}).mouseleave(function(){
				$(this).removeClass('hover');
			});
		});
	}
})(jQuery);

$(function(){
	$('.slideshow').slideShow();
	
	$('.image a img').hoverFade();
	
	$('.thumb a img').hoverFade({
		from: 0.5
	});
	
	$('#headerNavigation > li').subNavigation();
	
	if($.browser.msie == false){
		$('#headerNavigation > li').hoverFade({
			from: 0.5,
			duration: 300
		});
	}
});