# 

var enBoth=4, enHdr=1, enBody=2, enBot=6, enPlain=3, enNone=5, enHdr2=7, enBody2=8, enBody3=9;


# Allow us to easily use the inner or outer description of panelised divs
function panel_correct(node,type)
{
	if (type==undefined)
		type='outer';
	if (type=='inner' && node.panelised_inner)
		node=node.panelised_inner;
	if (type=='outer' && node.panelised_outer)
		node=node.panelised_outer;
	return node;
}


function panelise_roundtop(node,type,nogap){
	var outer,moveto;
	outer=document.createElement("div");
	outer.id=node.id+'_outer';
	switch(type){
	case enHdr:
		outer.innerHTML='<div class="'+(nogap?'':'panel_inset')+'"><div class="rnd2"></div><div class="rnd1"></div><div class="nornd">'
							+ '<div class="border_lift_left"></div>'
							+ '</div><div class=""></div><div class=""></div></div>';	
		moveto=outer.firstChild.firstChild.nextSibling.nextSibling.firstChild;
		break;
	case enBody:
		outer.innerHTML='<div class="border_plain '+(nogap?'':'panel_inset_flushtop')+'"></div>';	
		moveto=outer.firstChild;
	case enPlain:
		outer.innerHTML='<div class="border_plain '+(nogap?'':'panel_inset')+'"></div>';	
		moveto=outer.firstChild;
		break;
	}
	node.parentNode.insertBefore(outer,node);
	moveto.appendChild(node);
	node.panelised_outer=outer;
	outer.panelised_inner=node;
	if (class_contains(node,'hidden')){
		class_remove(node,"hidden");
		class_add(outer,"hidden");
	}
}



function panelise_round(node,type){
	var outer,moveto;
	outer=document.createElement("div");
	outer.id=node.id+'_outer';
	switch (type){
	case enBoth:
		outer.innerHTML='<div class="panel_inset"><div class="rnd2"></div><div class="rnd1"></div><div class="nornd"></div><div class="rnd1"></div><div class="rnd2"></div></div>';	
		moveto=outer.firstChild.firstChild.nextSibling.nextSibling;
		break
	case enHdr:
		outer.innerHTML='<div class="panel_inset"><div class="rnd2"></div><div class="rnd1"></div><div class="nornd"></div><div class="rnd1"></div><div class="rnd2"></div></div>';	
		moveto=outer.firstChild.firstChild.nextSibling.nextSibling;
		break;
	case enBody:
		outer.innerHTML='<div class="border_plain panel_inset_flushtop"></div>';	
		moveto=outer.firstChild;
		break;
	case enPlain:
		outer.innerHTML='<div class="border_plain panel_inset"></div>';	
		moveto=outer.firstChild;
		break
	case enNone:
		outer.innerHTML='<div class="panel_inset"></div>';	
		moveto=outer.firstChild;
		break;
	}
	node.parentNode.insertBefore(outer,node);
	moveto.appendChild(node);
	node.panelised_outer=outer;
	outer.panelised_inner=node;
	if (class_contains(node,'hidden')){
		class_remove(node,"hidden");
		class_add(outer,"hidden");
	}
}


function panelise_undo(node)
{
	var inner, outer;
	inner=panel_correct(node,'inner');
	outer=panel_correct(node,'outer');
	if(inner==outer)return;
	outer.parentNode.insertBefore(inner,outer);
	outer.parentNode.removeChild(outer);
	return node;
}


