/*

	MyWindowManagar 0.2
	
	Browser:
	- Firefox und vermutl. alle anderen Mozilla Browser und Klone
	- Internet Explorer 6
	- Vieleicht Mac Safari 2.x
	
	Das geht:
	- Mehrere Fenster oeffnen und bewegen
		- BUG: Die Buttons verhalten sich etwas merkwuerdig
	- Verschieben auf der z-achse durch anklicken.	
	
	
*/

function mywinmanFrames () {

	var winman = this;
	this.stack = new Array();
	this.active = null;
	this.order = new Array();
	this.qbox;
	this.xc = null;

/*
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...	    this.xc = new XMLHttpRequest();		}
	else if (window.ActiveXObject) { // IE		try {			this.xc = new ActiveXObject("Msxml2.XMLHTTP");            } catch (e) {                try {                    this.xc = new ActiveXObject("Microsoft.XMLHTTP");                } catch (e) {}            }
		}
*/	
			
	this.buildQBox = function() {
		//winman.qbox = winman.addWindow('qbox',190,250,'Quickbox',true,true,true,true,false,'');
		}
	

	this.addWindow = function (uri,w,h,windowname,scrollbars,moveable,resizeable,closeable,basics,classprefix) {
		
		x = 10 * (winman.stack.length + 1);
		y = 10 * (winman.stack.length + 1);
		z = 10 * (winman.stack.length + 1);

		var container = document.createElement('iframe');
		container.id = 'ifr'+z;
		container.name = 'mywinifr'+z;
		container.style.display = 'none';
		container.style.borderWidth = '0';
		document.body.appendChild(container);

		var win = new mywindow(container.id,w,h,x,y,z,windowname,scrollbars,moveable,resizeable,closeable,basics,classprefix);
		container.src = uri;
		
/*		
		var container = document.createElement('div');
		container.style.display = "none";
		container.id = 'content'+z;
		document.body.appendChild(container);
*/		
		//xc.overrideMimeType('text/xml');

/*
		winman.xc.open('POST',uri,true);
		winman.xc.onreadystatechange = function () {
			if (winman.xc.readyState == 4 && winman.xc.status == 200) {
				container.innerHTML = winman.xc.responseText;
				}
			}
		winman.xc.send(null);

		var win = new mywindow(container.id,w,h,x,y,z,windowname,scrollbars,moveable,resizeable,closeable,basics,classprefix);
*/		
		if ( win.win.attachEvent ) {
			win.win.attachEvent('onclick',winman.activate);
			win._mclipzone.attachEvent('onclick',winman.activate);
			win._btnreset.attachEvent('onclick',winman.activate);
			win._btnmax.attachEvent('onclick',winman.activate);
			win._btnmin.attachEvent('onclick',winman.activate);
			}
		else {		
			win.win.addEventListener('click',winman.activate,false);	
			win._mclipzone.addEventListener('click',winman.activate,false);		
			win._btnreset.addEventListener('click',winman.activate,false);		
			win._btnmax.addEventListener('click',winman.activate,false);		
			win._btnmin.addEventListener('click',winman.activate,false);		
			}
		winman.stack[winman.stack.length] = win;
		win.win.id = winman.stack.length -1;
		win._mclipzone.id = 'mclip'+(winman.stack.length -1);
		win._btnreset.id = 'btres'+(winman.stack.length -1);
		win._btnmax.id = 'btmax'+(winman.stack.length -1);
		win._btnmin.id = 'btmin'+(winman.stack.length -1);
		winman.active = win;
		
		//return win;
		}
	
	this.activate = function (ev) {
		var winno;
		if ( ev.srcElement ) {
			winno = ev.srcElement.parentNode.id;
			if ( winno == '' ) {
				winno = ev.srcElement.id.substring(5,ev.srcElement.id.length);
				}
			}
		else {
			if ( ev.target.parentNode ) {
				winno = ev.target.parentNode.id;
				}
			if ( winno == '' || winno == null ) {
				winno = ev.target.id.substring(5,ev.target.id.length);
				}
			}
		if ( winno == winman.stack.length -1 ) {
			return;
			}
		else {
			var win = winman.stack[winno];
			win._wintitle.className = 'mywinInactiveTitlebar';
			var nstck = new Array();
			for ( i = 0; i < winman.stack.length; i++ ) {
				if ( i == winno && (i + 1) < winman.stack.length ) {
					i = i + 1;
					nstck[nstck.length] = winman.stack[i];
					}
				else if (i != winno) {
					nstck[nstck.length] = winman.stack[i];
					}
				}
			nstck[nstck.length] = winman.stack[winno];
			winman.stack = nstck;
			void(delete(nstck));
			
			var tmpw;
			for ( i = 0; i < winman.stack.length; i++ ) {
				tmpw = winman.stack[i];
				tmpw.win.id = i;
				if ( i != winman.stack.length - 1 ) {
					tmpw._wintitle.className = 'mywinInactiveTitlebar'
					}
				tmpw._mclipzone.id = 'mclip'+i;
				tmpw._btnreset.id = 'btres'+i;
				tmpw._btnmax.id = 'btmax'+i;
				tmpw._btnmin.id = 'btmin'+i;	
				tmpw.setZ(((i + 1) * 10));
				}
			return;
			}
		}
}