var sectionGroups={}
var sections={}
var sectionGroupsCount=0 
var hideContentGroup=''
var hideContentGroup2=''
var sectionGroupResizing=null;
var sizeCheckTimer=null
var showSectionTimer=null;
var dragOverGroup=''

var SECTIONGROUP_NOGROUPING=1

var SECTION_NOTAB=1
var SECTION_RESIZE=2
var SECTION_NOSCROLL=4



function ContainerSize()
{
	this.left=0;
	this.top=0;
	this.width=0;
	this.height=0;
}


function SectionGroups()
{
	this.onresize=false;
	this.ondisplay=false;
	this.sectionsLoadStart=0
	this.sectionsLoadEnd=0
	this.onBeforeLoadSectionsContent=null
	this.onAfterLoadSectionsContent=null
	this.onBeforeSectionsSetup=null
	this.onAfterSectionsSetup=null
}

function SectionGroup(uid)
{
	this.name=''
	this.parent=null
	this.flags=0;

	this.size=null;
	this.tabsClosedSize=new ContainerSize();
	this.tabsOpenSize=new ContainerSize();
	this.resizeSize={width:0,height:0}
	
	this.hasNoTabs=false;
	this.tabs=new Tabs()
	this.tabCount=0
	
	this.statusTimer=null;

	this.topOffset=0;
	this.leftOffset=0;
	this.rightOffset=0;
	this.bottomOffset=0;
	
	this.minWidth=0;
	this.minHeight=0;
	
	this.resizeHandler=null;
	this.resizeEndHandler=null;
	this.resizeLeaveHandler=null;
	this.resizeLastX=0
	this.resizeLastY=0

	this.resizeSides=0;
	

	this.uid=uid;	
	this.sections={};
	this.sectionCount=0;
	this.sectionShown='';
	
	this.barDragging=false;
	this.barDragHandler=null
	this.barDragEndHandler=null
	this.barDragLeaveHandler=null
	this.barDragOffsetTop=0
	this.barDragOffsetLeft=0
	this.barElement=null;
	this.barLastX=0
	this.barLastY=0

	this.sectionDragging=false;
	this.sectionDragHandler=null
	this.sectionDragEndHandler=null
	this.sectionDragLeaveHandler=null
	this.sectionDragStartLeft=0
	this.sectionDragStartTop=0
	this.sectionDragOffsetTop=0
	this.sectionDragOffsetLeft=0
	this.sectionElement=null
	this.sectionDragId='';
	this.sectionLastX=0
	this.sectionLastY=0
	this.zIndex=0;
	this.inFront=false;
}


SectionGroups.prototype.loadSectionsContent=function loadSectionsContent()
{
	
	this.onresize=false;
	this.ondisplay=false;

	var section,x
	for(x in sections)
	{
		section=sections[x]
		section.contentLoaded=false;
		this.sectionsLoadStart++
	}
	
	var call
	if(call=this.onBeforeLoadSectionsContent)call()
	for(x in sections)
	{
		sections[x].loadContent()
	}
}

SectionGroups.prototype.setupSections=function setupSections()
{
	
	var call,x
	
	if(call=this.onBeforeSectionsSetup)call()
	for(x in sections)
	{
		if(call=sections[x].setup)
		{
			call()
		}		
	}
	this.ondisplay=true;
	if(call=this.onAfterSectionsSetup)call()
}



SectionGroups.prototype.sectionContentLoaded=function sectionContentLoaded(uid)
{
	var call,x;
	this.sectionsLoadEnd++
	if(this.sectionsLoadEnd==this.sectionsLoadStart)
	{
		if(call=this.onAfterLoadSectionsContent)call()
		this.setupSections();
		this.onresize=true
		for(x in sections)
		{
			section=sections[x]
			if(call=section.oncontentloaded)
			{
				call(section);
			}
		}
		
	}
}



SectionGroups.prototype.findContainerCall=function findContainerCall(e,callFunc)
{
	var x,group,element,left,top,right,bottom,found=-1,foundId='';
	if(!sectionGroupResizing)document.body.style.cursor=''
		
	element=e.element
	while(element && element.className!='container')
	{
		element=element.parentNode
	}
	
	if(element)
	{
		e.element=element
		foundId=element.id.substring(element.id.indexOf('_')+1)
		return sectionGroups[foundId][callFunc](e)
	}
}


SectionGroups.prototype.removeSectionGroup=function removeSectionGroup(uid)
{
	document.getElementById('containers').removeChild(document.getElementById('container_'+uid))
	var x
	for(x in sectionGroups[uid].sections)
	{
		sectionGroups[uid].deleteSection(x)
	}
	delete sectionGroups[uid]
	sectionGroupsCount--
}


SectionGroups.prototype.addSectionGroup=function addSectionGroup(left,top,width,height,name,flags,minWidth,minHeight)
{
	var uid=''
	while(sectionGroups[uid=getUID()]);
	var group=sectionGroups[uid]=new SectionGroup(uid)
	sectionGroupsCount++
	group.parent=this;
	group.zIndex=sectionGroupsCount;
	
	group.size=group.tabsOpenSize;
	group.size.left=(left)?left:0
	group.size.top=(top)?top:0
	group.size.width=(width)?width:0
	group.size.height=(height)?height:0
	
	group.minWidth=(minWidth)?minWidth:0
	group.minHeight=(minHeight)?minHeight:0
	group.name=(name)?name:''
	group.flags=(flags)?flags:0
	
	group.tabsClosedSize.top=group.size.top
	group.tabsClosedSize.left=group.size.left
	group.tabsClosedSize.width=group.size.width
	group.tabsClosedSize.height=stdMinHeight

	var out=''
	+'<DIV'
	+' STYLE="'
	+((left)?'left:'+left+'px;':'')
	+((top)?'top:'+top+'px;':'')
	+((width)?'height:'+width+'px;':'')
	+((height)?'height:'+height+'px;':'')
	+'z-index:'+group.zIndex+';"'
	+' ID="container_'+uid+'" CLASS="container">'
	+'<DIV onMouseDown="sectionGroups[\''+uid+'\'].barDragStart(event)"'
	+' STYLE="'+((width)?'width:'+(Math.max(0,width-sizes.bar.outerAllWidth))+'px;':'')+'"'
	+' CLASS="bar" id="bar_'+uid+'">'
	+'<DIV CLASS="barText" ID="barText_'+uid+'">'+group.name+'</DIV>'
	+'<DIV CLASS="sendBack" onClick="sectionGroups[\''+uid+'\'].sendBack(event)"></DIV>'
	+'</DIV>'
	+'<DIV CLASS="tabs"'
	+' id="tabs_'+uid+'"'
	+' STYLE="'+((width)?'width:'+(Math.max(0,width-sizes.tabs.outerAllWidth))+'px;':'')+'"'
	+'>'
	+'</DIV>'
	+'<DIV CLASS="sectionsContainer"'
	+' STYLE="'
	+((width)?'width:'+(Math.max(0,width-sizes.sectionsContainer.outerAllWidth))+'px;':'')
	+((height)?('height:'+(Math.max(0,height-barsHeight))+'px;'):'')
	+'"'
	+' id="sectionsContainer_'+uid+'"'
	+' >'
	+'<DIV CLASS="sections"'
	+' STYLE="'
	+((width)?'width:'+(Math.max(0,width-sizes.sections.outerAllWidth))+'px;':'')
	+((height)?('height:'+(Math.max(0,height-barsHeight))+'px;'):'')
	+'"'
	+' id="sections_'+uid+'"></DIV>'
	+'</DIV>'
	+'<DIV'
	+' id="statusBar_'+uid+'"'
	+' STYLE="'
	+((width)?'width:'+(Math.max(0,width-sizes.statusBar.outerAllWidth))+'px;':'')
	+'"'
	+'CLASS="statusBar">'
	+'<DIV CLASS="statusBarText" ID="statusBarText_'+uid+'"></DIV>'
	+'<DIV CLASS="statusBarSEResize" onMouseDown="sectionGroups[\''+uid+'\'].startResize(event,25)"></DIV>'
	+'</DIV>'
	
	
	var element=document.createElement('DIV')
	element.innerHTML=out;
	document.getElementById('containers').appendChild(element.firstChild)
	return sectionGroups[uid]
}

