/*
MyWindow 2006.3 (20060722)

Copyright (c)2006 Carsten Ruppert - carsten.ruppert-at-web.de
*/

var _mywinXgif = '../img/mywindow/blank.gif'; // transparentes gif (!!!) - geht im mozilla auch ohne
//var _mywinXgif = './grid.png'; // kann man mal aus spass benutzen...
function mywindow(cid,w,h,x,y,z,windowname,scrollbars,moveable,resizeable,closeable,basics,classprefix) {
	
	var mywin = this;
	this.content = document.getElementById(cid);

	this.w = w;
	this.h = h;
	this.x = x;
	this.y = y;
	this.z = z;
	
	this.minheight = 200;
	this.minwidth = 200;
	
	this.scrollbars = scrollbars;
	this.resizeable = resizeable;
	this.statusbar = false;
	this.moveable = moveable;
	this.basics = basics; 
	this.closeable = closeable;
	this.skin = new Array();
	this.windowname = windowname;
	this.status = 'normalmode';

	this._btnposxd = new Array(0,0,0); // vorgabe button postionen min,max,close
	this._btnposx = new Array(0,0,0); // tatsaechliche x positionen der buttons
	this._btnposy = new Array(); // y positionen der buttons
	
	this.classprefix = classprefix ? classprefix : 'mywin'; // Skin
	this.restore;	


	// 22.05.2006
	this.tellWindow = function (what) {
		// Sag dem fenster was es tun soll, in der eingabereihenfolge
		var told = what.split(" ");
		var c = 0; var cmd = told[c];
		do {
			switch (cmd) {
				case 'close' : mywin.closeWin(); break;
				case 'maximize' : mywin.maximize();	break;
				case 'minimize' : mywin.minimize();	break;
				case 'reset' : mywin.reSet(); break;
				default : return;
				}
			++c;
			} while (cmd = told[c]);
		}

	this.prevMarking = function (ev) {
		return false;
		}	
	
	this.move = function (ev) {
		// bewegt sich gerade
		mywin.moveing = true;
		// clipping zone ausdehnen
		mywin._mclipzone.style.left = '0px'; mywin._mclipzone.style.top = '0px';
		mywin._mclipzone.style.width = '100%'; mywin._mclipzone.style.zIndex = 5000;
		
		// 1.0.1 - cursor position in der titelleiste bei click
		var ydif = (document.documentElement) ? document.documentElement.scrollTop : 0; // y differenz im IE
		mywin._citbx = ev.clientX - mywin.x;
		mywin._citby = (ev.clientY + ydif) - mywin.y;

		
		if ( window.innerHeight ) {
			mywin._mclipzone.style.height = window.innerHeight + 'px';
			}
		else {
			mywin._mclipzone.style.height = (document.documentElement) ? document.documentElement.scrollHeight + 'px' : '100%';
			}
		// Bewegen starten
		if ( mywin._mclipzone.addEventListener ) {
			mywin._mclipzone.removeEventListener('mousedown',mywin.move,false);
			mywin._mclipzone.addEventListener('mouseup',mywin.stopp,false);
			mywin._mclipzone.addEventListener('mousemove',mywin.follow,false);			
			}
		else {
			document.body.attachEvent('onselectstart',mywin.prevMarking);
			mywin._mclipzone.detachEvent('onmousedown',mywin.move);
			mywin._mclipzone.attachEvent('onmouseup',mywin.stopp);
			mywin._mclipzone.attachEvent('onmousemove',mywin.follow);						
			}
		}
	this.stopp = function(ev) {
		mywin.moveing = false;
		// clipping zone zusammenfalten
		void mywin.setClipZones();
		
		// Bewegen stoppen
		if ( mywin._mclipzone.addEventListener ) {
			mywin._mclipzone.addEventListener('mousedown',mywin.move,false);
			mywin._mclipzone.removeEventListener('mousemove',mywin.follow,false);
			mywin._mclipzone.removeEventListener('mouseup',mywin.stopp,false);
			}
		else {
			document.body.detachEvent('onselectstart',mywin.prevMarking);
			mywin._mclipzone.attachEvent('onmousedown',mywin.move);
			mywin._mclipzone.detachEvent('onmousemove',mywin.follow);
			mywin._mclipzone.detachEvent('onmouseup',mywin.stopp);
			}
		}
	this.follow = function(ev) {
		var x, y;
		var ydif = (document.documentElement) ? document.documentElement.scrollTop : 0;
		if ( ev.clientX ) {
			x = ev.clientX;	y = ev.clientY + ydif;
			}
		x -= mywin._citbx;
		y -= mywin._citby;
		mywin.moveTo (x,y);
		}
	this.resize = function(ev) {
		// clipping zone ausdehnen...
		mywin._rclipzone.style.top = '0px';	mywin._rclipzone.style.left = '0px';
		mywin._rclipzone.style.width = '100%'; mywin._rclipzone.style.zIndex = 5000;

		if ( window.innerHeight ) { mywin._rclipzone.style.height = window.innerHeight + 'px'; }
		else { mywin._rclipzone.style.height = (document.documentElement) ? document.documentElement.scrollHeight + 'px' : '100%';}		

		// resize starten
		if ( mywin._rclipzone.addEventListener ) {
			mywin._rclipzone.removeEventListener('mousedown',mywin.resize,false);
			mywin._rclipzone.addEventListener('mouseup',mywin.stopResize,false);
			mywin._rclipzone.addEventListener('mousemove',mywin.growShrink,false);
			}
		else {
			document.body.attachEvent('onselectstart',mywin.prevMarking);
			mywin._rclipzone.detachEvent('onmousedown',mywin.resize);
			mywin._rclipzone.attachEvent('onmouseup',mywin.stopResize);
			mywin._rclipzone.attachEvent('onmousemove',mywin.growShrink);
			}
		}
	this.stopResize = function(ev) {
		// clipping zone zusammenziehen
		void mywin.setClipZones();

		// resize beenden 
		if ( mywin._rclipzone.addEventListener ) {
			mywin._rclipzone.removeEventListener('mouseup',mywin.stopResize,false);
			mywin._rclipzone.removeEventListener('mousemove',mywin.growShrink,false);			
			mywin._rclipzone.addEventListener('mousedown',mywin.resize,false);
			}
		else {
			document.body.detachEvent('onselectstart',mywin.prevMarking);
			mywin._rclipzone.detachEvent('onmouseup',mywin.stopResize);
			mywin._rclipzone.detachEvent('onmousemove',mywin.growShrink);			
			mywin._rclipzone.attachEvent('onmousedown',mywin.resize);			
			}
		}
	this.growShrink = function(ev) {
		// zur cursor position schrumpfen oder wachsen
		var x, y;
		var ydif = (document.documentElement) ? document.documentElement.scrollTop : 0;
		if ( ev.clientX ) {x = ev.clientX;	y = ev.clientY + ydif;}
		else {x = ev.pageX; y = ev.pageY + ydif;}

		var nw = (x - (mywin.w + mywin.x)) + mywin.w; // neue breite
		var nh = (y - (mywin.h + mywin.y)) + mywin.h; // neue hoehe
		
		// minimale breite und hoehe
		mywin.w =  ( nw <= mywin.minwidth ) ? mywin.w : nw;
		mywin.h = ( nh <= mywin.minheight ) ? mywin.minheight : nh; // kaputt?!
		mywin.win.style.width = mywin.w + 'px';
		mywin.win.style.height = mywin.h + 'px';

		// statusleiste bewegen
		if ( mywin.statusbar ) {
			mywin.winstatus.style.left = mywin.x + 'px';
			mywin.winstatus.style.top = mywin.y + mywin.h - mywin.statusheight + 'px';
			mywin.winstatus.style.width = mywin.w + 'px';
			}
		// Content groesse setzen
		mywin._wintitle.style.width = mywin.getTitleWidth() + 'px';
		mywin.content.style.width = mywin.getContentWidth() + 'px';
		mywin.content.style.height = mywin.getContentHeight() + 'px';
		void mywin.setButtons();
		}

	this.maximize = function (ev) {
		mywin.restore = new Array(mywin.w,mywin.h,mywin.x,mywin.y);
		mywin.status = 'maximode';

		mywin.w = (window.innerWidth ? window.innerWidth : document.body.offsetWidth) - 30;
		mywin.win.style.width = mywin.w + 'px';
		mywin.h = (window.innerHeight ? window.innerHeight : document.documentElement.scrollHeight) - 30;
		mywin.win.style.height = mywin.h + 'px';

		mywin.x = 5; mywin.y = 5;
		mywin.win.style.left = mywin.x + 'px';
		mywin.win.style.top = mywin.y + 'px';
		
		// Content groesse setzen
		mywin._wintitle.style.width = mywin.getTitleWidth() + 'px';
		mywin.content.style.width = mywin.getContentWidth() + 'px';
		mywin.content.style.height = mywin.getContentHeight() + 'px';

		document.body.removeChild(mywin._btnmax);
		document.body.removeChild(mywin._btnmin);
		document.body.appendChild(mywin._btnreset);

		mywin.setClipZones();
		if ( mywin._mclipzone.attachEvent ) {
			mywin._mclipzone.detachEvent('onmousedown',mywin.move);
			mywin._mclipzone.detachEvent('ondblclick',mywin.maximize);
			mywin._mclipzone.attachEvent('ondblclick',mywin.reSet);
			}
		else {
			mywin._mclipzone.removeEventListener('mousedown',mywin.move,false);
			mywin._mclipzone.removeEventListener('dblclick',mywin.maximize,false);
			mywin._mclipzone.addEventListener('dblclick',mywin.reSet,false);
			}

		void mywin.setButtons();
		mywin.status = 'maximode';
		}
	this.minimize = function (ev) {
		mywin.restore = new Array(mywin.w,mywin.h,mywin.x,mywin.y);
		mywin.status = 'minimode';

		mywin.w = mywin._btnposxd[2] + 100;
		mywin.win.style.width = mywin.w + 'px';
		
		mywin.h = mywin.statusbar ? mywin.headheight + mywin.statusheight : mywin.headheight;
		mywin.win.style.height = mywin.h + 'px';
		
		mywin.y = 0;
		mywin.win.style.top = mywin.y + 'px';

		if ( mywin.statusbar ) {
			mywin.winstatus.style.left = mywin.x + 'px';
			mywin.winstatus.style.top = mywin.y + mywin.h - mywin.statusheight + 'px';
			mywin.winstatus.style.width = mywin.w + 'px';
			}
		mywin._wintitle.style.width = mywin.getTitleWidth() + 'px';
			
		document.body.removeChild(mywin._btnmax);
		document.body.removeChild(mywin._btnmin);
		document.body.appendChild(mywin._btnreset);
		void mywin.setButtons();
		
		if ( mywin._mclipzone.attachEvent ) {
			mywin._mclipzone.detachEvent('ondblclick',mywin.maximize);
			mywin._mclipzone.attachEvent('ondblclick',mywin.reSet);
			}
		else {
			mywin._mclipzone.removeEventListener('dblclick',mywin.maximize,false);
			mywin._mclipzone.addEventListener('dblclick',mywin.reSet,false);
			}
		void mywin.setClipZones();
		
		mywin.content.style.width = 0;
		mywin.content.style.height = 0;
		mywin.status = 'minimode';
		}
	this.reSet = function(ev) {
		mywin.w = mywin.restore[0];
		mywin.win.style.width = mywin.w + 'px';
		
		mywin.h = mywin.restore[1];
		mywin.win.style.height = mywin.h + 'px';
		
		mywin.x = mywin.restore[2];
		mywin.win.style.left = mywin.x + 'px';
		
		mywin.y = mywin.restore[3];
		mywin.win.style.top = mywin.y + 'px';

		mywin.restore = false;

		mywin._wintitle.style.width = mywin.getTitleWidth() + 'px';
		mywin.content.style.width = mywin.getContentWidth() + 'px';
		mywin.content.style.height = mywin.getContentHeight() + 'px';		

		document.body.appendChild(mywin._btnmax);
		document.body.appendChild(mywin._btnmin);
		document.body.removeChild(mywin._btnreset);

		if ( mywin._mclipzone.attachEvent ) {
			mywin._mclipzone.detachEvent('ondblclick',mywin.reSet);
			mywin._mclipzone.attachEvent('ondblclick',mywin.maximize);
			if (mywin.status == 'maximode') { mywin._mclipzone.attachEvent('onmousedown',mywin.move)}
			}
		else {
			mywin._mclipzone.removeEventListener('dblclick',mywin.reSet,false);
			mywin._mclipzone.addEventListener('dblclick',mywin.maximize,false);
			if (mywin.status == 'maximode') { mywin._mclipzone.addEventListener('mousedown',mywin.move,false)}
			}

		void mywin.setButtons();
		void mywin.setClipZones();
		mywin.status = 'normalmode';
		}
	
	this.closeWin = function (ev) {
		var attr = mywin.content.setAttribute('mywindow','0');
		var node; var chide;
		while ( mywin.win.hasChildNodes ) {
			node = mywin.win.firstChild;
			if ( node && node.id == mywin.content.id && chide != true ) { 
				document.body.appendChild(node);
				node.style.display = 'none';
				chide = true;
				}
			else if ( node ) { mywin.win.removeChild(node); } else { break; }
			}
		if ( mywin.moveable ) {document.body.removeChild(mywin._mclipzone)}
		if ( mywin.resizeable ) {document.body.removeChild(mywin._rclipzone)}
		if ( mywin.statusbar ) {document.body.removeChild(mywin.winstatus)}
		if ( mywin.basics ) {
			// 1.0.x
			if ( mywin.status != 'normalmode' ) {
				document.body.removeChild(mywin._btnreset)
				}
			else {
				document.body.removeChild(mywin._btnmax);
				document.body.removeChild(mywin._btnmin)
				}
			}
		if ( mywin.closeable ) {document.body.removeChild(mywin._btnclose)}
		document.body.removeChild(mywin.win);		
		delete mywin;
		}

	this.getSkin = function () {
		// alt...
		var cssnode;
		for ( i = 0; i < document.styleSheets.length; i++ ) {
			if ( document.styleSheets[i].cssRules ) {
				// DOM
				for ( x = 0; x < document.styleSheets[i].cssRules.length; x++ ) {
					cssnode = document.styleSheets[i].cssRules[x];
					if ( cssnode.selectorText ) {
						if ( cssnode.selectorText.indexOf(this.classprefix) > -1 ) {
							this.skin[cssnode.selectorText] = cssnode; // this.skin['.' + this.classprefix + 'SELECTORNAME'].style.PROPERTY;
							}
						}
					}
				}
			else {
				// Microsoft
				for ( x = 0; x < document.styleSheets[i].rules.length; x++ ) {
					cssnode = document.styleSheets[i].rules[x];
					if ( cssnode.selectorText.indexOf(this.classprefix) > -1 ) {
						this.skin[cssnode.selectorText] = cssnode; // this.skin['.' + this.classprefix + 'SELECTORNAME'].style.PROPERTY;
						}
					}
				}
			}
		return;
		}
	
	this.removePx = function (val) { 
		if ( val.indexOf('px') ) {
			val = Number(val.substr(0,val.indexOf('px')));
			}
		return val;
		}
	
	this.setButtons = function () { // Buttons neu setzen
		if ( mywin.closeable ) {
			mywin._btnposx[0] = mywin.x + mywin.w - mywin._btnposxd[0];
			mywin._btnposy[0] = (mywin.y + mywin.headheight / 2) - (mywin.removePx(mywin.skin['.' + mywin.classprefix + 'ButtonClose'].style.height) / 2);

			mywin._btnclose.style.left = mywin._btnposx[0] + 'px';
			mywin._btnclose.style.top = mywin._btnposy[0] + 'px';
			}
		if ( mywin.basics ) {
			if ( mywin.restore ) {
				mywin._btnposx[1] = mywin.x + mywin.w - mywin._btnposxd[1];				
				mywin._btnposy[1] = (mywin.y + mywin.headheight / 2) - (mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Maximizer'].style.height) / 2);
				
				mywin._btnreset.style.left = mywin._btnposx[1] + 'px';				
				mywin._btnreset.style.top = mywin._btnposy[1] + 'px';
				}
			else {
				mywin._btnposx[1] = mywin.x + mywin.w - mywin._btnposxd[1];
				mywin._btnposx[2] = mywin.x + mywin.w - mywin._btnposxd[2];
			
				mywin._btnposy[1] = (mywin.y + mywin.headheight / 2) - (mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Maximizer'].style.height) / 2);
				mywin._btnposy[2] = (mywin.y + mywin.headheight / 2) - (mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Minimizer'].style.height) / 2);

				mywin._btnmax.style.left = mywin._btnposx[1] + 'px';
				mywin._btnmax.style.top = mywin._btnposy[1] + 'px';

				mywin._btnmin.style.left = mywin._btnposx[2] + 'px';
				mywin._btnmin.style.top = mywin._btnposy[2] + 'px';			
				}
			}
		return;
		}
	
	this.setClipZones = function () { // clipping zonen neu ausrichten
		if ( mywin.moveable ) {
			mywin._mclipzone.style.left = mywin.x + 'px';
			mywin._mclipzone.style.top = mywin.y + 'px';
			mywin._mclipzone.style.width = mywin.w + 'px';
			mywin._mclipzone.style.height = mywin.headheight + 'px';
			mywin._mclipzone.style.zIndex = mywin.z + 1;
			}
		if ( mywin.resizeable ) {
			mywin._rclipzone.style.width = '10px'; mywin._rclipzone.style.height = '10px';
			mywin._rclipzone.style.left = mywin.x + mywin.w - 5 + 'px';
			mywin._rclipzone.style.top = mywin.y + mywin.h - 5 + 'px';
			mywin._rclipzone.style.zIndex = mywin.z + 1;
			}
		return;
		}


	this.getTitleWidth = function () {
		var w = mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Titlebar'].style.borderLeftWidth);
		w += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Titlebar'].style.borderRightWidth);
		w += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Titlebar'].style.paddingLeft);
		w += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Titlebar'].style.paddingRight);
		return mywin.w - w;
		}
	this.getContentWidth = function () {
		var w = mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Content'].style.borderLeftWidth);
		w += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Content'].style.borderRightWidth);
		w += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Content'].style.paddingLeft);
		w += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Content'].style.paddingRight);
		return mywin.w - w;
		}
	this.getContentHeight = function () {
		var h = mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Content'].style.borderTopWidth);
		h += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Content'].style.borderBottomWidth);
		h += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Content'].style.paddingTop);
		h += mywin.removePx(mywin.skin['.' + mywin.classprefix + 'Content'].style.paddingBottom);
		h += mywin.headheight;
		h += mywin.statusheight;
		return mywin.h - h;
		}
	
	this.setZ = function (z) {
		mywin.z = z;
		mywin.win.style.zIndex = z;
		mywin._btnclose.style.zIndex = mywin.z + 2;
		mywin._btnmax.style.zIndex = mywin.z + 2;
		mywin._btnmin.style.zIndex = mywin.z + 2;
		mywin._btnreset.style.zIndex = mywin.z + 2;
		mywin._mclipzone.style.zIndex = mywin.z + 1;
		mywin._rclipzone.style.zIndex = mywin.z + 1;
		}

	this.moveTo = function (x,y) {
		mywin.x = x; mywin.win.style.left = mywin.x + 'px';
		mywin.y = y; mywin.win.style.top = mywin.y + 'px';
		void mywin.setButtons();
		if ( !mywin.moveing ) { void mywin.setClipZones() }
		return;
		}


	if ( this.content ) { // Construct Window
		var atr = this.content.getAttributeNode('mywindow');
		var iswin = atr ? atr.nodeValue : 0;
		if ( iswin == 0 ) { // nein
			iswin = document.createAttribute('mywindow');
			iswin.nodeValue = '1';
			this.content.setAttributeNode(iswin);
			}
		else { // ja, abbruch
			delete mywin;
			return;
			}		


		void this.getSkin(); // stylesheet

		// hoehe von titel- und statusleiste vom stylesheet ziehen
		this.headheight = this.removePx(this.skin['.' + this.classprefix + 'Titlebar'].style.height);
		this.headheight += this.removePx(this.skin['.' + this.classprefix + 'Titlebar'].style.paddingTop);
		this.headheight += this.removePx(this.skin['.' + this.classprefix + 'Titlebar'].style.paddingBottom);
		this.headheight += this.removePx(this.skin['.' + this.classprefix + 'Titlebar'].style.borderTopWidth);
		this.headheight += this.removePx(this.skin['.' + this.classprefix + 'Titlebar'].style.borderBottomWidth);
		if ( this.statusbar ) {
			this.statusheight = this.removePx(this.skin['.' + this.classprefix + 'Statusbar'].style.height);
			this.statusheight = this.removePx(this.skin['.' + this.classprefix + 'Statusbar'].style.paddingTop);
			this.statusheight = this.removePx(this.skin['.' + this.classprefix + 'Statusbar'].style.paddingBottom);
			this.statusheight = this.removePx(this.skin['.' + this.classprefix + 'Statusbar'].style.borderTopWidth);
			this.statusheight = this.removePx(this.skin['.' + this.classprefix + 'Statusbar'].style.borderBottomWidth);
			}
		else {
			this.statusheight = 0;
			}

		this.minheight = this.headheight + this.statusheight; // min. hoehe
		
		// haupt fenster container
		this.win = document.createElement('div');
		this.win.className = this.classprefix + 'Window'; // Skin anwenden
		this.win.style.position = 'absolute';
		this.win.style.left = this.x + 'px'; this.win.style.top = this.y + 'px';
		this.win.style.width = this.w + 'px'; this.win.style.height = this.h + 'px';
		this.win.style.overflow = 'hidden';
		this.win.style.zIndex = this.z;
		document.body.appendChild(this.win);
		
		// content anpassen
		this.content.className = this.classprefix + 'Content';
		this.content.style.position = 'absolute';
		this.content.style.display = 'block';
		this.content.style.top = this.headheight + 'px';
		this.content.style.width = this.getContentWidth() + 'px';
		this.content.style.height = this.getContentHeight() + 'px';

		if ( scrollbars ) { this.content.style.overflow = 'auto'; }
		else {
			this.content.style.overflow = 'hidden'; // fehler bei iframes
			}
		this.win.appendChild(this.content); // content an win anhaengen

		// titelleiste
		this._wintitle = document.createElement('div');
		this._wintitle.className = this.classprefix + 'Titlebar'; // Apply Skin to titlebar
		this._wintitle.style.position = 'absolute';
		this._wintitle.style.left = '0px';
		this._wintitle.style.top = '0px';
		this._wintitle.style.width = this.getTitleWidth() + 'px';
		this._wintitle.style.overflow = 'hidden';
		this.win.appendChild(this._wintitle);

		if ( this.windowname != '' ) {
			// Fenstername
			var nameNode = document.createTextNode(this.windowname);
			this._wintitle.appendChild(nameNode);
			}
		
		if ( this.moveable ) {
			this._mclipzone = document.createElement('div');
			this._mclipzone.style.backgroundImage = 'url('+_mywinXgif+')'; // transparentes gif!
			this._mclipzone.style.position = 'absolute'; this._mclipzone.style.left = this.x + 'px';
			this._mclipzone.style.top = this.y + 'px';
			this._mclipzone.style.width = this.w + 'px';
			this._mclipzone.style.height = this.headheight + 'px';
			this._mclipzone.style.zIndex = this.z + 1;

			if ( this._mclipzone.attachEvent ) {
				this._mclipzone.attachEvent('onmousedown',this.move);
				if ( this.resizeable ) {
					this._mclipzone.attachEvent('ondblclick',this.maximize);
					}
				}
			else {
				this._mclipzone.addEventListener('mousedown',this.move,false);
				if ( this.resizeable ) {
					this._mclipzone.addEventListener('dblclick',this.maximize,false);
					}
				}
			document.body.appendChild(this._mclipzone);
			}
		
		// Statusleiste
		if ( this.statusbar ) {
			this.winstatus = document.createElement('div');
			this.winstatus.className = this.classprefix + 'Statusbar';
			this.winstatus.style.position = 'absolute';
			this.winstatus.style.top = this.y + 2 + this.h - this.statusheight + 'px';
			this.winstatus.style.left = this.x + 2+ 'px';
			this.winstatus.style.width = this.w + 'px';
			document.body.appendChild(this.winstatus);
			}	
		if ( this.resizeable ) {
			this._rclipzone = document.createElement('div');
			this._rclipzone.className = this.classprefix + 'Resizer';
			this._rclipzone.style.position = 'absolute';
			this._rclipzone.style.left = mywin.x + mywin.w - 5 + 'px';
			this._rclipzone.style.top = mywin.y + mywin.h - 5 + 'px';
			this._rclipzone.style.cursor = 'se-resize';
			this._rclipzone.style.width = '10px';
			this._rclipzone.style.height = '10px';
			this._rclipzone.style.background = 'transparent url('+_mywinXgif+') top left repeat';
			this._rclipzone.zIndex = this.z + 1;

			if ( this._rclipzone.addEventListener ) {
				this._rclipzone.addEventListener('mousedown',this.resize,false);
				}
			else {
				this._rclipzone.attachEvent('onmousedown',this.resize);
				}			
			document.body.appendChild(this._rclipzone);
			}
		if ( this.closeable ) { // schliessen
			this._btnclose = document.createElement('div');
			this._btnposxd[0] = this.removePx(this.skin['.' + this.classprefix + 'ButtonClose'].style.width) + 5;
			this._btnposx[0] = this.x + this.w - this._btnposxd[0];
			this._btnposy[0] = (this.y + this.headheight / 2) - (this.removePx(this.skin['.' + this.classprefix + 'ButtonClose'].style.height) / 2);
			
			this._btnclose.className = this.classprefix + 'ButtonClose';
			this._btnclose.style.position = 'absolute';
			this._btnclose.style.left = this._btnposx[0] + 'px';
			this._btnclose.style.top = this._btnposy[0] + 'px';
			this._btnclose.style.zIndex = this.z + 2;
			document.body.appendChild(this._btnclose);
			
			if ( this._btnclose.addEventListener ) {this._btnclose.addEventListener('click',this.closeWin,false);}
			else {this._btnclose.attachEvent('onclick',this.closeWin);}			
			}
		if ( this.basics ) { // minimieren & maximieren
			this._btnmax = document.createElement('div');
			this._btnmin = document.createElement('div');
			
			this._btnposxd[1] = this.removePx(this.skin['.' + this.classprefix + 'Maximizer'].style.width) + 5;
			this._btnposxd[1] += this.closeable ? this._btnposxd[0] : 0;
			
			this._btnposxd[2] = this._btnposxd[1] + 5 + this.removePx(this.skin['.' + this.classprefix + 'Minimizer'].style.width);

			this._btnposx[1] = this.x + this.w - this._btnposxd[1];
			this._btnposx[2] = this.x + this.w - this._btnposxd[2];
			
			this._btnposy[1] = (this.y + this.headheight / 2) - (this.removePx(this.skin['.' + this.classprefix + 'Maximizer'].style.height) / 2);
			this._btnposy[2] = (this.y + this.headheight / 2) - (this.removePx(this.skin['.' + this.classprefix + 'Minimizer'].style.height) / 2);

			this._btnmax.className = this.classprefix + 'Maximizer';
			this._btnmax.style.position = 'absolute';
			this._btnmax.style.left = this._btnposx[1] + 'px';
			this._btnmax.style.top = this._btnposy[1] + 'px';
			this._btnmax.style.zIndex = this.z + 2;

			this._btnmin.className = this.classprefix + 'Minimizer';
			this._btnmin.style.position = 'absolute';
			this._btnmin.style.left = this._btnposx[2] + 'px';
			this._btnmin.style.top = this._btnposy[2] + 'px';
			this._btnmin.style.zIndex = this.z + 2;
			
			this._btnreset = document.createElement('div');
			this._btnreset.className = this.classprefix + 'ButtonReset';
			this._btnreset.style.position = 'absolute';
			this._btnreset.style.left = this._btnposx[1] + 'px';
			this._btnreset.style.top = this._btnposy[1] + 'px';
			this._btnreset.style.zIndex = this.z + 2;
			
			if ( this._btnmax.addEventListener ) {
				this._btnmax.addEventListener('click',this.maximize,false);
				this._btnmin.addEventListener('click',this.minimize,false);
				this._btnreset.addEventListener('click',this.reSet,false);
				}
			else {
				this._btnmax.attachEvent('onclick',this.maximize);
				this._btnmin.attachEvent('onclick',this.minimize);
				this._btnreset.attachEvent('onclick',this.reSet);
				}
			document.body.appendChild(this._btnmax);
			document.body.appendChild(this._btnmin);
			}
		return this.content.id;
		}
	else {
		return false;
		}
}