

if (typeof popkong == 'undefined')
	popkong = function() {
	}
if (typeof popkong.theme == 'undefined')
	popkong.theme = function() {
	}
if (typeof popkong.theme.help == 'undefined')
	popkong.theme.help = new function() {
		var $ = AJS.$;
		
		this.initHelpTips = function() {
			
			var sidebar = $("#info-panel").parent("#sidebar");
			
			var mode = "none";
			if (window.location && window.location.href) {
				var loc = window.location.href;
				// Setup modes
				if (loc.indexOf("choosetheme.action") > -1 || 
						loc.indexOf("removespace.action") > -1 ||
						loc.indexOf("listpermissionpages.action") > -1 ||
						loc.indexOf("listdecorators.action") > -1 || 
						loc.indexOf("viewstylesheet.action") > -1 || 
						loc.indexOf("viewpdflayoutconfig.action") > -1 || 
						loc.indexOf("viewpdfstyleconfig.action") > -1 || 
						loc.indexOf("configurespacelogo.action") > -1 || 
						loc.indexOf("editstylesheet.action") > -1 || 
						loc.indexOf("importpages.action") > -1) {
					mode = "space";
				}	
				if(loc.indexOf("editpage.action") > -1 ) {
					mode = "editpage";
				}
				if(loc.indexOf("createpage.action") > -1 ) {
					mode = "createpage";
				}
				// Do work
				if (mode == "space") {
					// Add Help tip Links to tab area in space admin
					$('div#tab-navigation ul').append('<li style="float:right;border:1px solid #fc0; background-color:#ffc;padding:2px;"><a href="javascript:popkong.theme.help.showHelpTips(false);" style="text-decoration:none">Help Tips</a></li>');
					// hide original sidebar
					sidebar.attr('style','display:none');
				}
				if(mode == "editpage" || mode == "createpage") {
					// Add help tips link in wiki markup icon editor area
					$('div#linkinserters ul').append('<li class="toolbar-button" style="font-size: 8pt; border:1px solid #fc0; background-color:#ffc;line-height:1.6em;margin-top:2px"><a href="javascript:popkong.theme.help.showHelpTips(true);">&nbsp;Help Tips&nbsp;</a></li>')
					// hide original sidebar
					sidebar.attr('style','display:none');
					
					// Resize the title text are to fill since there are no nav items in the nav cell
					$('table td#title-cell').attr('width','100%'); 
					$('table td#navigation-cell').attr('style','display:none');
					$('input#content-title').attr('style','width:99%');
					
				}
				
			} // end: if (window.location && window.location.href) {
			

		} // end initHelpTips
		
		// SEE: http://confluence.atlassian.com/display/AUI/Dialog
		this.showHelpTips = function(showFullNotationBtn) {

			var popup = new AJS.Dialog(640, 500);
			popup.addHeader($('#helpheading').text()); 
			popup.addPanel("Panel 1", "panel1");
			
			// Restyle the content that will go in the help tips pop-up
			$('#helpcontent dl').attr('style','font-size: 10pt');
			$('#helpcontent dt').attr('style','background-color: #efefef;padding:4px'); 
			$('#notation-help-link').attr('style','font-weight:bold');
			
			// Get the text from the Full notation hyperlink; we'll use it as the button label
			var fullNotationHelpLabel = $('#notation-help-link').text();
			// Get the href too (context root differs in some installations)!
			var fullNotationHelpURL = $('#notation-help-link').attr('href');
			// Hide the Full notation guide hyperlink from the content (we're going to make it a button)
			$('#notation-help-link').attr('style','display:none');
			
			// Put the content of the help tips sidebar into the popup dialog...
			popup.getCurrentPanel().html($('#helpcontent').html());
			
			if(showFullNotationBtn){
				popup.addButton(fullNotationHelpLabel, function (dialog) {
					
					window.open(fullNotationHelpURL,'notation_help','width=780, height=580, resizable, scrollbars');
					// Hide the pop-up dialog when users view full notation help
					dialog.hide();
				});
			}
					
			// add "Cancel" button on page 0 (current page)
			popup.addButton("Close", function (dialog) {
				dialog.hide();
			});
			
			popup.addPage();
			 
			// start first page, first panel
			popup.gotoPage(0);
			popup.gotoPanel(0);
			 
			// display the popup
			popup.show();
		}

	AJS.toInit(this.initHelpTips);
}


