/*
	window.js needs window.css
	Pascal Vorsmann
	
	Version 1.0 2009-08-24
	
	pascal´s kleine Windows Klasse zum Erstellen eines kleinen dynamischen Fensters mit folgenden features:
	- variable Größe
	- Overlay im Hintergrund
	- Dragable
	- mehrere Instanzen
	
*/
var global_depth=0;
var global_id = new Array();
var mydrag = new Array();

// Funktion zum ermitteln der Fenstergdimension für Overlays etc
function getPageDimensions() {
	var pageDimensions =[];
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageDimensions['height'] = windowHeight;
	} else { 
		pageDimensions['height'] = yScroll;
	}

	if(xScroll < windowWidth){	
		pageDimensions['width'] = windowWidth;
	} else {
		pageDimensions['width'] = xScroll;
	}
	return pageDimensions;
}
	
// Funktion für die nächste freie Ebene 
function getNextHighestDepth(){
	global_depth+=10;
	return global_depth;
}

// Function zum Generieren eines Fensters
function ShowContact(w,h,ct,name,beruf){
	// Fenstergröße ermitteln für Overlay
	pageDimensions = getPageDimensions();
	// Nächste freie Ebene bestimmen
	depth = getNextHighestDepth();
	global_id.push(depth);
	// Dummy-Code
	window_code = '	<div style="background:url(images/das-team/hg_xxl.png) top left no-repeat; height:528px; width:375px;">'+
						'<div style="position:absolute; width:38px; height:38px; margin:10px 0 0 332px;">'+
						  '<a href="JavaScript:;" OnClick="HideWindow(\''+depth+'\'); return false;"><img src="images/x.gif" alt="close" width="38" height="38" border="0"/></a></div>'+
						'<div style="position:absolute; width:293px; height:418px; margin:51px 0 0 31px;"><img src="images/das-team/xxl_'+ct+'.jpg" alt="XXL-Abbildung" width="293" height="418" /></div>'+
						'<div class="size14" style="position:absolute; width:323px; margin:483px 0 0 0; text-align:right;"><strong style="color:#3a3a3a;">'+name+'</strong></div>'+
						'<div style="position:absolute; width:323px; margin:498px 0 0 0; text-align:right; color:#d403aa;">'+beruf+'</div>'+
					'</div>';
	// Window
	win = document.createElement('div');
	win.setAttribute('id', 'mywindow'+depth);
	win.setAttribute((document.all ? 'className' : 'class'), 'mywindow');
	win.innerHTML = window_code;
	
	// Overlay
	overlay = document.createElement('div');
	overlay.setAttribute('id', 'myoverlay'+depth);
	overlay.setAttribute((document.all ? 'className' : 'class'), 'myoverlay');
	overlay.innerHTML = '&nbsp;';
	
	// Window und Overlay In Seite nach Body einsetzen
	var body = document.getElementsByTagName('body')[0];
	body.appendChild(overlay);
	body.appendChild(win);
	
	// AB HIER KÖNNEN DANN ELEMENTE ÜBER DAS DOM ERGO PROTOTYPE ANGESPROCHEN WERDEN

	// Zindex für Overlay und Fenster
	zindexwin	= 1000+depth;
	zindexover	= 1000+(depth-1);
	// Overlay auf 100% höhe bringen:
	$('myoverlay'+depth).setStyle({ 'background':'transparent url(images/window/white-75.png) top left repeat', 'position':'absolute', 'left':'0px', 'top':'0px', 'width':'100%', 'height': pageDimensions['height']+'px', 'zIndex':zindexover });
	// Fenster mittig ausrichten
	ml=w/2;	mt=h/2;
	$('mywindow'+depth).setStyle({ 'position':'absolute', 'display': 'block', 'width':w+'px', 'height':h+'px', 'top':'85px', 'left':'50%', 'marginLeft':'-'+ml+'px', 'zIndex':zindexwin}); 

	// und Draggable machen (im IE zu Buggy!)
	if(!document.all){
		mydrag[depth] = new Draggable('mywindow'+depth);
	}

}