SectionGroup.prototype.getCallStr=function getCallStr()
{
	return 'sectionGroups.'+this.uid
}

SectionGroup.prototype.resizeFX=function resizeFX(FXId,stepLeft,stepTop,stepWidth,stepHeight)
{
	var section=sections[FXId];
	
	if(typeof stepLeft=='undefined')
	{
		stepLeft=Math.floor((this.size.left-section.resizeFXSize.left)/10)
		stepTop=Math.floor((this.size.top-section.resizeFXSize.top)/10)
		stepWidth=Math.floor((this.size.width-section.resizeFXSize.width)/10)
		stepHeight=Math.floor((this.size.height-section.resizeFXSize.height)/10)
	}

	if(section.resizeFXSize.left!=this.size.left)section.resizeFXSize.left=((stepLeft>0)?Math.min(this.size.left,(section.resizeFXSize.left+stepLeft)):Math.max(this.size.left,section.resizeFXSize.left+stepLeft))
	if(section.resizeFXSize.top!=this.size.top)section.resizeFXSize.top=((stepTop>0)?Math.min(this.size.top,(section.resizeFXSize.top+stepTop)):Math.max(this.size.top,section.resizeFXSize.top+stepTop))
	if(section.resizeFXSize.width!=this.size.width)section.resizeFXSize.width=((stepWidth>0)?Math.min(this.size.width,(section.resizeFXSize.width+stepWidth)):Math.max(this.size.width,section.resizeFXSize.width+stepWidth))
	if(section.resizeFXSize.height!=this.size.height)section.resizeFXSize.height=((stepHeight>0)?Math.min(this.size.height,(section.resizeFXSize.height+stepHeight)):Math.max(this.size.height,section.resizeFXSize.height+stepHeight))
	
	
	var element=document.getElementById('resizeFX')
	element.style.visibility='visible';
	element.style.zIndex=sectionGroupsCount+1;
	element.style.left=section.resizeFXSize.left+'px';
	element.style.top=section.resizeFXSize.top+'px';
	element.style.width=section.resizeFXSize.width+'px';
	element.style.height=section.resizeFXSize.height+'px';
	

	if((section.resizeFXSize.left==this.size.left) && (section.resizeFXSize.top==this.size.top) && (section.resizeFXSize.width==this.size.width) && (section.resizeFXSize.height==this.size.height))
	{
		element.style.visibility='hidden';
	}
	else
	{
		setTimeout(this.getCallStr()+'.resizeFX(\''+FXId+'\','+stepLeft+','+stepTop+','+stepWidth+','+stepHeight+')',5)
	}
}


SectionGroup.prototype.setSizeCheckTabs=function setSizeCheckTabs(FXId)
{
	if(FXId)
	{
		var section=sections[FXId];
		section.resizeFXSize.left=this.size.left
		section.resizeFXSize.top=this.size.top
		section.resizeFXSize.width=this.size.width
		section.resizeFXSize.height=this.size.height
	}
	if(this.sectionShown)
	{
		this.size=sections[this.sectionShown].containerSize
	}
	else 
	{
		this.size=this.tabsClosedSize
	}
	this.showSize()
	if(FXId)this.resizeFX(FXId)
}
	

SectionGroup.prototype.showSize=function showSize()
{
	if(this.sectionShown)
	{
		this.size.height=Math.max(this.size.height,Math.max(stdMinHeight,Math.max(sections[this.sectionShown].minHeight,this.minHeight)));
		this.size.width=Math.max(this.size.width,Math.max(stdMinWidth,Math.max(sections[this.sectionShown].minWidth,this.minWidth)));
	}
	else
	{
		this.size.height=Math.max(this.size.height,Math.max(stdMinHeight,this.minHeight));
		this.size.width=this.minWidth;
	}

	var element=document.getElementById('container_'+this.uid)
	element.style.left=this.size.left+'px'
	element.style.top=this.size.top+'px'
	element.style.width=this.size.width+'px'
	element.style.height=this.size.height+'px'
	
	element=document.getElementById('bar_'+this.uid)
	element.style.width=Math.max(0,this.size.width-sizes.bar.outerAllWidth)+'px'
	
	element=document.getElementById('barText_'+this.uid)
	element.style.width=Math.max(0,this.size.width-sizes.barText.outerAllWidth-sizes.sendBack.width)+'px'
	
	element=document.getElementById('tabs_'+this.uid)
	element.style.width=Math.max(0,this.size.width-sizes.tabs.outerAllWidth)+'px'

	element=document.getElementById('sectionsContainer_'+this.uid)
	element.style.width=Math.max(0,this.size.width-sizes.sectionsContainer.outerAllWidth)+'px'

	element=document.getElementById('sections_'+this.uid)
	element.style.width=Math.max(0,this.size.width-sizes.sections.outerAllWidth)+'px'

	element=document.getElementById('statusBar_'+this.uid)
	element.style.width=Math.max(0,this.size.width-sizes.statusBar.outerAllWidth)+'px'
	
	element=document.getElementById('statusBarText_'+this.uid)
	element.style.width=Math.max(0,this.size.width-sizes.statusBarText.outerAllWidth-sizes.statusBarSEResize.width)+'px'

	
	this.checkTabs()
}

SectionGroup.prototype.checkTabs=function SectionGroup_checkTabs()
{
	var x,height,element,resizeWidth,resizeHeight,notfound=true;
	this.hasNoTabs=true
	for(x in this.sections)
	{
		if(!(this.sections[x].flags & SECTION_NOTAB))
		{
			this.hasNoTabs=false
			break;
		}
	}
	if(this.hasNoTabs)
	{
		element=document.getElementById('sections_'+this.uid)
		height=Math.max(0,this.size.height-barsHeightNoTabs)
		element.style.height=height+'px'
		element.parentNode.style.height=height+'px'
		
		element=document.getElementById('tabs_'+this.uid)
		element.style.height='';
		element.style.width='';

		this.resizeSize.width=resizeWidth=Math.max(0,this.size.width-sizes.sections.outerAllWidth)
		this.resizeSize.height=resizeHeight=Math.max(0,this.size.height-sizes.sections.outerAllHeight-barsHeightNoTabs)
		
		if(this.sectionShown && (this.sections[this.sectionShown].flags & SECTION_RESIZE))
		{
			var element=document.getElementById(this.sections[this.sectionShown].uid)
			this.tabsOpenHeight=resizeHeight
			element.style.height=resizeHeight+'px';
			element.style.width=resizeWidth+'px'
			if(this.parent.onresize && (call=this.sections[this.sectionShown].onresize))
			{
				call(this.sections[this.sectionShown],this.resizeSize);
			}
		}
	}
	else
	{
		element=document.getElementById('sections_'+this.uid)
		height=Math.max(0,this.size.height-barsHeight)
		element.parentNode.style.height=height+'px'
		element.style.height=height+'px'
		
		element=document.getElementById('tabs_'+this.uid)
		element.style.height=sizes.tab.height+'px';
		element.style.width=Math.max(0,this.size.width-sizes.tabs.outerAllWidth)+'px'

		this.resizeSize.width=resizeWidth=Math.max(0,this.size.width-sizes.sections.outerAllWidth)
		this.resizeSize.height=resizeHeight=Math.max(0,this.size.height-sizes.sections.outerAllHeight-barsHeight)
			
		if(this.sectionShown && (this.sections[this.sectionShown].flags & SECTION_RESIZE))
		{
			var element=document.getElementById(this.sections[this.sectionShown].uid)
			element.style.height=resizeHeight+'px';
			element.style.width=resizeWidth+'px'
			if(this.parent.onresize && (call=this.sections[this.sectionShown].onresize))
			{
				call(this.sections[this.sectionShown],this.resizeSize);
			}
		}
	}
}



