// DynWindow Object
// a widget-object that creates a draggable window with a Scroll to mimic an OS window

// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynduo/

function DynWindow(name,x,y,width,height) {
	this.name = "DynWindow"+(DynWindow.count++)
	this.x = x
	this.y = y
	this.w = width
	this.h = height
	this.title = ''
	this.visibility = 'inherit'
	this.zIndex = null
	this.obj = this.name + "DynWindowObject"
	eval(this.obj + "=this")
	this.built = false
	
	this.scroll = new Scroll(0,0,this.w-15,this.h-20)
	this.scroll.setDimensions(0,0,15,this.scroll.h,14,15,29,1)
	this.scroll.clipImages = false
	this.scroll.setImages('scroll-img-box0.gif','scroll-img-box1.gif','scroll-img-up0.gif','scroll-img-up1.gif','scroll-img-dn0.gif','scroll-img-dn1.gif','scroll-img-bar.gif','../Images/')
	this.scroll.build(false)
	
	this.closeImg0 = new Image()
	this.closeImg0.src = "../Images/window-close0.gif"
	this.closeImg1 = new Image()
	this.closeImg1.src = "../Images/window-close1.gif"
	this.minImg0 = new Image()
	this.minImg0.src = "../Images/window-min0.gif"
	this.minImg1 = new Image()
	this.minImg1.src = "../Images/window-min1.gif"
	
	this.setTitle = DynWindowSetTitle
	this.activate = DynWindowActivate
	this.build = DynWindowBuild

	this.minimizeDown = DynWindowMinimizeDown
	this.minimize = DynWindowMinimize
	this.closeDown = DynWindowCloseDown
	this.close = DynWindowClose
}
function DynWindowBuild(write) {

	this.css = (write!=false)? css('START'):''
	this.css += css(this.name+'DynWindow',this.x,this.y,this.w,this.h,null,this.visibility,this.zIndex)+
	css(this.name+'Titlebar1',0,0,this.w,18,'#000000')+
	css(this.name+'Titlebar2',1,1,this.w-2,17,'#2A5E89')+
	css(this.name+'TitlebarE',0,0,this.w,18)+
	css(this.name+'Title',18,2,this.w-36,null,'transparent')+
	css(this.name+'Min',0,0,18,18)+
	css(this.name+'MinE',0,0,18,18)+
	css(this.name+'Close',this.w-18,0,18,18)+
	css(this.name+'CloseE',this.w-18,0,18,18)+
	css(this.name+'Content',0,18,this.w,this.h-20,'#FFFFCC')+
	this.scroll.css
	if (write!=false) {
		this.css += css('END')
		document.write(this.css)
	}
	this.div = '<DIV ID="'+this.name+'DynWindow">\n'+
	'<DIV ID="'+this.name+'Titlebar1">\n'+
	'<DIV ID="'+this.name+'Titlebar2"></DIV>\n'+
	'</DIV>\n'+
	'<DIV ID="'+this.name+'Title"></DIV>\n'+
	'<DIV ID="'+this.name+'TitlebarE"></DIV>\n'+
	'<DIV ID="'+this.name+'Min"><IMG NAME="'+this.name+'MinImg" SRC="../Images/window-min0.gif" WIDTH=18 HEIGHT=18></DIV>\n'+
	'<DIV ID="'+this.name+'Close"><IMG NAME="'+this.name+'CloseImg" SRC="../Images/window-close0.gif" WIDTH=18 HEIGHT=18></DIV>\n'+
	'<DIV ID="'+this.name+'MinE"></DIV>\n'+
	'<DIV ID="'+this.name+'CloseE"></DIV>\n'+
	'<DIV ID="'+this.name+'Content">\n'+
	this.scroll.div+
	'</DIV>\n'+
	'</DIV>\n'
	this.built = true
}
function DynWindowActivate() {
	this.lyr = new DynLayer(this.name+'DynWindow')
	this.titlelyr = new DynLayer(this.name+'Title')
	this.titlelyr.write = DynLayerWrite
	this.minl = new DynLayer(this.name+'Min')
	this.minlyr = new DynLayer(this.name+'MinE')
	if (is.ns) this.minlyr.event.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK)
	this.minlyr.event.onmousedown = new Function(this.obj+'.minimizeDown(); return false;')
	this.minlyr.event.onmouseup = new Function(this.obj+'.minimize(); return false;')
	this.closel = new DynLayer(this.name+'Close')
	this.closelyr = new DynLayer(this.name+'CloseE')
	if (is.ns) this.closelyr.event.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.CLICK)
        this.closel.event.onmousedown = new Function(this.obj+'.closeDown(); return false;')
	this.closelyr.event.onmouseup = new Function(this.obj+'.close(); return false;')
        eval('drag.add('+this.obj+'.lyr)')
	eval('drag.setGrab('+this.obj+'.lyr,0,264,18,18)')
}
function DynWindowMinimizeDown() {
	this.minl.doc.images[this.name+"MinImg"].src = this.minImg1.src
}
function DynWindowMinimize() {
	this.minl.doc.images[this.name+"MinImg"].src = this.minImg0.src
	this.lyr.hide()
}
function DynWindowCloseDown(){
	this.closel.doc.images[this.name+"CloseImg"].src = this.closeImg1.src
}
function DynWindowClose() {
	this.closel.doc.images[this.name+"CloseImg"].src = this.closeImg0.src
	this.lyr.hide()
}
function DynWindowSetTitle(title) {
	this.title = title
	if (this.built) this.titlelyr.write('<DIV ALIGN="CENTER" CLASS="windowTitleStyle">'+this.title+'</DIV>')
}
DynWindow.count = 0
