$j(document).ready(function() {

	//featured wines - update the margin-top on the image to make each item the same height.
	featured_wines_content_height = 0;
	$j('div#featured-wines div.record div.content').each(function() {
		if ($j(this).height() > featured_wines_content_height) featured_wines_content_height = $j(this).height();
	});
	$j('div#featured-wines div.record div.content').each(function() {
		if ($j(this).height() < featured_wines_content_height) {
			$j(this).find('img').css({'margin-top': featured_wines_content_height - parseInt($j(this).height())});
		}
	});

	//featured wines - update height of grey panel with a min-height of 77px
	featured_wines_desc_height = 66;
	$j('div#featured-wines div.record div.desc').each(function() {
		if ($j(this).height() > featured_wines_desc_height) featured_wines_desc_height = $j(this).height();
	});
	if (featured_wines_desc_height > 66) featured_wines_desc_height = featured_wines_desc_height + 10;
	$j('div#featured-wines div.record div.desc').css({'height': featured_wines_desc_height});

	//featured wines - work out mask height & div#featured-wines width.
	featured_wines_mask_height = 1;
	featured_wines_records = 0;
	$j('div#featured-wines div.record').each(function() {
		if ($j(this).height() > featured_wines_mask_height) featured_wines_mask_height = $j(this).height();
		featured_wines_records++;
	});
	if (featured_wines_records <= 4) {
		$j('div#featured-wines-previous-arrow').css({'display': 'none'});
		$j('div#featured-wines-next-arrow').css({'display': 'none'});
	}
	$j('div#featured-wines-mask').css({
		'height': featured_wines_mask_height+20,
		'overflow': 'hidden',
		'width': 885,
		'position': 'relative',
		'margin': 'auto'
	});

	var featured_wines_records_width = featured_wines_records * (parseInt($j('div#featured-wines>div.record').width()) + parseInt($j('div#featured-wines>div.record').css('margin-right')));
	$j('div#featured-wines').css({'width': featured_wines_records_width});


	var featured_wines_scroller_animating = false;
	$j('div#featured-wines-next-arrow a').click(function(event) {
		event.preventDefault();

		if (!featured_wines_scroller_animating) {


			var new_x = parseInt($j('div#featured-wines').css('margin-left')) - (parseInt($j('div#featured-wines>div.record').width()) + parseInt($j('div#featured-wines>div.record').css('margin-right')));
			if (new_x < ($j('div#featured-wines').width() - visible_width)) new_x = ($j('div#featured-wines').width() - visible_width);

			var visible_width = ((parseInt($j('div#featured-wines>div.record').width()) + parseInt($j('div#featured-wines>div.record').css('margin-right'))) * 4);

			if (new_x >= -($j('div#featured-wines').width() - visible_width)) {
				featured_wines_scroller_animating = true;
				$j('div#featured-wines').animate({
					marginLeft: new_x
				}, {
					'duration': 800,
					'easing': 'easeInOutExpo',
					'queue': true,
					'complete': function() { featured_wines_scroller_animating = false; }
				});
			}
		}
	});


	$j('div#featured-wines-previous-arrow a').click(function(event) {
		event.preventDefault();

		if (!featured_wines_scroller_animating) {

			var new_x = parseInt($j('div#featured-wines').css('margin-left')) + (parseInt($j('div#featured-wines>div.record').width()) + parseInt($j('div#featured-wines>div.record').css('margin-right')));
			if (new_x > 0) new_x = 0;
			if (new_x <= 0) {
				featured_wines_scroller_animating = true;
				$j('div#featured-wines').animate({
					marginLeft: new_x
				}, {
					'duration': 800,
					'easing': 'easeInOutExpo',
					'queue': true,
					'complete': function() { featured_wines_scroller_animating = false; }
				});
			}
		}
	});







});