function panelise_square(node,type,nogap){
	var outer,moveto;
	outer=document.createElement("div");
	outer.id=node.id+'_outer';
	
	switch(type){
	case enBoth:
		outer.innerHTML='<div class="border_plain '+(nogap?'':'panel_inset')+'"><div class="border_lift"></div></div>';	
		moveto=outer.firstChild.firstChild;
		break;
	case enHdr:
		outer.innerHTML='<div class="border_top3 '+(nogap?'':'panel_inset')+'"><div class="border_lift"></div></div>';	
		moveto=outer.firstChild.firstChild;
		break;
	case enBody:
		outer.innerHTML='<div class="border_plain '+(nogap?'':'panel_inset_flushtop')+'"></div>';	
		moveto=outer.firstChild;
		break;
	case enBody3:
		outer.innerHTML='<div class="border_plain_b4footer '+(nogap?'':'panel_inset_flushtop')+'"></div>';	
		moveto=outer.firstChild;
		break;
	case enBot:
		outer.innerHTML='<div class="border_plain border_plain_notop '+(nogap?'':'panel_inset_flushtop')+'"></div>';	
		moveto=outer.firstChild;
		break;		
	case enPlain:
		outer.innerHTML='<div class="border_plain '+(nogap?'':'panel_inset')+'"></div>';	
		moveto=outer.firstChild;
		break;
	case enNone:
		outer.innerHTML='<div class="panel_inset"></div>';	
		moveto=outer.firstChild;
		break;
	}

	node.parentNode.insertBefore(outer,node);
	moveto.appendChild(node);
	node.panelised_outer=outer;
	outer.panelised_inner=node;
	if (class_contains(node,'hidden')){
		class_remove(node,"hidden");
		class_add(outer,"hidden");
	}
}

function panelise_pad(node,type,nogap){
	var outer,moveto;
	outer=document.createElement("div");
	outer.id=node.id+'_outer';
	
	switch(type){
	case enHdr:
		outer.innerHTML='<div class="'+(nogap?'':'panel_inset')+'"><div></div></div>';	
		moveto=outer.firstChild.firstChild;
		break;
	}

	node.parentNode.insertBefore(outer,node);
	moveto.appendChild(node);
	node.panelised_outer=outer;
	outer.panelised_inner=node;
	if (class_contains(node,'hidden')){
		class_remove(node,"hidden");
		class_add(outer,"hidden");
	}
}

function panelise_plain(node,type){
	var outer,moveto;
	if(!node) return;
	outer=document.createElement("div");
	outer.id=node.id+'_outer';
	
	switch(type){
	case enHdr:
		outer.innerHTML='<div class="border_top3"><div class="border_lift"></div></div>';	
		moveto=outer.firstChild.firstChild;
		break;
	case enHdr2:
		outer.innerHTML='<div class="border_plain border_plain_topright"><div class="border_lift"></div></div>';	
		moveto=outer.firstChild.firstChild;
		break;
	case enBody:
		outer.innerHTML='<div class="border_plain"></div>';	
		moveto=outer.firstChild;
		break;
	case enBody2:
		outer.innerHTML='<div class="border_plain border_plain_topright"></div>';	
		moveto=outer.firstChild;
		break;
	case enBody3:
		outer.innerHTML='<div class="border_plain_b4footer"></div>';	
		moveto=outer.firstChild;
		break;
	case enBot:
		outer.innerHTML='<div class="border_plain border_plain_notop"></div>';	
		moveto=outer.firstChild;
		break;		
	}

	node.parentNode.insertBefore(outer,node);
	moveto.appendChild(node);
	node.panelised_outer=outer;
	outer.panelised_inner=node;
	if (class_contains(node,'hidden')){
		class_remove(node,"hidden");
		class_add(outer,"hidden");
	}
}


function get_panel_node(txt,type)
{
	var node=document.getElementById(txt);
	if (type=="outer" && node.panelised_outer){
		return node.panelised_outer;
	}else{
		return node;
	}
}

# This is a bit of a hack... but will do for now, lets see if we can improve later
function set_panel_bottom_border_color(node,col)
{
	var node2=panel_correct(node);
	if (node2 && node2!=node){
		var tweak=node2.lastChild.lastChild.previousSibling;
		if (tweak) {
			tweak.style.background=col;
		}
	}
}

function panelise_none(node,type){
	node.panelised_inner=node;
	node.panelised_outer=node;
}