$.fn.tabset = function(options) {
		
	this.options = $.extend({}, options || {});
	
	this.each(function() {
		
		var $tabs = $('ul:eq(0) li', this);

		$tabs
			.each(function(i){ $(this).data('index', i); })
			.bind('click', function(e){
				e.preventDefault();
				e.stopPropagation();
				var $this = $(this);
				var $container = $this.closest("div");
				
				$('div.tabset-panel', $container).hide();
				$('div.tabset-panel:eq('+$this.data('index')+')', $container).show();
				$('ul:eq(0) li', $container)
					.removeClass('selected')
					.each(function(){
						var src = $('img', $(this)).attr('src');
						if (src.charAt(src.lastIndexOf('.')-1) == '_') {
							$('img', $(this)).attr('src', src.substr(0,src.lastIndexOf('.')-1) + src.substr(src.lastIndexOf('.')));
						}		   
					});
				$this.addClass('selected');
				
				var src = $('img', $this).attr('src');
				if (src.charAt(src.lastIndexOf('.')-1) != '_') {
					$('img', $this).attr('src', src.substr(0,src.lastIndexOf('.')) + '_' + src.substr(src.lastIndexOf('.')));
				}
				
			})
			.hover(
					function(){
						var src = $('img', $(this)).attr('src');
						if (src.charAt(src.lastIndexOf('.')-1) != '_') {
							$('img', $(this)).attr('src', src.substr(0,src.lastIndexOf('.')) + '_' + src.substr(src.lastIndexOf('.')));
						}
					},
					function(){
						if (!$(this).hasClass('selected')) {
							var src = $('img', $(this)).attr('src');
							if (src.charAt(src.lastIndexOf('.')-1) == '_') {
								$('img', $(this)).attr('src', src.substr(0,src.lastIndexOf('.')-1) + src.substr(src.lastIndexOf('.')));
							}
						}
					}
				   );

		// Initialise
		if ($('div.tabset-panel', this).length > 0) {
			$('div.tabset-panel', this).hide();
			$tabs.eq(0).trigger('click');
		}
			
	});

};
