;(function($) {
	$.fn.ribbon = function() {
		return this.each(function() {
			$('.thumb  img').hover(function() { 
				var id = $(this).closest('div .ribbon').attr('id').split('_')[1];
				
				$(this)
					.stop(true)
					.css('z-index', 10)
					.animate({ height: '200px' }, { duration: 'slow', easing: 'swing', complete: function() {  }, queue: false });	
					
					var sel_td = $(this).closest('td:parent'); 
					var sel_col = $(sel_td).parent().children().index($(sel_td)) + 1;
					
					$('#ribbon_'+id+' table tr:last td:nth-child('+sel_col+')').children('.panel').addClass('show');
					var panel_padding = parseInt($('.show').css('paddingLeft'));
					var panel_border = parseInt($('.show').css('borderLeftWidth'));
	
					var full_height = 200;
					var img_width =$(this).width();
					var img_height =$(this).height();
					var full_width = Math.floor( full_height * img_width / img_height - 2*(panel_padding + panel_border));

				$('#ribbon_'+id+' table tr:last td:nth-child('+sel_col+')').children('div')
					.stop(true)
					//.css('z-index', 10)
					.animate({ width: full_width + 'px', height: '100%' }, { duration: 'slow', easing: 'swing', complete: function() { }, queue: false });	

			}, function() {
				var id = $(this).closest('div .ribbon').attr('id').split('_')[1];

				$(this)
					.stop(true)
					
					.animate({ height: '80px' }, { duration: 'slow', easing: 'swing', complete: function() { $(this).css('z-index', 1);  }, queue: false });	
	
					var sel_td = $(this).closest('td:parent');
					var sel_col = $(sel_td).parent().children().index($(sel_td)) + 1;
					//var sel_rows = $('#ribbon_'+id+' table tr').siblings();

				$('#ribbon_'+id+' table tr:last td:nth-child('+sel_col+')').children('div')
					.stop(true)
					.animate({ height: '0px', width: '80px' }, { duration: 'slow', easing: 'swing', complete: function() { 
						$('#ribbon_'+id+' table tr:last td:nth-child('+sel_col+')').children('.panel').removeClass('show');
						//$(this).css('z-index', 1);
						}, queue: false });	

			});
		});
	}
})(jQuery);

