$(function() {

	/**
	 * Resize Home
	 */
	var theWindow = $(window);
	jQuery.resizeHome = function() {
		if ($.browser.msie && parseInt($.browser.version) == 7) {
			$('#home-page img').css({
				'height': '8250px !important',
				'width': 'auto !important'
			});
		} else {
			$('#home-page a,#home-page img').each(function() {
				var aspectRatio = $(this).width()/$(this).height();
				if ((theWindow.width() / theWindow.height()) < aspectRatio) {
					$(this).css({height:'100% !important',width:'auto'});
				} else {
					$(this).css({height:'auto',width:'100% !important'});
				}
			});
		}
		setTimeout('jQuery.resizeHome()', 500);
	}
	if ($('#home-page').length > 0) {
		jQuery.resizeHome();
	}

	/**
	 * Home Good Time
	 */
	$('#home-good-time').click(function() {
		$('.slideshow').cycle('pause');
		$.scrollTo('850px', 1000, {
			axis:'y',
			onAfter: function() {
				$('.slideshow').cycle('resume');
			}
		});
		return false;
	});
	
	/**
	 * Slideshow
	 */
	$('.slideshow').cycle({
		timeout: 5000,
		slideResize: 0
	});

	/**
	 * Accordion
	 */
	$('.accordion').accordion({
		active: false,
		animated: 'easeInOutQuad',
		header: "> div > h3",
		autoHeight: false,
		navigation: true,
		collapsible: false,
		change: function(event, ui) {
			$.scrollTo(ui.newHeader, 500, {axis:'y'});
		}
	});
	$('.accordion > div > h3 > a').append($('<span />').addClass('arrow'));

	/**
	 * View All Wines
	 */
	$('#wines-nav').hoverIntent(function() {
		$(this).css({'background-color': '#fff'});
		$(this).find('ul').show();
	}, function() {
		$(this).css({'background-color': 'transparent'});
		$(this).find('ul').hide();
	});

	/**
	 * Footer Nav
	 */
	$('#footer-nav li').hoverIntent(function() {
		$(this).find('ul').fadeIn();
	}, function() {
		$(this).find('ul').fadeOut();
	});

	/**
	 * External
	 */
	$('a[rel="external"]').click(function() {
		$(this).attr('target', '_blank');
		return true;
	});
});
