/**
 * website.js
 */

var website = {
	
	init: function() {
		
		$('.lower-link a').hover(function() {
			$(this).stop().fadeTo('fast', 0.5);
		}, function() {
			$(this).stop().fadeTo('fast', 1);
		});
		
		$("a[href^='#']").click(function() {
			if( $(this).attr('href') == '#top' ) {
				$.scrollTo( $(this).attr('href'), 2000, { easing:'easeInOut' } );
			} else {
				$.scrollTo( $(this).attr('href'), 2000, { easing:'easeInOut' } );
			}
		});
		
		setInterval( "website.slideShow()", 5000 );
		
		$('.evening-link').click(function() {
			
			return false;
		});
		
		$('.swatches-link').click(function() {
			$(this).blur();
			$(this).parents('.collection-item').find('.images img:last').attr('src', $(this).attr('href') );
			return false;
		});
		
		$("a.enlarge-link").fancybox({
			'titleShow'		: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});

		/*
		$('.enlarge-link').click(function() {
			$(this).blur();
			$(this).parents('.collection-item').find('.images img:last').attr('src', $(this).attr('href') );
			return false;
		});
		*/

		$('.images img.first').click(function() {
			$(this).blur();
			$(this).parents('.images').find('.enlarge-link').trigger('click');
			return false;
		});

	}
	
	,slideShow: function() {
		if( $('.header-image a').length <= 1 ) return false;
		
		var $active = $('.header-image a.active');
	
		if ( $active.length == 0 ) $active = $('.header-image a:last');
	
		var $next =  $active.next().length ? $active.next()
			: $('.header-image a:first');
	
		$active.addClass('last-active');
	
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
	}
	
};

$(document).ready(website.init);
