$(document).ready(function() {
	
	//featured wines - update the margin-top on the image to make each item the same height.
	featured_wines_content_height = 0;
	$('div#featured-wines div.record div.content').each(function() {
		if ($(this).height() > featured_wines_content_height) featured_wines_content_height = $(this).height();
	});
	$('div#featured-wines div.record div.content').each(function() {
		if ($(this).height() < featured_wines_content_height) {
			$(this).find('img').css({'margin-top': featured_wines_content_height - parseInt($(this).height())});
		}
	});
	
	//featured wines - update height of grey panel with a min-height of 77px
	featured_wines_desc_height = 66;
	$('div#featured-wines div.record div.desc').each(function() {
		if ($(this).height() > featured_wines_desc_height) featured_wines_desc_height = $(this).height();
	});
	if (featured_wines_desc_height > 66) featured_wines_desc_height = featured_wines_desc_height + 10;
	$('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;
	$('div#featured-wines div.record').each(function() {
		if ($(this).height() > featured_wines_mask_height) featured_wines_mask_height = $(this).height();
		featured_wines_records++;
	});
	$('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($('div#featured-wines>div.record').width()) + parseInt($('div#featured-wines>div.record').css('margin-right')));
	$('div#featured-wines').css({'width': featured_wines_records_width});
	
	
	var featured_wines_scroller_animating = false;
	$('div#featured-wines-next-arrow a').click(function(event) {
		event.preventDefault();		
		
		if (!featured_wines_scroller_animating) {
			
		
			var new_x = parseInt($('div#featured-wines').css('margin-left')) - (parseInt($('div#featured-wines>div.record').width()) + parseInt($('div#featured-wines>div.record').css('margin-right')));
			if (new_x < ($('div#featured-wines').width() - visible_width)) new_x = ($('div#featured-wines').width() - visible_width);
			
			var visible_width = ((parseInt($('div#featured-wines>div.record').width()) + parseInt($('div#featured-wines>div.record').css('margin-right'))) * 4);
			
			if (new_x >= -($('div#featured-wines').width() - visible_width)) {
				featured_wines_scroller_animating = true;
				$('div#featured-wines').animate({
					marginLeft: new_x
				}, {
					'duration': 800,
					'easing': 'easeInOutExpo',
					'queue': true,
					'complete': function() { featured_wines_scroller_animating = false; }
				});
			}
		}
	});


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







});


