﻿(function($) {
    $.fn.extend({
        pmTabs: function() {
			return this.each(function() {
				//	Tab container 
				var oTabContainer = $(this);
				
				var tabIsActive = false;
				
				oTabContainer.find("div[id^='tabContainer']").each(function(){
					oTabContentContainer = $(this);
				
					if ($.trim(oTabContentContainer.html()).length > 0) {
						var strTabId = oTabContentContainer.attr("id");
						strTabId = strTabId.substring(12, strTabId.length);
						
						oTab = $("#tab" + strTabId);
						
						//	Show tab
						oTab.show();
						
						//	Select first tab with content
						if (!tabIsActive) {
							oTab.removeClass().addClass("selected");
							oTabContentContainer.show();	
							
							tabIsActive = true;
						}
						
						//	Handle tab events
						oTab.click(function(e) {
							oTab = $(this);
						
							oTabContainer = oTab.parents("div[class*='Container']");
							oTabContentContainer = oTabContainer.find("div[id^='tabContainer" + strTabId + "']");
							
							oTabContainer.find(".selected").removeClass().addClass("unselected");
							oTabContainer.find("div[id^='tabContainer']").hide();
							
							oTab.removeClass().addClass("selected");
							oTabContentContainer.show();
						});	
					}															   
				});
			});
		}
    });
})(jQuery);