SectionGroup.prototype.setSizePosition=function SectionGroup_setSizePosition(left,top,width,height,side)
{
	
		
		if(this.sectionShown)
		{
			height=Math.max(height,Math.max(stdMinHeight,Math.max(sections[this.sectionShown].minHeight,this.minHeight)));
			width=Math.max(width,Math.max(stdMinWidth,Math.max(sections[this.sectionShown].minWidth,this.minWidth)));
		}
		else
		{
			height=Math.max(height,Math.max(stdMinHeight,this.minHeight));
			width=this.minWidth;
		}
		var element=document.getElementById('container_'+this.uid)
		
		element.style.left=(this.size.left=left)+'px'
		element.style.top=(this.size.top=top)+'px'
		element.style.width=(this.size.width=width)+'px'
		element.style.height=(this.size.height=height)+'px'
		
		element=document.getElementById('bar_'+this.uid)
		element.style.width=Math.max(0,this.size.width-sizes.bar.outerAllWidth)+'px'
		
		element=document.getElementById('barText_'+this.uid)
		element.style.width=Math.max(0,this.size.width-sizes.barText.outerAllWidth-sizes.sendBack.width)+'px'

		element=document.getElementById('tabs_'+this.uid)
		element.style.width=Math.max(0,this.size.width-sizes.tabs.outerAllWidth)+'px'

		
		element=document.getElementById('sectionsContainer_'+this.uid)
		element.style.width=Math.max(0,this.size.width-sizes.sectionsContainer.outerAllWidth)+'px'

		element=document.getElementById('sections_'+this.uid)
		element.style.width=Math.max(0,this.size.width-sizes.sections.outerAllWidth)+'px'

		element=document.getElementById('statusBar_'+this.uid)
		element.style.width=Math.max(0,this.size.width-sizes.statusBar.outerAllWidth)+'px'
		
		element=document.getElementById('statusBarText_'+this.uid)
		element.style.width=Math.max(0,this.size.width-sizes.statusBarText.outerAllWidth-sizes.statusBarSEResize.width)+'px'

		
		if(this.sectionShown)
		{
			var section=this.sections[this.sectionShown]
			section.containerSize.left=this.size.left;
			section.containerSize.top=this.size.top;
			section.containerSize.width=this.size.width;
			section.containerSize.heigt=this.size.heigt;
		}
		
		this.checkTabs()
}


SectionGroup.prototype.addSection=function SectionGroup_addSection(uid,name,flags,minWidth,minHeight)
{
	var section=sections[uid]=this.sections[uid]=new Section(this,uid,name,flags,minWidth,minHeight)
	this.sectionCount++;
	
	section.containerSize.left=this.tabsOpenSize.left;
	section.containerSize.top=this.tabsOpenSize.top;
	section.containerSize.width=this.tabsOpenSize.width;
	section.containerSize.height=this.tabsOpenSize.height;
	
	var out='';
	if(!(section.flags & SECTION_NOTAB))
	{
		this.tabs.addTab(section)
	}
	out=''
	+'<DIV'
	+' STYLE="'
	+((section.flags & SECTION_NOTAB)?'':' display:none;')
	+'"'
	+' CLASS="section" id="'+uid+'"></DIV>'
	

	var element=document.createElement('DIV')
	element.innerHTML=out;
	var element2=document.getElementById('sections_'+this.uid)
	element2.appendChild(element.firstChild)
	
	if(section.flags & SECTION_NOSCROLL)element2.style.overflow='hidden'
	else element2.style.overflow='auto'
	if(this.sectionCount>1)this.setSizeCheckTabs()
	return this.sections[uid]
}




SectionGroup.prototype.checkSides=function SectionGroup_checkSides(e)
{
	var bottom=this.size.top+this.size.height+sizes.container.outerHeight
	var right=this.size.left+this.size.width
	var sides=0;

	if(e.x>=this.size.left && e.x<=right && e.y>=this.size.top && e.y<=bottom)sides|=1
	if((e.x>=this.size.left && e.x<=(this.size.left+resizeLeftWidth))&& (e.y>=this.size.top && e.y<bottom))sides|=2
	if((e.x>=this.size.left && e.x<right) && (e.y>=this.size.top && e.y<=(this.size.top+resizeTopWidth)))sides|=4
	if((e.x>=(right-resizeRightWidth) && e.x<=right) && (e.y>=this.size.top && e.y<=bottom))sides|=8
	if(((e.x>=this.size.left && e.x<=right) && e.y>=(bottom-resizeBottomWidth) && e.y<=bottom))sides|=16
	
	
	return sides
}

SectionGroup.prototype.toFront=function SectionGroup_toFront(e)
{
	var noIcon=true
	if(e)
	{
		if(e.element.className=='barIcon')noIcon=false
	}
	if(noIcon)
	{
		var x,count=0
		for(x in sectionGroups)
		{
			count++
			if(sectionGroups[x].zIndex>this.zIndex)
			{
				sectionGroups[x].inFront=false;
				document.getElementById('container_'+x).style.zIndex=--sectionGroups[x].zIndex
			}
		}
		document.getElementById('container_'+this.uid).style.zIndex=this.zIndex=count
		this.inFront=true;
	}
}

SectionGroup.prototype.sendBack=function SectionGroup_sendBack(e)
{
	if(window.getSelection)window.getSelection().removeAllRanges();
	else if(document.selection)document.selection.empty();
	if(this.inFront)
	{
		var x,minZ=0,maxZ=0,count=0
		for(x in sectionGroups)
		{
			if(x!=this.uid)
			{
				sectionGroups[x].inFront=false;
				if(sectionGroups[x].zIndex<this.zIndex)
				{
					document.getElementById('container_'+x).style.zIndex=++sectionGroups[x].zIndex
				}
			}
		}
		document.getElementById('container_'+this.uid).style.zIndex=this.zIndex=0
		this.inFront=false;
	}
	e.cancelBubble=true;
}

SectionGroup.prototype.startResize=function SectionGroup_startResize(e,sides)
{
		var force=sides;
		sides=((sides)?sides:this.checkSides(e))
		if(sides>1 && (force || !sectionGroupResizing))
		{
			if(force)this.resizeEnd()
			if(!this.resizeHandler)
			{
				this.toFront()
				this.resizeSides=sides
				var x=(e.x)?e.x:e.pageX
				var y=(e.y)?e.y:e.pageY
				this.leftOffset=x-this.size.left
				this.topOffset=y-this.size.top
				this.rightOffset=x-this.size.left-this.size.width
				this.bottomOffset=y-this.size.top-this.size.height
				sectionGroupResizing=this.uid
				this.resizeHandler=events.addListener('mousemove',new Function('e','sectionGroups.'+this.uid+'.resize(e)'))
				this.resizeEndHandler=events.addListener('mouseup',new Function('e','sectionGroups.'+this.uid+'.resizeEnd(e)'))
				this.resizeLeaveHandler=events.addListener('mouseout',new Function('e','sectionGroups.'+this.uid+'.resizeLeave(e)'))
			}
		}
}


