/* public javascript code
 * based on	dynlite dhtml dom api
 * @author:  Peter Assenov- AIP Solutions Ltd.' 2001-2006
 * @version: 2.2.1.2/2005-03-20
 * !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)}

/* 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;
	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 */
	//default x position
	this.cont.style.left=posObjX-this._img.width+"px";
	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 */
	//default y position
	this.cont.style.top=posObjY-this._img.height+"px";
	if((this._img.height+posObjY)>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;
	obj('ert').value=dp.cont.style.top;
	//e.cancelBubble = true
	//dp.cont.onmouseout=function(){dp_stopmove();}
	//if(parseInt(dp.cont.style.top)<10) info(e);//setTimeout('dp_stopmove()',10);
		
}
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;
	dp.cont.style.height=e.clientY-dp.offsetY;
	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');

function picOnload()
{ 	imobj.src=im.src;
	(ns6)? cont.style.MozOpacity="1":cont.filters.alpha.opacity="100";
}

//open privacy popup
function blockOpen(elId){obj(elId).on();}
function blockClose(elId){obj(elId).off();}

//right menu
var dir=0;
	
function rightMenuHandle(elId,arrow)
{	if(dir==0)
	{	obj(elId).off();
		obj(arrow).src="img/arrowDown.gif";
		dir=1;
	}
	else
	{	obj(elId).on();
		obj(arrow).src="img/arrowUp.gif";
		dir=0;
	}
}

//map functions
mob=new Object();
mob.pl=20;//220;
mob.pt=50;//350;
mob.zob=0;
mob.cob=0;
mob.timeout=0;

mob.select=function(ob)
{	this.cob=ob; /* area object */	
	var cords=this.cob.getAttribute('coords').split(',');
	if(this.timeout) clearTimeout(this.timeout);
	
	if(this.lob) this.lob.className=this.lob.className.toString().replace(/mapActive/,'');
	this.lob=obj(this.cob.getAttribute('ref')); /* list object */
	this.lob.className+=' mapActive';
	
	if(!this.zob) this.zob=obj('mapZoom');/* zoom object */
	this.zob.style.left=this.pl+parseInt(cords[0])+'px';
	this.zob.style.top=this.pt+parseInt(cords[1])+'px';
	this.zob.innerHTML=this.lob.innerHTML;
	this.zob.on();
	//alert(this.pl+parseInt(cords[0])+'px');
}
mob.hover=function(id)
{	this.select(obj(id+'Area'));
	this.timeout=setTimeout("obj('mapZoom').off()",5000);
}	
mob.over=function()
{	if(this.timeout) clearTimeout(this.timeout);
}	
mob.out=function(mode)
{	this.timeout=setTimeout("obj('mapZoom').off()",500);
}

