(function($j){
	$j.fn.simpletabs = function(params){
		
		var opts = params || {};
		opts.hideTags = opts.hideTags || false;
		opts.activeTab = opts.activeTab - 1 || 0;
		opts.activeClass = opts.activeClass || "active";
		opts.mouseover = opts.mouseover || false;
		opts.noresize = opts.noresize || false;
		opts.navParent = opts.navParent || false;
		opts.framesParent = opts.framesParent || false;
		
		var currentTab = false;
		
		this.each(function(){
			
			// Selections
			var container = $j(this);
			var nav_container = opts.navParent || container.find("> :first-child");
			var frames_container = opts.framesParent || container.find("> :nth-child(2)");
			var nav_links = nav_container.find("a[href^=#]");
			var frames = frames_container.find("> *");
			
			// Tabs count == frames count ?
			if (nav_links.length != frames.length){return false;}
			
			// Resize height
			if (!(opts.noresize)){
				$j(window).load(function(){
					var maxHeight = 0;
					frames.each(function(){
						var curHeight = $j(this).height();
						if (curHeight > maxHeight){maxHeight = curHeight;}
					});
					frames.height(maxHeight);
				});
			}
			
			// Prevent default event & remove outline
			nav_links.click(function(e){
				e.preventDefault();
			}).css("outline", "0");
			
			// Add frames to link properties
			nav_links.each(function(){
				this._linkedFrame = frames.filter($j(this).attr("href"));
			});
			
			// Switch tabs on click
			nav_links.click(function(){
				if (currentTab){
					currentTab.removeClass(opts.activeClass);
					currentTab.get(0)._linkedFrame.hide();
				}
				else {
					frames.filter(":visible").hide();
				}
				this._linkedFrame.show();
				$j(this).addClass(opts.activeClass);
				currentTab = $j(this);
			});
			
			// And on mouseover
			if (opts.mouseover){
				nav_links.hover(function(){ // On mouseover
					$j(this).click();
				},function(){});
			}
			
			// Hide tags
			if (opts.hideTags){
				frames.find(opts.hideTags).hide();
			}
			
			// Show first tab
			nav_links.filter(":eq(" + opts.activeTab + ")").click();
		});
		
		return this;
	};
})(jQuery);