var wc_re = /\bwindowContainer\b/
var wb_re = /\bwindowBody\b/

function tg_wnd(context) {
return function(e) {
	e = Event(e)
	var c = find_class(e.target,wc_re)
	var o = find_class_down(c,wb_re)
	if(isHide(o))
		{ showE(o)
			c.style.top = (c.offsetTop -1)
			c.style.top = (c.offsetTop +1) 
			context && context.onshow && context.onshow(); 
		}
	else
		{ hideE(o); context && context.onhide && context.onhide(); }
	}
}
	
function wnddrag(context) {
	return DnDProcessor({ root: context.root || function(elem) { find_class(elem,wc_re) }, 
					v:{min:0}, h: {min:0}, button: 0,
					ondrop: function() {context && context.onmoved && context.onmoved() }
		})
}

regAttach(["SPAN", {'class':/\bwindowMinBtn\b/}], [ 
	html.span({'class':"windowBtnDot windowBtnDot11"}),
	html.span({'class':"windowBtnDot windowBtnDot12"}),
	html.span({'class':"windowBtnDot windowBtnDot21"}),
	html.span({'class':"windowBtnDot windowBtnDot22"}),
	html.span({'class':"windowBtnpl"}),
])

regAttach(["DIV", {win:"min"} ], 
function (mapper, elem) {
	var ss = make_children_subst(elem,[{ win:"title" }] )
	elem.className += " windowContainer"
	var context = eval(elem.getAttribute("onwinevents")) || {}
	context.root = elem
	return html.table.nospace(html.tbody(
		html.tr( html.td(
				html.table.nospace({width:"100%", 'class': "windowTitleRow"})(html.tbody(
					html.tr(
						html.td( html.div({'class':"windowTitle", onmousedown: wnddrag(context)} ) (subst_child(ss,0))),
						html.td({width:"12"})( html.span({'class':"windowMinBtn", onmousedown: tg_wnd(context) } ))
					)
				))
			)
		),
		html.tr( html.td(
				html.div({'class':"windowBody", style: context.closed?"display:none":"display:block"}) (subst_child(ss))
			)
		)
	))
} )

regAttach(["A", {href:"menu:"} ], 
function (mapper, elem) {
	elem.href = "#"
	var context = eval(elem.getAttribute("param")) || {}
	elem.onclick = MenuProcessor(context)
} )
