var AjaxLoading="<div id='ajaxload'></div>"; //content of lightbox while loading content
var AjaxFailure="<div id='ajaxfail' onClick='javascript:keyboard_resetAll();'></div>"; //content of lightbox if loading failed
var closeButton="img/close.gif"; //path to image for close button

/*
** dms_lb_script
** Version 1.1
**
** Verbreitung des Scripts erwünscht
** 
** Homepage: http://www.electronic-culture.de
** E-Mail: dms@electronic-culture.de
**
** ChangeLog:
**   V1.0 (14.02.2008)
**   - first release
**   V1.1 (15.02.2008)
**   - Funktion >>createLightboxContainer(name, id, width, height)<< hinzugefuegt
**
** Known Bugs:
**   - overlay will not be cleanly removed in Opera
*/

function removeElement(id){
	var element=top.document.getElementById(id);
	element.parentNode.removeChild(element);
}

function createLightboxObj(name, width, height){
	var bod=top.document.getElementsByTagName('body')[0];

	var container=top.document.createElement('div');
	container.className='lb_container'; container.id='lb_container_'+name;

	var overlay=top.document.createElement('div');
	overlay.id='lb_overlay_'+name; overlay.className='lb_overlay';
	overlay.onclick = function () {destroyLightbox(name); return false;}

	var lb=top.document.createElement('div');
	lb.id='lb_data_'+name; lb.className='lb_data';
	lb.style.width=width+"px"; lb.style.height=height+"px";
	lb.style.marginLeft=(-width/2)+"px"; lb.style.marginTop=(-height/2)+"px";

	container.appendChild(overlay); container.appendChild(lb);
	bod.appendChild(container);

	return lb;
}

function createLightboxIFrame(name, url, width, height){
	var lb=createLightboxObj(name,width,height);
	lb.innerHTML='<IFRAME frameborder="0" name="lb_iframe" id="lb_iframe'+name+'" src="'+url+'"></IFRAME><IMG src="'+closeButton+'" alt="" id="lb_close_'+name+'" class="lb_close" onClick="destroyLightbox('+"'"+name+"'"+');" />';
}

function createLightboxHTML(name, html, width, height){
	var lb=createLightboxObj(name,width,height);
	lb.innerHTML=html+'<IMG src="'+closeButton+'" alt="" id="lb_close_'+name+'" class="lb_close" onClick="destroyLightbox('+"'"+name+"'"+');" />';
}

function createLightboxAjax(name, url, width, height){
	var lb=createLightboxObj(name,width,height);
	lb.innerHTML=AjaxLoading+'<IMG src="'+closeButton+'" alt="" id="lb_close_'+name+'" class="lb_close" onClick="destroyLightbox('+"'"+name+"'"+');" />';
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {lb.innerHTML=transport.responseText+'<IMG src="'+closeButton+'" alt="" id="lb_close_'+name+'" class="lb_close" onClick="destroyLightbox('+"'"+name+"'"+');" />';},
		onFailure: function(transport) {lb.innerHTML=AjaxFailure+'<IMG src="'+closeButton+'" alt="" id="lb_close_'+name+'" class="lb_close" onClick="destroyLightbox('+"'"+name+"'"+');" />';}
	});
}

function createLightboxContainer(name, id, width, height){
	var lb=createLightboxObj(name,width,height);
	var container=top.document.createElement('div');
	container.id=id;
	container.style.position="absolute";
	container.style.top="0px"; container.style.left="0px";
	container.style.width=width+"px"; container.style.height=height+"px";

	var close=top.document.createElement('img');
	close.alt=""; close.src=closeButton; 
	close.id='lb_close_'+name; close.className="lb_close";
	close.onclick=function(event){destroyLightbox(name); return false;};
	
	lb.appendChild(container);
	lb.appendChild(close);
	return container;
}

function destroyLightbox(name){
	removeElement('lb_overlay_'+name);
	removeElement('lb_data_'+name);
	removeElement('lb_container_'+name);
	if (window.opera){
		//need to fix opera redraw bug
	}
	enableKeyboard(); enableScreensaver();
}
