/* dynlite dhtml dom api
 * peter assenov- aip solutions ltd' 2001-2009
 * @version: 2.3.03 - 2009-09-02
 */
/* main environment */
dl={ver:2.3, dev:false, w:window, d:document, n:navigator };
/* browser detection */
dl.is={
	ua:dl.n.userAgent.toLowerCase(),
	os:dl.n.platform.toLowerCase(),
	sniff:function()
	{	this.rv=parseFloat((this.ua.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1]);
		this.wk=/webkit/.test(this.ua); 					/* Webkit - Safari, Chrome */
		this.pr=/opera/.test(this.ua);  					/* Presto - Opera */
		this.tr=/msie/.test(this.ua)&&!this.pr; 			/* Trident - Internet Explorer 4-8 */
		this.gk=/mozilla/.test(this.ua)&&!this.tr&&!this.wk;/* Gecko - Firefox, Mozilla */
	/* browser aliases */
		this.sf=this.ch=this.wk;
		this.op=this.pr;
		this.ie=this.tr;
		this.ns=this.ff=this.mz=this.gk;
	/* specific browsers */
		this.ie6=this.ie&&this.rv==6;
	return this;
	}
}
dl.is.sniff();
/* debug functionality */
dl.trace=function(el)
{
	if(typeof(el)=='object')
	{	var code=[];
		for(var i in el){try{code.push(i+' -> '+el[i])}catch(e){}}
		(code.length>30)? dl.d.write(code.join('<br>')):alert(code.join('\n'));
	}
	else alert(el);
}
dl.log=['--- dynlite log ---'];
/* javaScript error handling */
dl.error=function(msg,url,lno,type)
{	var err=[msg,' ['+lno+']',url.replace(/^.*(\/|\\)/,'')];
	dl.log.push('!'+(type||'')+'Error: '+err.join(' '));
	if(dl.dev) dl.trace(dl.log);
return true;
}
//onerror=dl.error;
/* modules initialisation */
dl.mods=['dl'];
/* events management */
dl.evt={
	add:function(el,evt,func)
	{	if(el.addEventListener)	el.addEventListener(evt,func,false);
        else el['on'+evt]=function(event){func(event)}
    return this;
	},
	remove:function(el,evt,func)
	{	if(el.removeEventListener) el.removeEventListener(evt,func,false);
		else el['on'+evt]=null;
	return this;
	}
}
/* onload code execution */
dl.load=[];
dl.ready=0;

dl.onload=function(event)
{	if(dl.ready) return;
	dl.log.push('- processing onload code');
	if(dl.load.length) eval(dl.load.join(';'));
	dl.process();
	if(dl.w.init) init();
	dl.log.push('#onload code executed');
	dl.ready=1;
};
dl.loading=function()
{	if(dl.is.gk||dl.is.pr) dl.evt.add(dl.d,'DOMContentLoaded',dl.onload);
    if(dl.is.wk)
	{	if(/loaded|complete/.test(dl.d.readyState)) dl.onload();
       	else {setTimeout(arguments.callee,10);return;}
	}
	if(dl.is.tr)
	{	try{dl.d.documentElement.doScroll("left");}
		catch(e){setTimeout(arguments.callee,10);return;}
		dl.onload();
	}
	dl.evt.add(dl.w,'load',dl.onload);
}
dl.loading();
/* html elements dynamic manipulations */
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(atr,val)
	{	//trace(el[atr]);
		if(!val) return (atr=='class')? el.className : (el.hasAttribute&&el.hasAttribute(atr))?el.getAttribute(atr):el[atr];
		else (atr=='class')? el.className=val:el.setAttribute(atr,val,false);
	return el;
	}
	el.css=function(prop,val)
	{	if(!val) return el.style[prop];
		else el.style[prop]=val;
	return el;
	}
	el.on=function(disp){el.css('display',(disp? disp:'block')); return el;}
	el.off=function(){el.css('display','none'); return el;}
	dl.els[id]=el;
return el;
}
dl.is.el=function(id){return dl.d.getElementById(id);}
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 */
}
function url(page)
{	self.location.href=page;
}
dl.url=url;

/* Automatic objects creation */

dl.tags=[];
dl.make=function(tag,par){if(tag) dl.tags[tag]=par||'dlo'; return dl;}
dl.process=function()
{//	trace(dl.tags);
	for(tag in dl.tags)
	{
		dl.log.push('- processing ['+tag+'] tags');
		var par=dl.tags[tag];
		var els=dl.d.getElementsByTagName(tag);
		for(var i=els.length;i;)
		{	var el=els[--i];
			if(!el||!el.id||!par) continue;
			var ob=dl.el(el.id).attr(par);
		//	trace(el.id+'->'+par);
			if(ob) (dl.w[ob])? dl.els[el.id].ob=new dl.w[ob](el.id) : 0;//dl.error('no ptototype '+ob+' found','dynlite.js','dl.process()','Runtime');
		}
	}
}
/* benchmark */
dl.mt=new Date();
dl.smt=function(){dl.mt=new Date();return this;}
dl.gmt=function(){return new Date()-dl.mt;}
/* shortcuts */
trace=dl.trace;
/* keep the comment and use freely! end of code, enjoy... */