SectionGroup.prototype.hideContent=function SectionGroup_hideContent(group)
{
	var element=document.getElementById('hideContent')
	if(!group)group=this
	element.style.zIndex=group.zIndex+1
	element.style.left=group.size.left+sizes.sections.outerAllLeft+'px'
	element.style.top=group.size.top+sizes.sections.outerAllTop+sizes.bar.height+'px'
	element.style.width=group.size.width-sizes.sections.outerAllWidth+'px'
	element.style.height=group.size.height-sizes.sections.outerAllHeight-sizes.bar.height-sizes.statusBar.height+'px'
	element.style.display='block';
	hideContentGroup=group.uid;
}

SectionGroup.prototype.unhideContent=function SectionGroup_unhideContent(e)
{
	var element=document.getElementById('hideContent')
	element.style.display='none';
	hideContentGroup='';
}

SectionGroup.prototype.hideContent2=function SectionGroup_hideContent2(group)
{
	var element=document.getElementById('hideContent2')
	if(!group)group=this
	element.style.zIndex=group.zIndex+1
	element.style.left=group.size.left+sizes.sections.outerAllLeft+'px'
	element.style.top=group.size.top+sizes.sections.outerAllTop+sizes.bar.height+'px'
	element.style.width=group.size.width-sizes.sections.outerAllWidth+'px'
	element.style.height=group.size.height-sizes.sections.outerAllHeight-sizes.bar.height-sizes.statusBar.height+'px'
	element.style.display='block';
	hideContentGroup=group.uid;
}

SectionGroup.prototype.unhideContent2=function SectionGroup_unhideContent2(e)
{
	var element=document.getElementById('hideContent2')
	element.style.display='none';
	hideContentGroup2='';
}



SectionGroup.prototype.resize=function SectionGroup_resize(e)
{
	if(window.getSelection)window.getSelection().removeAllRanges();
	else if(document.selection)document.selection.empty();
	if(e.x<0)e.x=Math.max(0,this.resizeLastX);
	if(e.y<0)e.y=Math.max(0,this.resizeLastY);
	this.resizeLastX=e.x
	this.resizeLastY=e.y
	if(this.resizeSides>1)
	{
		switch(this.resizeSides)
		{
			case 3:
				//w
				this.setSizePosition(e.x-this.leftOffset,this.size.top,this.size.width+this.size.left-e.x+this.leftOffset,this.size.height,'w')
				break;
			case 5:
				//n
				this.setSizePosition(this.size.left,e.y-this.topOffset,this.size.width,this.size.height+this.size.top-e.y+this.topOffset,'n')
				break;
			case 7:
				//nw
				this.setSizePosition(e.x-this.leftOffset,e.y-this.topOffset,this.size.width+this.size.left-e.x+this.leftOffset,this.size.height+this.size.top-e.y+this.topOffset,'nw')
				break;
			case 9:
				//e
				this.setSizePosition(this.size.left,this.size.top,e.x-this.size.left-this.rightOffset,this.size.height,'e')
				break;
			case 13:
				//ne
				this.setSizePosition(this.size.left,e.y-this.topOffset,e.x-this.size.left-this.rightOffset,this.size.height+this.size.top-e.y+this.topOffset,'ne')
				break;
			case 17:
				//s
				this.setSizePosition(this.size.left,this.size.top,this.size.width,e.y-this.size.top-this.bottomOffset,'s')
				break;
			case 19:
				//sw
				this.setSizePosition(e.x-this.leftOffset,this.size.top,this.size.width+this.size.left-e.x+this.leftOffset,e.y-this.size.top-this.bottomOffset,'sw')
				break;
			case 25:
				this.setSizePosition(this.size.left,this.size.top,e.x-this.size.left-this.rightOffset,e.y-this.size.top-this.bottomOffset,'se')
				//se
				break;
		}
		this.hideContent()
	}
}

SectionGroup.prototype.resizeEnd=function SectionGroup_resizeEnd(e)
{
	if(this.resizeHandler)this.resizeHandler.remove()
	this.resizeHandler=null
	if(this.resizeEndHandler)this.resizeEndHandler.remove()
	this.resizeEndHandler=null
	if(this.resizeLeaveHandler)this.resizeLeaveHandler.remove()
	this.resizeLeaveHandler=null
	this.resizeSides=null;
	sectionGroupResizing=null
	this.unhideContent()
	this.unhideContent2()
}

SectionGroup.prototype.resizeLeave=function SectionGroup_resizeLeave(e)
{
	if(e.x<0 || e.y<0)
	{
		this.resize(e)
		this.resizeEnd(e,true)
	}
}

SectionGroup.prototype.setCursors=function SectionGroup_setCursors(e)
{
		if(!sectionGroupResizing)
		{
			var sides=this.checkSides(e)
			if(sides>1)
			{
				switch(sides)
				{
					case 3:
					case 9:
						document.body.style.cursor='e-resize'	
						return;
					case 7:
					case 25:
						document.body.style.cursor='se-resize'	
						return;
					case 5:
					case 17:
						document.body.style.cursor='s-resize'	
						return;
					case 13:
					case 19:
						document.body.style.cursor='sw-resize'	
						return;
				}
			}
			else document.body.style.cursor=''
		}
		else
		{
			this.hideContent2(sections.map.parent)
		}
		return
}



SectionGroup.prototype.barDragStart=function SectionGroup_barDragStart(e)
{
	if(!e)e=event;
	var sides=this.checkSides(e)
	if(sides<=1)
	{
		this.toFront()
		var element=((typeof e.srcElement!='undefined')?e.srcElement:e.target)
		var className=element.className
		if(className=='bar' || className=='barText')
		{
			this.barElement=document.getElementById('container_'+this.uid) //element.parentNode
			this.barDragOffsetLeft=this.barElement.offsetLeft-parseInt((typeof e.x!='undefined')?e.x:e.pageX)
			this.barDragOffsetTop=this.barElement.offsetTop-parseInt((typeof e.y!='undefined')?e.y:e.pageY)
			this.barDragHandler=events.addListener('mousemove',new Function('e','sectionGroups.'+this.uid+'.barDrag(e)'))
			this.barDragEndHandler=events.addListener('mouseup',new Function('e','sectionGroups.'+this.uid+'.barDragEnd(e)'))
			this.barDragLeaveHandler=events.addListener('mouseout',new Function('e','sectionGroups.'+this.uid+'.barDragLeave(e)'))
			this.dragContainer=this.uid;
			this.hideContent()
		}
	}
}



SectionGroup.prototype.barDrag=function SectionGroup_barDrag(e)
{
	if(window.getSelection)window.getSelection().removeAllRanges();
	else if(document.selection)document.selection.empty();
	
	if(this.barDragging)
	{
		if(e.x<0)e.x=Math.max(Math.abs(this.barDragOffsetLeft),this.barLastX);
		if(e.y<0)e.y=Math.max(Math.abs(this.barDragOffsetTop),this.barLastY);

		this.barLastX=e.x
		this.barLastY=e.y
		var left=(e.x+this.barDragOffsetLeft);
		var top=(e.y+this.barDragOffsetTop);
		this.barElement.style.left=left+'px'
		this.barElement.style.top=top+'px'
		sectionGroups[this.dragContainer].size.left=left
		sectionGroups[this.dragContainer].size.top=top
		if(!(this.flags & SECTIONGROUP_NOGROUPING))
		{
			var element=document.getElementById('container_'+this.uid)
			element.className='containerDrag';
		}
		this.checkDragOver(e)
		this.hideContent()
	}
	else this.barDragging=true;
}

