/* dynlite dhtml dom api - images dynamic popup object
 * peter assenov- aip solutions ltd' 2001-2009
 * @version: 2.3.02 - 2009-02-11
 */
/* environment creation if used standalone */
if(!window.dl)
{	dl={ver:2.3, dev:true, w:window, d:document};
	dl.is={tr:(dl.d.all)? 1:0}
	dl.log=['- dynamic popup initialization -'];
	dl.els=[];
	dl.el=function(id,ob)
	{	if(dl.els[id]) return dl.els[id];
		var el=dl.d.getElementById(id);
		if(!el)	{dl.error('no element with id='+id+' found','dynlite.js','dl.el()','Runtime');return 0;}
		if(ob) el.ob=ob;
		el.attr=function(attr,val)
		{	if(!val) return (attr=='class')? el.className : (!dl.is.tr&&el.hasAttribute(attr))? el.getAttribute(attr):el[attr];
			else (attr=='class')? el.className=val:el.setAttribute(attr,val,false);
		return el;
		}
		el.on=function(disp){el.style.display=disp||'block'; return el;}
		el.off=function(){el.style.display='none'; return el;}
		dl.els[id]=el;
	return el;
	}
	dl.dom={
		el:function(tag,par,attr,text)
		{	var id=(attr&&attr.id)? attr.id:dl.els.length;
			if(dl.els[id]) return dl.els[id];
			var el=dl.d.createElement(tag);
				el.id=id;
			(par)?  par.appendChild(el) : dl.d.body.appendChild(el);
			dl.log.push('# '+tag+' element with id="'+id+'" created.')
			var del=dl.el(id);
			if(attr&&typeof(attr)=='object')
				for(i in attr)
					del.attr(i,attr[i]);
			if(text) el.appendChild(dl.d.createTextNode(text));
		return del;
		},
		evt:function(_this,evt){if(_this[evt]) return (function(){return _this[evt](this);});} /* closure */
	}
}
/* image popup class */
dl.image=function(id)
{	this.id=id;
	this.src=null;
	this.margin=10; /* margin between the popup and the browser window */
/* created elements */
	this.cont=null; /* main container parent to all other elements */
	this.head=null; /* window title */
	this.text=null; /* description */
	this.img=null; /* image element */
	this.load=null; /* loading message */
/* global elements */
	this.d=dl.d.documentElement; /* shortcut to window.document */
	this.b=null; /* body element */
	this.msg={loading:"Loading image...",close:"Click here to close the window."};
	this.offsetY=0;
	this.offsetX=0;
	this.ready=false;
/* private methods */	
	this.init=function()
	{	if(this.ready) return;
		this.cont=dl.dom.el('DIV',false,{id:this.id});
		this.cont.onclick=dl.dom.evt(this,'close');
		this.head=dl.dom.el('H3',this.cont,false);
		this.text=dl.dom.el('P',this.cont);
		this.load=dl.dom.el('H4',this.cont,false,this.msg.loading);
		this.b=this.cont.parentNode;
		this.ready=true;
	}
	this.close=function()
	{	if(!this.cont) return;
		this.load.on();
		if(this.img)
		{	this.img.off();
			this.img=null;
		}
		this.cont.off();
	}
	this.onload=function()
	{	var c=this.cont;
		var i=this.img;
		this.load.off();
		this.img.on();
		if(dl.is.tr) return;
		/* outside the window correction */
		var cy=Math.min(this.d.clientHeight+this.offsetY-(c.offsetTop+c.offsetHeight+this.margin),0);
		var cx=Math.min(this.d.clientWidth+this.offsetX-(c.offsetLeft+c.offsetWidth+this.margin),0);
		c.style.top=c.offsetTop+cy+'px';
		c.style.left=c.offsetLeft+cx+'px';
	}
/* public methods */
	this.open=function(src,e)
	{
		this.src=src;
		this.e=e||event;
		if(!this.ready)
			this.init();
		this.close();
	/* copying the text information */
		this.head.innerHTML=this.src.getAttribute('title')||this.mgs.close;
		this.img=dl.dom.el('IMG',this.cont).off(); /* image needs to be recreated every time because it stores width&height attributes in ie */
		this.img.src=this.src.getAttribute('image');
		this.img.title=this.src.getAttribute('text');
		this.img.onload=dl.dom.evt(this,'onload');
//		this.img.onload=function(){ dl.dp.onload() }
		this.text.innerHTML=this.src.getAttribute('text');
	/* positioning the popup */
		/* correction if the site is smaller than window */
		this.offsetY=-Math.max((this.d.clientHeight-this.b.offsetHeight)/2,0);
		this.offsetX=-Math.max((this.d.clientWidth-this.b.offsetWidth)/2,0); 
		/* correction if the viewport is scrolled */
		this.offsetY+=this.d.scrollTop;
		this.offsetX+=this.d.scrollLeft;
		this.cont.style.top=parseInt(this.e.clientY+this.offsetY)+'px';
		this.cont.style.left=parseInt(this.e.clientX+this.offsetX)+'px';
	/* visualization */
		this.cont.on();
	}
}
/* static object creation */
dl.dp=new dl.image('enlarge');
/* code end- enjoy... */