// Function zum Generieren eines Fensters
function ShowWindow(w,h,url,callBack){
	// Fenstergröße ermitteln für Overlay
	pageDimensions = getPageDimensions();
	// Nächste freie Ebene bestimmen
	depth = getNextHighestDepth();
	global_id.push(depth);
	// Dummy-Code
	window_code = '<div style="width:571px; height:auto;">'+
          				'<div id="top_'+depth+'" style="background:transparent url(images/window/win_top.png) top left no-repeat; height:48px; text-align:right;">'+
          					'<a href="JavaScript:;" OnClick="HideWindow(\''+depth+'\',\''+callBack+'\'); return false;"><img src="images/x.gif" height="45" width="44" border="0" /></a>'+
          				'</div>'+
          				'<div style="background:transparent url(images/window/win_content.png) top left repeat-y;">'+
          	  				'<div style="padding:20px 0px 27px 50px; width:480px; overflow:auto;">'+
          						'<iframe id="iframe_'+depth+'" name="iframe_'+depth+'" src="about:blank" width="100%" height="100%" frameborder="0" marginwidth="0" marginheight="0" scrolling="auto" allowtransparency="true"></iframe>'+
          					'</div>'+
          				'</div>'+
          				'<div id="bottom_'+depth+'" style="background:transparent url(images/window/win_bottom.png) top left no-repeat; height:29px;"></div>'+
          			'</div>';

	// Window
	win = document.createElement('div');
	win.setAttribute('id', 'mywindow'+depth);
	win.setAttribute((document.all ? 'className' : 'class'), 'mywindow');
	win.innerHTML = window_code;
	
	// Overlay
	overlay = document.createElement('div');
	overlay.setAttribute('id', 'myoverlay'+depth);
	overlay.setAttribute((document.all ? 'className' : 'class'), 'myoverlay');
	overlay.innerHTML = '&nbsp;';
	
	// Window und Overlay In Seite nach Body einsetzen
	var body = document.getElementsByTagName('body')[0];
	body.appendChild(overlay);
	body.appendChild(win);
	
	// AB HIER KÖNNEN DANN ELEMENTE ÜBER DAS DOM ERGO PROTOTYPE ANGESPROCHEN WERDEN

	// Zindex für Overlay und Fenster
	zindexwin	= 1000+depth;
	zindexover	= 1000+(depth-1);
	// Overlay auf 100% höhe bringen
	$('myoverlay'+depth).setStyle({ 'background':'transparent url(images/window/white-75.png) top left repeat', 'position':'absolute', 'left':'0px', 'top':'0px', 'width':'100%', 'height': pageDimensions['height']+'px', 'zIndex':zindexover });
	// Fenster mittig ausrichten
	ml=w/2;	mt=h/2;
	$('mywindow'+depth).setStyle({ 'position':'absolute', 'display': 'block', 'width':w+'px', 'height':h+'px', 'top':'85px', 'left':'50%', 'marginLeft':'-'+ml+'px', 'zIndex':zindexwin}); 

	// und Draggable machen (im IE zu Buggy!)
	if(!document.all){
		mydrag[depth] = new Draggable('mywindow'+depth);
	}
	
	// Iframe höhe Berechnen!
	iframeh = h-($('top_'+depth).getHeight()+$('bottom_'+depth).getHeight());
	$('iframe_'+depth).setStyle({'height':iframeh+'px'});
		
	// URL im Fenster laden!
	$('iframe_'+depth).src=url+'&depth='+depth;
}


function HideWindow(depth){
	// Prüfen nach Anzahl und ggf. Overlay stehen lassen und fenster nur löschen wenn es keines gibt das übergeordnet ist getNextHighestDepth-1>depth
	// Fenster und Overlay löschen
	if(mydrag[depth]){
		mydrag[depth].destroy();
	}
	Element.remove($('mywindow'+depth));
	Element.remove($('myoverlay'+depth));
	global_depth-=10;
	global_id.pop();
}