SectionGroup.prototype.barDragEnd=function SectionGroup_barDragEnd(e,dontGroup)
{
	if(window.getSelection)window.getSelection().removeAllRanges();
	else if(document.selection)document.selection.empty();
	
	var element=document.getElementById('container_'+this.uid)
	element.className='container';
	this.barDragLeaveHandler.remove()
	this.barDragLeaveHandler=null
	this.barDragEndHandler.remove()
	this.barDragEndHandler=null
	this.barDragHandler.remove()
	this.barDragHandler=null
	this.barDragOffsetTop=0
	this.barDragOffsetLeft=0
	this.barElement=null;
	var to
	if(this.barDragging && (to=this.checkDragOver(e)))
	{
		if(!e.shiftKey)this.ungroupSections(this.dragContainer,to,dontGroup)
		else document.getElementById('container_'+to).className='container'
	}
	this.unhideContent()
	this.unhideContent2()
	this.dragContainer=''
	this.barDragging=false;
}

SectionGroup.prototype.barDragLeave=function barDragLeave(e)
{
	if(e.x<0 || e.y<0)
	{
		this.barDrag(e)
		this.barDragEnd(e,true)
	}
}


SectionGroup.prototype.sectionDragStart=function sectionDragStart(uid,e)
{
	if(!e)e=event;
	if(this.sectionCount>1)
	{
		this.toFront()
		var element=((typeof e.srcElement!='undefined')?e.srcElement:e.target)
		this.sectionElement=document.getElementById('container_'+this.uid);
		this.sectionDragStartLeft=parseInt((typeof e.x!='undefined')?e.x:e.pageX)
		this.sectionDragStartTop=parseInt((typeof e.y!='undefined')?e.y:e.pageY)
		this.sectionDragOffsetLeft=this.sectionElement.offsetLeft-this.sectionDragStartLeft
		this.sectionDragOffsetTop=this.sectionElement.offsetTop-this.sectionDragStartTop
		this.sectionDragId=uid;
		this.sectionDragHandler=events.addListener('mousemove',new Function('e','sectionGroups.'+this.uid+'.sectionDrag(e)'))
		this.sectionDragEndHandler=events.addListener('mouseup',new Function('e','sectionGroups.'+this.uid+'.sectionDragEnd(e)'))
		this.sectionDragLeaveHandler=events.addListener('mouseout',new Function('e','sectionGroups.'+this.uid+'.sectionDragLeave(e)'))
	}
}

SectionGroup.prototype.sectionDrag=function sectionDrag(e)
{
	if(window.getSelection)window.getSelection().removeAllRanges();
	else if(document.selection)document.selection.empty();
	
	if(Math.abs(this.sectionDragStartLeft-e.x)>3 || Math.abs(this.sectionDragStartTop-e.y)>3)
	{
		if(this.sectionDragging)
		{
			if(e.x<0)e.x=Math.max(Math.abs(this.sectionDragOffsetLeft),this.sectionLastX);
			if(e.y<0)e.y=Math.max(Math.abs(this.sectionDragOffsetTop),this.sectionLastY+sizes.bar.height+sizes.container.outerTop);
			this.sectionLastX=e.x
			this.sectionLastY=e.y
			
			var left=(e.x+this.sectionDragOffsetLeft);
			var top=(e.y+this.sectionDragOffsetTop);
			this.sectionElement.style.left=left+'px'
			this.sectionElement.style.top=top+'px'
			sectionGroups[this.dragContainer].size.left=left
			sectionGroups[this.dragContainer].size.top=top
			
			if(!(this.flags & SECTIONGROUP_NOGROUPING))
			{
				var element=document.getElementById('container_'+this.dragContainer)
				element.className='containerDrag';
			}
			
			this.checkDragOver(e)
			
			sectionGroups[this.dragContainer].hideContent()
			sections[this.sectionDragId].readyState='dragging'
			if(call=sections[this.sectionDragId].onreadystatechanged)call(sections[this.sectionDragId],sections[this.sectionDragId].readyState)
		}
		else
		{
			this.sections[this.sectionDragId].readyState='dragstart'
			if(call=this.sections[this.sectionDragId].onreadystatechanged)call(this.sections[this.sectionDragId],this.sections[this.sectionDragId].readyState)
			
			var group=this.groupSection(this.sectionDragId)
			this.dragContainer=group.uid;
			this.sectionElement=document.getElementById('container_'+group.uid)
			this.sectionElement.style.left=(e.x+this.sectionDragOffsetLeft)+'px'
			this.sectionElement.style.top=(e.y+this.sectionDragOffsetTop)+'px'
			this.sectionDragging=true;
			
			sections[this.sectionDragId].readyState='dragstarted'
			if(call=sections[this.sectionDragId].onreadystatechanged)call(sections[this.sectionDragId],sections[this.sectionDragId].readyState)
			sectionGroups[this.dragContainer].hideContent()
		}
	}
}

SectionGroup.prototype.sectionDragEnd=function sectionDragEnd(e,dontGroup)
{
	if(window.getSelection)window.getSelection().removeAllRanges();
	else if(document.selection)document.selection.empty();
	
	if(this.dragContainer)
	{
		var element=document.getElementById('container_'+this.dragContainer)
		element.className='container';
	}
	var uid=this.sectionDragId
	this.sectionDragHandler.remove()
	this.sectionDragHandler=null
	this.sectionDragEndHandler.remove()
	this.sectionDragEndHandler=null
	this.sectionDragLeaveHandler.remove()
	this.sectionDragLeaveHandler=null

	this.sectionDragOffsetTop=0
	this.sectionDragOffsetLeft=0
	this.sectionElement=null
	this.sectionDragId='';
	
	var to
	if(this.sectionDragging && (to=this.checkDragOver(e)))
	{
		if(!e.shiftKey)this.ungroupSections(this.dragContainer,to,dontGroup)
		else document.getElementById('container_'+to).className='container'
	}
	this.unhideContent()
	this.unhideContent2()
	this.dragContainer=''
	var wasDragging=this.sectionDragging
	this.sectionDragging=false;
	if(wasDragging)
	{
		sections[uid].readyState='dragEnd'
		if(call=sections[uid].onreadystatechanged)call(sections[uid],sections[uid].readyState)
		sections[uid].readyState='complete'
		if(call=sections[uid].onreadystatechanged)call(sections[uid],sections[uid].readyState)
	}
}

SectionGroup.prototype.sectionDragLeave=function sectionDragLeave(e)
{
	if(e.x<0 || e.y<0)
	{
		this.sectionDrag(e)
		this.sectionDragEnd(e,true)
	}
}


SectionGroup.prototype.checkDragOver=function SectionGroup_checkDragOver(e)
{
	var x,group,element,left,top,right,bottom,found=-1,foundId='';
		
		for(x in sectionGroups)
		{
			if(x!=this.dragContainer)
			{
				element=document.getElementById('container_'+(group=sectionGroups[x]).uid);
				left=element.offsetLeft;
				top=element.offsetTop;
				right=left+element.offsetWidth;
				bottom=top+element.offsetHeight;
				if(group.zIndex>found && (left<=e.x && right>=e.x && top<=e.y && bottom>=e.y))
				{
					found=group.zIndex;
					foundId=x;
				}
			}
		}
		var grouping=!(this.flags & SECTIONGROUP_NOGROUPING);
		if (foundId) var groupingOver=!(sectionGroups[foundId].flags & SECTIONGROUP_NOGROUPING);
		if(hideContentGroup!=foundId)
		{
			this.unhideContent2();
			if(foundId)sectionGroups[foundId].hideContent2();
		}
		if(dragOverGroup!=foundId)
		{
			if(dragOverGroup)
			{
				document.getElementById('container_'+dragOverGroup).className='container';
				dragOverGroup='';
			}
			if(grouping && groupingOver)
			{
				if(foundId)
				{
					document.getElementById('container_'+foundId).className='containerDragOver';
					dragOverGroup=foundId;
				}
				return dragOverGroup;
			}
			else return ''; 
		}
		return dragOverGroup;
}

