(function($){
	$.fn.extend({
		cwTab: function(){
			return $(this).each(function(){
				var tabs = $('.tab-selector li', this), id = $(this).attr('id'), current;
				var tabInit = function(){
					$.each(tabs, function(i){
						var selector = $(this).children('a'), target = $(selector.attr('href'));
						selector.click(tabSelect);
						if (i == 0) {
							current = $(this);
							current.addClass('current')
						}
						else {
							target.hide();
						}
					});
				};
				var tabSelect = function(){
					if (current.attr('id') == $(this).attr('id')) return;
					current.removeClass('current');
					$(current.children('a').attr('href')).hide();
					current = $(this).parent();
					current.addClass('current');
					$(current.children('a').attr('href')).show();
					return false;
				};
				tabInit();
			});
		}
	});
	$(function(){
		var productSelection = function(){
			var id = $(this).attr('href');
			var selected = $(id);
			$('.rimoh-product').hide();
			selected.show()
				.find('img').fadeTo(0,0).fadeTo(1000,1).end()
				.find('a[href="'+id+'"]').parent().addClass('current');
			return false;
		};
		if (!$('body').is('.editable-mode')) {
			if ($('.rimoh-product').length) {
				$('.rimoh-product-selector a').click(productSelection);
				productSelection.apply($('#product-1 a[href="#product-1"]')[0]);
			}
		}
		if (!$('body').is('.editable-mode')) {
			$('.cw-tab-contents').cwTab();
		}
	});
})(jQuery);//
