//========================== Help ===============================
var baseHelp
var baseHelpLeft
var helpDFrame

var IntroductionIndex
var ReferenceIndex
var StylesIndex
var baseHelpRight
var leftDFrame = []

//buttonsTexts[] and buttonsActions[] are defined in the application using help.js


function openHelp() {
	//no scrollBar for IE
	if (is.ie) document.body.scroll="no"

	if (!baseHelp) {
		//Create base dFrame for all others dFrames
		baseHelp = new DFrame([0, 0, 100, 100],'DFrameAPI help', dFrameStyleForHelpNoBorders)
		baseHelp.addToTaskBars('baseAll')
		baseHelp.addToTaskMenus(false)
		baseHelp.setTitleBar(true)
		
		//Add a DFrame on the left side		
		baseHelpLeft = new DFrame([0,0,22,100],'', dFrameStyleForHelpNoBorders, baseHelp)
		baseHelpLeft.addToTaskBars(false)
		baseHelpLeft.addToTaskMenus(false)
		//Add bar for tabs
		var bar = baseHelpLeft.addBar(tabBarStyle)
		//Add tab buttons
		var bn = []
		for (var i = 0 ; i<buttonsTexts.length ; i++) {
			bn[i] = bar.addButton(buttonsTexts[i], 'openIndexPage(' + i + ')')		
		}			

		//Add a DFrame on right side
		var pos = [0,0,100,100]
		pos[0] = [baseHelpLeft, 'Right',2]
		baseHelpRight = new DFrame(pos,'', dFrameStyleForHelpNoBorders, baseHelp)
		baseHelpRight.addToTaskBars(false)
		baseHelpRight.addToTaskMenus(false)		
		baseHelpRight.addTaskBar('', 'baseHelp')
		//open the first index	
		bn[0].setLook('SELECTED')
		openIndexPage(0)
	}
	//Instanciate (and return) the content dFrame
	helpDFrame = DFrameCollector.find('helpDFrame')
	if (!helpDFrame) {	
		//The dFrame for content help
		helpDFrame = new DFrame([0,0,100,100], '', dFrameStyleForHelp, baseHelpRight)
		var bar = helpDFrame.addBar('', 'BOTTOM', barStyle)
		bar.addButton('Close', 'thisDFrame.closeFrame()')		
		helpDFrame.addToTaskBars('baseHelp')
		helpDFrame.addToTaskMenus(false)
		helpDFrame.setTitleAsHTMLTitle(true)
		//as helpDFrame can be set to multiple target, need to define the open function for itself
		helpDFrame.setTarget('openHelp()')	
	}
	DFrameCollector.register(helpDFrame, 'helpDFrame')
	return helpDFrame
}

function openIndexPage(page) {
	if (!leftDFrame[page]) leftDFrame[page] = openDFrameHelpForLeftSide()
	leftDFrame[page].setURL(indexPage[page])
/*
	leftDFrame[page].onEvent = function(e) {
		if (e.action == 'postCreate' && e.dFrame == leftDFrame[page]) {
			if (is.ie) var h = 35
			else if (is.ns6) var h = 25
			else if (is.ns4) var h = 35

			DynDoc = this.createDynAPIDocument()		
			DynDoc.addChild(new DynLayer(null,0,0,100,h,'#ffffff'))
			e.cancelBubble=true
		}	
	}	
*/
}

function openDFrameHelpForLeftSide() {
	//Insert a DFrame in baseHelpLeft: One DFrame for each index
	var dFrame = new DFrame([0,0,100,100],'left index', dFrameStyleForHelp, baseHelpLeft)
	dFrame.addToTaskBars(false)
	dFrame.addToTaskMenus(false)	
	dFrame.setTarget('openHelp()')	
	dFrame.setMultipleTarget(false)	

	//Add a bar and 2 buttons in the bottom
	var bar = dFrame.addBar('BOTTOM', barStyle)
	bar.setPos('BOTTOM')
	bar.addButtonImage('multiple', 'thisDFrame.setMultipleTarget(true)')	
	var bn = bar.addButtonImage('unique', 'thisDFrame.setMultipleTarget(false)')	
	bn.setLook('SELECTED')
	
	dFrame.useContextMenu(false)	
	return dFrame
}