SectionGroup.prototype.groupSection=function SectionGroup_groupSection(uid)
{
		var call;
		var group=this.parent.addSectionGroup(this.size.left,this.size.top,this.size.width,this.size.height,this.name,this.flags,this.minWidth,this.minHeight)	
		this.moveSection(uid,this.uid,group.uid)
		return group
}

SectionGroup.prototype.ungroupSections=function SectionGroup_ungroupSections(fromGroupId,toGroupId,dontGroup)
{
		if(!dontGroup)
		{
			var x,call=null;
			var fromGroup=sectionGroups[fromGroupId]
			var toGroup=sectionGroups[toGroupId]
			for(x in fromGroup.sections)
			{
				this.moveSection(x,fromGroupId,toGroupId)
			}
			this.parent.removeSectionGroup(fromGroupId)
		}
		else dragOverGroup=''
		document.getElementById('container_'+toGroupId).className='container'
}

SectionGroup.prototype.removeSection=function SectionGroup_deleteSection(uid)
{
	var element,ret,section=this.sections[uid]
	
	section.readyState='delete'
	if(call=section.onreadystatechanged)call(section,section.readyState)
		
	if(this.sectionShown==uid)
	{
		this.sectionShown=''
		this.sectionOpen=false;
	}
	
	delete this.sections[uid]
	delete sections[uid]
	this.sectionCount--;
	this.tabs.removeTab(section)
	if(element=document.getElementById(uid)) ret=document.getElementById('section_'+this.uid).removeChild(element)
	
	this.setSizeCheckTabs()
	return ret
}


SectionGroup.prototype.moveSection=function SectionGroup_moveSection(uid,fromGroupId,toGroupId)
{
	var toGroup=sectionGroups[toGroupId]
	var fromGroup=sectionGroups[fromGroupId]
	var section=sections[uid]
	var call=null;
	
	if(fromGroup.sectionShown==uid)
	{	
		fromGroup.sectionShown='';
		fromGroup.sectionOpen=false;
	}
	fromGroup.tabs.removeTab(section)
	delete fromGroup.sections[uid]

	fromGroup.sectionCount--
	var element=document.getElementById(section.uid)
	var contentNode=document.getElementById('sections_'+fromGroup.uid).removeChild(element)
	
	fromGroup.setSizeCheckTabs()
	section.readyState='removed'
	if(call=section.onreadystatechanged)call(section,section.readyState)

	
	if(fromGroup.sectionShown && fromGroup.sectionShown!=uid )section.sectionOpen=true;	
	
	if(section.sectionOpen && toGroup.sectionShown && !(section.flags & SECTION_NOTAB))
	{
		var secShown=sections[toGroup.sectionShown];
		toGroup.tabs.deselectTab(secShown);
		secShown.sectionOpen=false;
		toGroup.sectionShown='';
		toGroup.sectionOpen=false;
		if(call=secShown.onhide)call(secShown);

		document.getElementById(secShown.uid).style.display='none';
	}
	
	section.parent=toGroup;
	section.containerSize.left=toGroup.size.left
	section.containerSize.top=toGroup.size.top
	
	toGroup.sections[uid]=section;
	if((++toGroup.sectionCount)==1)section.sectionOpen=true
	

	if(section.flags & SECTION_NOSCROLL)contentNode.style.overflow='hidden'
	else contentNode.style.overflow='auto'
	
	if(editAppendFix)
	{
		var element=document.createElement('DIV')
		element.uid=uid;
		element.className='section'
		
		if(section.flags & SECTION_NOSCROLL)element.style.overflow='hidden'
		else element.style.overflow='auto'
		if(section.sectionOpen)element.style.display='block'	
		else element.style.display='none'	
		element.innerHTML=contentNode.innerHTML
		
		document.getElementById('section_'+toGroupId).appendChild(element)
		//if(this.parent.ondisplay && (call=section.ondisplay))call(section);
		if(this.parent.ondisplay && section.ondisplay)setTimeout('if(sectionGroups.'+toGroupId+')'+section.getCallStr()+'.ondisplay('+section.getCallStr()+');',0);
	}
	else
	{
		document.getElementById('sections_'+toGroupId).appendChild(contentNode)
	}
	
	toGroup.tabs.addTab(section)
	if(section.sectionOpen)
	{
		if(toGroup.sectionOpen)
		{
			var hideSection=sections[toGroup.sectionShown]
			if(this.parent.onhide && section.onhide)setTimeout('if(sectionGroups.'+toGroupId+')'+hideSection.getCallStr()+'.onhide('+hideSection.getCallStr()+');',0);
			//if(this.parent.onhide && (call=sections[toGroup.sectionShown].onhide))call(sections[toGroup.sectionShown]);
		}
		else toGroup.sectionOpen=true;
		toGroup.sectionShown=uid;
		toGroup.tabs.selectTab(section);
		document.getElementById(uid).style.display='block';
		if(this.parent.ondisplay && section.ondisplay)setTimeout('if(sectionGroups.'+toGroupId+')'+section.getCallStr()+'.ondisplay('+section.getCallStr()+');',0);
		//if(this.parent.ondisplay && (call=section.ondisplay))call(section);
	}
	toGroup.setSizeCheckTabs()
	
	section.readyState='added'
	if(call=section.onreadystatechanged)call(section,section.readyState)
	section.readyState='complete'
	if(call=section.onreadystatechanged)call(section,section.readyState)
}


SectionGroup.prototype.showSection=function SectionGroup_showSection(uid)
{
	var section,element,obj=null,obj2=null,call=null;
	if(obj=document.getElementById(uid))
	{	
		section=this.sections[this.sectionShown]
		if(this.sectionShown && !(section.flags & SECTION_NOTAB))
		{
			section.sectionOpen=false;
			if(obj2=document.getElementById(this.sectionShown))obj2.style.display='none';
			if(call=section.onhide)call(section);
		}
		
		if(this.sectionShown!=uid)
		{
			section=this.sections[uid]
			this.sectionShown=uid
			this.sectionOpen=true
			section.sectionOpen=true;
			obj.style.display='block'
			if(innerHTMLFix)obj.innerHTML=section.content
			if(section.flags & SECTION_NOSCROLL)obj.style.overflow='hidden'
			else obj.style.overflow='auto'
			if(this.parent.ondisplay && (call=section.ondisplay))
			{
				call(section)
			}
		}
		else this.sectionShown='';
		this.tabs.toggleSelectTab(sections[uid])
		this.toFront()
		this.setSizeCheckTabs(uid)
	}
}


function Section(parent,uid,name,flags,minWidth,minHeight)
{
	this.parent=(parent)?parent:null;
	this.uid=(uid)?uid:'';
	this.name=(name)?name:'';
	this.flags=(flags)?flags:0;
	this.minWidth=(minWidth)?minWidth:0;
	this.minHeight=(minHeight)?minHeight:0;
	
	this.containerSize=new ContainerSize()
	this.resizeFXSize=new ContainerSize();
	this.content='';
	this.ondisplay=null;
	this.onhide=null;
	this.oncontentloaded=null;
	this.onreadystatechanged=null;
	this.setup=null;
	this.contentLoaded=false;
	this.sectionOpen=false;
	this.contentHidden=false;
	this.readyState='';
}


