(function($) {
	
	$.fn.extend({
		
		ratingChart: function(options) {
			
			var defaults = {
			};
			
			options = $.extend(defaults, options);
			
			return this.each(function() {
				
				this.m_oOptions = options;
				this.m_jH = $(this).find('h4:first');
				this.m_jDl = $(this).find('dl:first');
				this.m_jList = $(this).find('.group-choice ul');
				
				var dChart = this;
				
				this.Animate = function() {
					dChart.m_jDl.find('.rating-indicator span').each(function(i) {
						var iWidth = $(this).css('width');
						$(this).css('width', 0).delay(i * 100).animate({
							width: iWidth
						}, 350);
					});
				};
				
				this.ShowSummary = function(i) {
					dChart.m_jList.find('li').removeClass('active');
					dChart.m_jList.find('li:eq(' + i + ')').addClass('active');
					var jDl = dChart.m_jList.find('li:eq(' + i + ') dl');
					var jH = dChart.m_jList.find('li:eq(' + i + ') p');
					//dChart.m_jH.stop(true, false).animate({
					//	opacity: 0
					//}, 100);
					dChart.m_jDl.stop(true, false).animate({
						opacity: 0
					}, 100, function() {
						var jHClone = jH.clone();
						var jDlClone = jDl.clone();
						jDlClone.find('.rating-indicator span').css('display', 'none');
						dChart.m_jDl.replaceWith(jDlClone).fadeIn(150);
						dChart.m_jH.html(jH.html());
						dChart.m_jDl = jDlClone;
						dChart.Animate();
					});
				};
				
				var jPanel = $(this).closest('.ui-tabs-panel');
				if (jPanel.length) {
					var sPanel = jPanel.attr('id');
					jPanel.prevAll('.ui-tabs:first').bind('tabsselect', function(e, ui) {
						if ($(ui.panel).attr('id') == sPanel) {
							dChart.m_jDl.find('.rating-indicator span').css('display', 'none');
						}
					}).bind('tabsshow', function(e, ui) {
						if ($(ui.panel).attr('id') == sPanel) {
							dChart.Animate();
						}
					});
				}
				this.m_jList.find('h6').each(function(i) {
					$(this).click(function() {
						dChart.ShowSummary(i);
						return false;
					});
				});
				this.Animate();
				
			});
			
		}
		
	});
	
})(jQuery);