var pkAttachments = true;
var pkLabels = true;
var pkComments = true;
var pkChildren = true;

function setPopKongTabExtras(attachments,labels,comments,children){
	//alert("attachments: " + attachments + "|labels: " + labels + "|comments:" + comments + "|children:" + children);
	pkAttachments = attachments;
	pkLabels = labels;
	pkComments = comments;
	pkChildren = children;
}

AJS.toInit(function () {
	
	var $ = AJS.$;
	
	this.determinePixelWidth = function() {
		if (typeof popkong != 'undefined' && typeof popkong.theme != 'undefined') {
			var availableWidth = popkong.utils.determinePageWidth();
			$(".tab-extras-tab").width(availableWidth * 0.95 + "px");
		}
	}

	/**
	 * extends a jquery object with an isVisible attribute that's true when the jquery obj
	 * has elements and is not hidden (display is not 'none')
	 */
	this.extendSectionObj = function(section) {
		section.isVisible = section.length > 0;
		return section;
	};
	
	// Extend sections with isVisible attribute while grabbing them as variables...
	var comments = this.extendSectionObj($('#comments-section'));
	var labels   = this.extendSectionObj($("#labels-section"));
	var children = this.extendSectionObj($("#children-section"));
	
	// -------------------------------------------------------------
	// COMMENTS SECTION
	// -------------------------------------------------------------
	if(pkComments){
		if (comments.isVisible) {
			$('#comments-section-title').remove();
			//$('#pop-comments-tab').append(comments);
		} //else {
			//$("#pop-comments-tab, #pop-comments-tab-title").remove();
		//}
	}

	// -------------------------------------------------------------
	// CHILDREN SECTION
	// -------------------------------------------------------------
	
	if(pkChildren){
		if (children.isVisible) {
			$('#children-section-title').remove();
			//$('#pop-children-tab').append(children);
		} else {
			$("#pop-children-tab, #pop-children-tab-title").remove();
		}
	}

	// -------------------------------------------------------------
	// LABELS SECTION
	// -------------------------------------------------------------
	
	if(pkLabels){
		if (labels.isVisible) {
			$('#labels-section-title').remove();
			//$('#pop-labels-tab').append(labels);
		} //else {
			//$("#pop-labels-tab, #pop-labels-tab-title").remove();
		//}
	}
	
	var popTabExtras = new popkongYAHOO.widget.TabView("pop-tab-extras");
	
	//set the active Tab to the cookie value, if present:
	var activeTabCookie = "popkong-active-tab";
	
	if (popkongYAHOO.util.Cookie.get(activeTabCookie)) {
		popTabExtras.set("activeTab", popTabExtras.getTab(popkongYAHOO.util.Cookie.get(activeTabCookie)));
	};
	
	//when a Tab changes, set the cookie:
	popTabExtras.on("activeTabChange", function(o) {
		popkongYAHOO.util.Cookie.set(activeTabCookie, this.getTabIndex(o.newValue)); 
	});
	
	if(pkAttachments || pkLabels || pkComments || pkChildren) {
		// Set width on attachments tab so that overflow:auto will work on that tab.
		this.determinePixelWidth();
		$(window).bind("resize", this.determinePixelWidth);
		$("#pop-tab-extras").show();
	}
	
});
	