Section.prototype.putStatusText=function Section_putStatusText(str,timeout)
{
	if(this.parent.statusTimer)
	{
		clearTimeout(this.parent.statusTimer)
		this.statusTimer=null;
	}
	element=document.getElementById('statusBarText_'+this.parent.uid);
	element.innerHTML=str;
	element.title=str;
	if(timeout)setTimeout(this.getCallStr()+'.clearStatusText()',timeout)
}

Section.prototype.clearStatusText=function Section_clearStatusText()
{
	this.parent.statusTimer=null;
	element=document.getElementById('statusBarText_'+this.parent.uid);
	element.title='';
	element.innerHTML='';
}

Section.prototype.hideSectionContent=function Section_hideSectionContent()
{
	this.contentHidden=true;
	var call;
	if(this.parent.onhide && (call=this.onhide))call()
	var obj=document.getElementById(this.uid)
	obj.style.visibility='hidden'
}

Section.prototype.showSectionContent=function Section_showSectionContent()
{
	this.contentHidden=false;
	if(this.parent.ondisplay && (call=this.ondisplay))call()
	var obj=document.getElementById(this.uid)
	obj.style.visibility='visible'
}


Section.prototype.showSection=function Section_showSection()
{
	var section,element,obj=null,obj2=null,call=null;
	var group=this.parent
	if(obj=document.getElementById(this.uid))
	{	
		if(group.sectionShown && !(this.flags & SECTION_NOTAB))
		{
			section=group.sections[group.sectionShown]
			section.sectionOpen=false;
			if(obj2=document.getElementById(section.uid))obj2.style.display='none';
			if(call=section.onhide)call(section);
		}
		
		if(group.sectionShown!=this.uid)
		{
			group.sectionShown=this.uid
			group.sectionOpen=true;
			this.sectionOpen=true;
			obj.style.display='block'
			if(innerHTMLFix)obj.innerHTML=this.content
			
			if(this.flags & SECTION_NOSCROLL)obj.style.overflow='hidden'
			else obj.style.overflow='auto'
			if(this.parent.parent.ondisplay && (call=this.ondisplay))
			{
				call(this)
			}
		}
		else 
		{
			group.sectionShown='';
			group.sectionOpen=false;
		}
		group.tabs.toggleSelectTab(sections[this.uid])
		group.toFront()
		group.setSizeCheckTabs(this.uid)
	}
}

Section.prototype.getCallStr=function Section_getCallStr()
{
	return 'sectionGroups.'+this.parent.uid+'.sections.'+this.uid
}

Section.prototype.loadContent=function loadContent()
{
	this.readyState='load'
	if(call=this.onreadystatechanged)call(this,this.readyState)
	GDownloadUrl('ui/section_'+this.uid+'.html',new Function('content','status',this.getCallStr()+'.loadContentCallback(content,status)'))
}


Section.prototype.loadContentCallback=function Section_loadContentCallback(content,status)
{
	if(!status || status==200)
	{
		var call;
		this.content=content;
		this.contentLoaded=true;
		document.getElementById(this.uid).innerHTML=content;
		this.parent.parent.sectionContentLoaded(this.uid)
		this.readyState='loaded';
		if(call=this.onreadystatechanged)call(this,this.readyState);
	}
	else alert('GDownloadUrl status: '+status+' section:'+this.uid);
}

function getBarSizes()
{
	resizeRightWidth=sizes.sectionsContainer.outerAllRight+sizes.container.outerAllRight-((scrollFix)?2:0);
	resizeLeftWidth=sizes.sectionsContainer.outerAllLeft+sizes.container.outerAllLeft;
	resizeTopWidth=sizes.bar.outerAllTop+sizes.container.outerAllTop;
	resizeBottomWidth=sizes.container.outerAllBottom+sizes.statusBar.height;//+sizes.statusBar.outerAllBottom
	stdMinHeight=sizes.statusBar.height+sizes.bar.height+sizes.tab.height+sizes.tabs.outerHeight+sizes.sections.outerAllHeight
	stdMinWidth=80
	barsHeightNoTabs=sizes.bar.height+sizes.statusBar.height+sizes.tabs.outerHeight
	barsHeight=sizes.bar.height+sizes.statusBar.height+Math.max(sizes.tabs.height,sizes.tab.height+sizes.tabs.outerHeight)
}

function sectionCleanUp()
{
	setCursorsMouseMoveHandler.remove()
	setCursorsMouseDownHandler.remove()
	setCursorsClickHandler.remove()
}


