/* public javascript code
 * based on	dynlite dhtml dom api
 * @author:  Peter Assenov- AIP Solutions Ltd.' 2001-2007
 * @version: 2.2.1.3/2007-03-21
 * !requires: dynlite.0.9.js
 */

  
/* library functions */
evt=function(el,evt,obj){(ns6)?el.addEventListener(evt,obj,false):el.attachEvent('on'+evt,obj)}
noevt=function(el,evt,obj){(ns6)?el.removeEventListener(evt,obj,false):el.detachEvent('on'+evt,obj)}
exists=function(nam){return document.getElementById(nam)}
/* debug functionality */
document.onkeyup=function(e)
{	if(!e) e=event;
	if(e.altKey&&e.ctrlKey&&e.keyCode==68)	// press Ctrl-Alt-D to visualize debug info
	{	log.push('--- dynlite log end ---');
		var err=log.join('<br>');
			err=err.replace(/#([^<]+)</gi,'<b class="debug"># $1</b><'); // status messages
			err=err.replace(/\!([^<]+)</gi,'<em class="debug">! $1</em><'); // error messages
		var el=obj("debug");
			el.innerHTML=err;
			el.on();
			el.onclick=function(){this.off()}
	}
};

/* div popup class */
function divPopup(id,cont,img)
{	this.id=id;
	this._img=new Image();
	this._contName=cont;
	this._imgName=img;
	this.cont=0;
	this.img=0;
	lastImg='';
}
/* div popup methods */
/* private */
_dp=divPopup.prototype;
_dp._show=function()
{	if(this.time) 
	{	clearTimeout(this.time);
	}
	this.img.src=this._img.src;
	this.cont.style.width=this._img.width+((ns6)?20:23);
	this.cont.style.height=this._img.height;
	if(this.lbl)
	{	this.img.width=this._img.width;
		this.img.height=this._img.height;
	}
/* calculating Y-coord of the enlarge div */
	if((this._img.width+posObjX)>document.body.scrollWidth)
	{	if((posObjX-this._img.width)<0)
			this.cont.style.left=0;
		else
			this.cont.style.left=posObjX-this._img.width+"px";
	}
	else
		this.cont.style.left=posObjX+"px";
/* calculating Y-coord of the enlarge div */
	if((this._img.height+posObjY+40)>document.body.scrollHeight)
	{	if((posObjY-this._img.height)<0)
			this.cont.style.top=0;
		else
			this.cont.style.top=posObjY-this._img.height+"px";
	}
	else
		this.cont.style.top=posObjY+"px";
	(ns6)? this.cont.style.MozOpacity="1":this.cont.filters.alpha.opacity="100";
	setTimeout("obj('enlargeBottom').on()",450);
}
/* public */
function disableEvent(){return false;}
function enableEvent(){return true;}
_dp.show=function(src,e)
{	if(!this.cont) this.cont=obj(this._contName);
	if(!this.img) this.img=obj(this._imgName);
	if(!ns6) e=event;
	posObjY=e.clientY+document.body.scrollTop;
	posObjX=e.clientX+document.body.scrollLeft;
	this._img.defsrc=this.img.getAttribute("defsrc",false);
	this._img.src=src;
	this._img.onload=function(){dp._show();};
	this.time=setTimeout("dp._show()",100);
	obj('enlargeBottom').off();
	this.cont.on();
	document.onselectstart = disableEvent;
	document.onmousedown = disableEvent;
	document.ondragstart = disableEvent;
}
_dp.close=function()
{	this.cont.off();
	this.img.src=this._img.defsrc;
	(ns6)? this.cont.style.MozOpacity=".7":this.cont.filters.alpha.opacity="70";
	document.onselectstart = enableEvent;
	document.onmousedown = enableEvent;
	document.ondragstart = enableEvent;
}
_dp.drag=function(e)
{	if(!ns6) e=event;
	this.offsetY=e.clientY-this.cont.offsetTop;
	this.offsetX=e.clientX-this.cont.offsetLeft;
	evt(document,'mousemove',dp_move);
	evt(document,'mouseup',dp_stopmove);
}
function dp_move(e)
{	if(!ns6) e=event;
	dp.cont.style.top=e.clientY-dp.offsetY;	
	dp.cont.style.left=e.clientX-dp.offsetX;
}
function dp_stopmove(e)
{	noevt(document,'mousemove',dp_move);
}
_dp.resize=function(e)
{	if(!ns6) e=event;
	this.lbl=1;
	this.offsetY=e.clientY-this.img.height;
	this.offsetX=e.clientX-this.img.width;
	evt(document,'mousemove',dp_size);
	evt(document,'mouseup',dp_stopsize);
	
}
function dp_size(e)
{	if(!ns6) e=event;
	dp.cont.style.width=e.clientX-dp.offsetX+((ns6)?20:23);
	dp.cont.style.height=e.clientY-dp.offsetY+((ns6)?0:4);
	dp.img.width=e.clientX-dp.offsetX;
	dp.img.height=e.clientY-dp.offsetY;
}
function dp_stopsize(e)
{	noevt(document,'mousemove',dp_size);
}	

/* static object creation */
dp=new divPopup('dp','enlarge','enlargePic');