function sectionsSetup()
{
	getBarSizes()
	groups=new SectionGroups()
	groups.onBeforeSectionsSetup=function()
	{
		mapSetup()
		nodesTreeSetup();
		presetsSetup();
		setupSelectOptions()
	}

	setCursorsMouseMoveHandler=events.addListener('mousemove',function(e){groups.findContainerCall(e,'setCursors')});
	setCursorsMouseDownHandler=events.addListener('mousedown',function(e){groups.findContainerCall(e,'startResize')});
	setCursorsClickHandler=events.addListener('click',function(e){groups.findContainerCall(e,'toFront')});
	
	var sectionGroup,section;
	
	sectionGroup=groups.addSectionGroup(410,100,200,500,'Map',SECTIONGROUP_NOGROUPING)
		section=sectionGroup.addSection('map','Google Map',SECTION_NOTAB | SECTION_RESIZE | SECTION_NOSCROLL,null,75)
		sectionGroup.sectionOpen=true;
		sectionGroup.sectionShown='map';
		section.sectionOpen=true;
		section.setup=function(){}
		section.onresize=function(section,size){gmap.checkResize();mapMoveEnd()}
	
	sectionGroup=groups.addSectionGroup(520,5,220,455)
		section=sectionGroup.addSection('mapEdit','Map Settings',SECTION_RESIZE)
		section.setup=function(){mapEditSetup();}
		section.ondisplay=function(section){putMapEdit()}
		section.oncontentloaded=function(section){}//section.showSection();}
	
		section=sectionGroup.addSection('icons','Marker Icons',SECTION_RESIZE | SECTION_NOSCROLL)
		section.setup=function(){iconSetup()}
		section.onresize=function(section,size)
		{
			var element=document.getElementById('iconListContainer')
			element.style.height=(Math.max(0,size.height-40-sizes.grouping.outerHeight-sizes.iconListContainer.outerAllHeight))+'px';
			element.style.width=(Math.max(0,size.width-sizes.iconListContainer.outerAllWidth))+'px';
			element=document.getElementById('iconList')
			element.style.height=(Math.max(0,size.height-40-sizes.grouping.outerHeight-sizes.iconList.outerAllHeight))+'px';
			element.style.width=(Math.max(0,size.width-sizes.iconList.outerAllWidth))+'px';
		}
		section.ondisplay=function(section){putIconLists()}
		section.oncontentloaded=function(section){}//section.showSection();
	
	
	sectionGroup=groups.addSectionGroup(5,5,500,480)
	
		section=sectionGroup.addSection('nodeList','Nodes',SECTION_RESIZE | SECTION_NOSCROLL)
		section.setup=function(){nodesSetup()}
		section.oncontentloaded=function(section){section.showSection();}
		section.ondisplay=function(section){putNodes()}
		section.onresize=function(section,size)
		{
			var element=document.getElementById('nodeTreeContainer')
			element.style.height=(Math.max(0,size.height-80-sizes.grouping.outerHeight-sizes.nodeTreeContainer.outerAllHeight))+'px';
			element.style.width=(Math.max(0,size.width-sizes.nodeTreeContainer.outerAllWidth))+'px';
			element=document.getElementById('nodeTree')
			element.style.height=(Math.max(0,size.height-80-sizes.grouping.outerHeight-sizes.nodeTree.outerAllHeight))+'px';
			element.style.width=(Math.max(0,size.width-sizes.nodeTree.outerAllWidth))+'px';
		}
	
		sectionGroup=groups.addSectionGroup(745,5,480,500)
				
		section=sectionGroup.addSection('infoWindowSimple','Simple Info',SECTION_RESIZE)
		section.setup=function(){markerInfoWindowSimpleSetup(markerPresetUid)}
		section.ondisplay=function(section){markerPutInfoSimple(markerCurrentNode)}
		section.oncontentloaded=function(section){/*section.showSection()*/}
		section.onresize=function(section,size)
		{
			var element=document.getElementById('infoWindowSimple');
			var width=Math.max(0,size.width-sizes.editIFrame.outerAllWidth-(((element.offsetHeight-element.scrollHeight)<0)?18:0))
			element=document.getElementById('markerInfoSimpleEdit');
			element.style.width=width+'px';
		}
	
	
		section=sectionGroup.addSection('infoWindowTabbed','Tabbed Info',SECTION_RESIZE)
		section.setup=function(){markerInfoTabbedSetup(markerPresetUid)}
		section.ondisplay=function(section){markerPutInfoTabbed(markerCurrentNode)}
		section.oncontentloaded=function(section){/*section.showSection()*/}
		section.onresize=function(section,size)
		{
			var element=document.getElementById('infoWindowTabbed');
			var width=Math.max(0,size.width-sizes.editIFrame.outerAllWidth-(((element.offsetHeight-element.scrollHeight)<0)?18:0))
			element=document.getElementById('markerInfoTabbedEdit')
			element.style.width=width+'px';
		}

		section=sectionGroup.addSection('infoWindowBlowup','Map Blowup Info',SECTION_RESIZE)
		section.setup=function(){markerInfoWindowBlowupSetup(markerPresetUid)}
		section.ondisplay=function(section){markerPutInfoBlowup(markerCurrentNode)}
		section.oncontentloaded=function(section){/*section.showSection()*/}
		
		section=sectionGroup.addSection('marker','Marker',SECTION_RESIZE)
		section.setup=function(){nodeMarkerSetup(markerPresetUid)}
		section.ondisplay=function(section){markerPutNode()}
		section.oncontentloaded=function(section){/*section.showSection()*/};
		section.onresize=function(section,size)
		{
			var element=document.getElementById('infoWindowBlowup');
			var width=Math.max(0,size.width-sizes.grouping.outerAllWidth-(((element.offsetHeight-element.scrollHeight)<0)?18:0)-((inputWidthFix)?7:0))
			element=document.getElementById('markerAddress');
			element.style.width=width+'px';
			element=document.getElementById('title');
			element.style.width=width+'px';
			element=document.getElementById('markerName');
			element.style.width=width+'px';
		}
	
		section=sectionGroup.addSection('group','Group',SECTION_RESIZE)
		section.setup=function(){groupSetup(groupPresetUid)}
		section.ondisplay=function(section){groupPutNode()}
		section.oncontentloaded=function(section){/*section.showSection()*/};
		section.onresize=function(section,size)
		{
			var element=document.getElementById('group');
			var width=Math.max(0,size.width-sizes.grouping.outerAllWidth-(((element.offsetHeight-element.scrollHeight)<0)?18:0)-((inputWidthFix)?7:0))
			element=document.getElementById('groupName');
			element.style.width=width+'px';
			element=document.getElementById('groupAddress');
			element.style.width=width+'px';
		}

		section=sectionGroup.addSection('polygon','Polygon',SECTION_RESIZE)
		section.setup=function(){nodePolygonSetup(polygonPresetUid)}
		section.ondisplay=function(section){polygonPutNode()}
		section.oncontentloaded=function(section){};
		section.onresize=function(section,size)
		{
			var element=document.getElementById('polygon');
			var width=Math.max(0,size.width-sizes.grouping.outerAllWidth-(((element.offsetHeight-element.scrollHeight)<0)?18:0)-((inputWidthFix)?7:0))
			element=document.getElementById('polygonName');
			element.style.width=width+'px';
			element=document.getElementById('polygonAddress');
			element.style.width=width+'px';
		}

		section=sectionGroup.addSection('overlay','Overlay',SECTION_RESIZE)
		section.setup=function(){overlaySetup(overlayPresetUid)}
		section.ondisplay=function(section){overlayPutNode()}
		section.oncontentloaded=function(section){section.showSection()};
		section.onresize=function(section,size)
		{
			var element=document.getElementById('overlay');
			var scrollBar=(((element.offsetHeight-element.scrollHeight)<0)?18:0)
			var width=Math.max(0,size.width-sizes.grouping.outerAllWidth-scrollBar-((inputWidthFix)?7:0))
			element=document.getElementById('overlayName');
			element.style.width=width+'px';
			element=document.getElementById('overlayAddress');
			element.style.width=width+'px';
			element=document.getElementById('overlayHTMLEdit');
			width=Math.max(0,size.width-sizes.editIFrame.outerAllWidth-scrollBar)
			element.style.width=width+'px';
		}
	sectionGroup=groups.addSectionGroup(5,520,610,300)
	
		section=sectionGroup.addSection('search','Search',SECTION_RESIZE | SECTION_NOSCROLL)
		section.setup=function(){searchSetup();}
		section.oncontentloaded=function(section){}//section.showSection()}
		section.ondisplay=function(section){}
		section.onresize=function(section,size)
		{
			var element=document.getElementById('searchResultsContainer')
			element.style.height=(Math.max(0,size.height-24-sizes.searchResultsContainer.outerAllHeight))+'px';
			element.style.width=(Math.max(0,size.width-sizes.searchResultsContainer.outerAllWidth))+'px';
			element=document.getElementById('searchResults')
			element.style.height=(Math.max(0,size.height-24-sizes.searchResults.outerAllHeight))+'px';
			element.style.width=(Math.max(0,size.width-sizes.searchResults.outerAllWidth))+'px';
		}
	
		
		section=sectionGroup.addSection('message','Test',SECTION_RESIZE)
		sectionGroup.sectionOpen=true;
		section.sectionOpen=true;
		section.oncontentloaded=function(section){section.showSection()};
		section.setup=function(){}
		/*section.onresize=function(section,size)
		{
			var width=Math.max(0,size.width-sizes.grouping.outerAllWidth)
			var height=Math.max(0,size.width-sizes.grouping.outerAllHeight)
			var element=document.getElementById('messageContent');
			element.style.width=width+'px';
			element.style.height=height+'px';
		}*/


		/*section=sectionGroup.addSection('amusement','Amusement',SECTION_RESIZE)
		sectionGroup.sectionOpen=true;
		section.sectionOpen=true;
		section.oncontentloaded=function(section){};
		section.setup=function(){}
		section.onresize=function(section,size)
		{
			var width=Math.max(0,size.width-sizes.grouping.outerAllWidth)
			var height=Math.max(0,size.width-sizes.grouping.outerAllHeight)
			var element=document.getElementById('messageContent');
			element.style.width=width+'px';
			element.style.height=height+'px';
		}*/
	groups.loadSectionsContent()
	
}
