/*==============================
  ProbelJS 0.37 Alpha
  javascript library

  Copyright (c) ZNS team(Nesterov A., Zdanov S., Logvinenko M.), 2008
  http://www.znsdev.ru

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
	 claim that you wrote the original software. If you use this software
	 in a product, an acknowledgment in the product documentation would be
	 appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
	 misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

==============================*/

;new function(){
// --------------------- LEVEL 1 ------------------------
// ---  probelJS object and extender                  ---
// ------------------------------------------------------

if(window.probelJS)return;

// main object
window.probelJS=({
	probelJS:'ZNS ProbelJS v0.37'
});

// browser detect

window.probelJS.browser=((window.opera&&'opera')
	||(navigator.userAgent.match(/AppleWebKit/)&&'safari')
	||(navigator.userAgent.match(/MSIE/)&&document.all&&'ie')
	||(navigator.userAgent.match(/Gecko/)&&'mozilla')
	||'unknown');


//extender
var $cpyarray;
window.$cpy=probelJS.$cpy=function(t,s){if(s){for(var i in s){t[i]=s[i]}}return t;};

// --------------------- LEVEL 2 ------------------------
// ---  functions for existing types & json           ---
// ------------------------------------------------------

// Object
$cpy(Object.prototype,{
	/*clone:function(){ return $cpy({},this); }/*,*
	toJSON:function(){var r=[],v;for(var k in this){v=(this[k].toJSON)?(this[k].toJSON()):String(this[k]);if(v!==undefined)r.push(k+':'+v)}return'{'+r.join(',')+'}'}/**/
});

// Array

_break=function(){throw Array._breaker; };
$cpy(Array,{
	_breaker:{},
	build:function(x){var r=[],i=0,m=x.length||0;for(;i<m;i++){r.push(x[i])}return r;}
});
$cpy(Array.prototype,{
	walk:function(fn){
		var i=0,m=this.length||0;
		try{77
			for(;i<m;i++){
				this[i]=fn(this[i],i);
			}
		}catch(e){
			if(e!=Array._breaker)throw e;
		}
		return this
	},
	revwalk:function(fn){
		var i=(this.length||0)-1;
		try{
			for(;i>=0;i--){
				this[i]=fn(this[i]);
			}
		}catch(e){
			if(e!=Array._breaker)throw e;
		}
		return this
	},
	clean:function(){
		var i=0,j=0,m=this.length||0;
		for(;i<m;i++){
			if(this[i]&&this[i]!=''){
				if(j<i)this[j]=this[i];
				j++
			}
		}
		this.length=j;
		return this
	},
	filter:function(fn){
		var i=0,j=0,m=this.length||0;
		try{
			for(;i<m;i++){
				if(fn(this[i])){
					if(j<i)this[j]=this[i];
					j++
				}
			}
		}catch(e){
			if(e!=Array._breaker)throw e;
		}
		this.length=j;
		return this
	},
	clone:function(a){
		var i=0,m=a.length||0,r=new Array();
		for(;i<m;i++){r[i]=a[i]}r.length=m;
		return r
	},
	search:function(el,st){
		if(typeof(el)!='function'&&this.indexOf)return this.indexOf(el);
		var i=st||0,m=this.length||0,f=(typeof(el)=='function')?el:function(x){return x==el};
		try{for(;i<m;i++){if(f(this[i]))return i;}}catch(e){if(e!=Array._breaker)throw e;}
		return -1;
	},
	flat:function(){
		var i=0,m=this.length||0,r=[];
		for(;i<m;i++){r=r.concat((this[i].flat)?this[i].flat():[this[i]])}
		return r
	},
	uniq:function(){
		var i=0,m=this.length||0,r=[];
		for(;i<m;i++){r.push_uniq(this[i])}
		return r
	},
	push_uniq:function(x){
		if(this.search(x)<0)this.push(x);
		return this
	},
	remove:function(x){
		var i=this.search(x);
		if(i>=0){ this.splice(i,1) }
		return this
	},
//	push_multi:function(){return (this=this.concat(arguments))},
	toObject:function(g){
		var i=0,m=this.length||0,r={},g=(typeof(g)=='function')&&g;
		for(;i<m;i++){r[g?g(v,i):i]=this[i]}
		return this
	},
	toJSON:function(){
		var i=0,m=this.length||0,r=[];
		for(;i<m;i++){r.push(this[i].toJSON())}
		return'['+r.join(',')+']'
	}
});

// Function
Function.prototype.closure=function(obj){
		var id=this.__cfnid=Function.closured.length;
		var rfn=function(){ return Function.closured[id].fn.call(Function.closured[id].obj,arguments); };
		Function.closured[id]={
			fn:this,
			obj:obj
		};
		obj=null;
		return rfn;
	};
Function.prototype.toJSON=function(){return ''};

Function.closured=[];

// Number
$cpy(Number.prototype,{
	//####
	isFinite:function(){return(String(this-this)!='NaN')},
	clamp:function(a,b){return (this<a?a:this>b?b:this)},
	padZeros:function(dc,b){var n=Number(this),res='',b=b||10;while((dc--)>0){res=Math.floor(n%b)+res;n=Math.floor(n/b)}return res},
	toBase:function(b){var n=Number(this),res='';while(n){res=Math.floor(n%b)+res;n=Math.floor(n/b)}},
	toHex:function(){return this.toBase(16)},
	toJSON:function(){return this.toString()}
});

// String
$cpy(String,{
	repeat:function(ch,l){
		var r='';
		while(l){
			if(l&1)r+=ch;
			ch+=ch;
			l>>=1;
		}
		return r;
	}
});
$cpy(String.prototype,{
	//####
	put:function(){var i=0,m=arguments.length,t=this;for(;i<m;i++)t=t.replace('{'+i+'}',arguments[i]);return t},
	trim:function(){return this.replace(/^\s*(.*)\s*$/,"$1")},
	ltrim:function(){return this.replace(/^\s*(.*)$/,"$1")},
	rtrim:function(){return this.replace(/^(.*)\s*$/,"$1")},
	escape:function()
	{
		var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\','<':'&lt;',
		'>':'&gt;','\'':'\\\'','\"':'\\\"'},r=/["\\\x00-\x1f\x7f-\x9f<>'\"]/g,h=this.valueOf();
		return h.replace(r,function(a){var c=m[a];if(c){return c;}c=a.charCodeAt();return '\\u00'+
			((c>>8)&15).toString(16)+((c>>4)&15).toString(16)+(c&15).toString(16);});
	},
	eschtml:function(){
		return this.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;');
	},
	toJSON:function(){return'"'+this.escape()+'"'}
});

//Date
$cpy(Date,{
	fromAll:function(y,m,d,h,n,s,o){return(new Date()).setAll(y,m,d,h,n,s,o);},
	getMonthDays:function(y,m){var de=(new Date());de.setDate(1);de.setAll(Number(y)||1970,Number(m||0)+1,0);return de.getDate()}
});
$cpy(Date.prototype,{
	reset:function(){this.setFullYear(1970);this.setMonth(0);this.setDate(1);this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this},
	setAll:function(y,m,d,h,n,s,o){this.reset();this.setFullYear(y||1970);this.setMonth(m||0);this.setDate((d!==undefined)?d:1);this.setHours(h||0);this.setMinutes(n||0);this.setSeconds(s||0);this.setMilliseconds(o||0);return this},
	clone:function(){return (new Date(this))},
	toJSON:function(){ return "new Date('"+this.valueOf+"')"}
});

// --------------------- LEVEL 3 ------------------------
// ---  dom-elements control                          ---
// ------------------------------------------------------

$cpy(probelJS,{
	HTML:function(html)
	{
		var r,ins,h;
		h=html.replace(/^\s+/g,'');
		h=h.replace(/\s+$/g,'');
		h=h.toLowerCase();
		if(!h.indexOf('<opt')){
			r='<select>'+html+'</select>'; ins=1;
		}else{
			r=html; ins=0;
		}
		var p=document.createElement('div');
		p.innerHTML=r;
		while(ins--){ p=p.firstChild; }
		var e=[];
		for(var i=0,m=p.childNodes.length;i<m;i++)e.push(p.childNodes[i]);
		return $cpyarray(e,probelJS.ex,probelJS.exm);
	},
	emptyfn:function(){},
	returnfn:function(a){return a},
	truefn:function(){},
	falsefn:function(){},
	'to be continued':true
});

var css2js=function(n){return n.replace(/-[a-z]/ig,function(c){return c.substr(1).toUpperCase()})};
//var css2js=function(p){var t;return (t=p.split('-')).shift()+t.walk(function(e){return e.charAt(0).toUpperCase()+e.substr(1)}).join('')};
var js2css=function(n){ return n.replace(/[A-Z]/g,"-$1").toLowerCase() };

probelJS.ex=({
	//Extender marker
	__probelJS:{},
	//DOM Manipulation
	SubItem:function(t,p,b){
		var p=p||{},x=$(document.createElement(t)),s=(p.style)||{};
		delete p.style; $cpy(x,p); $cpy(x.style,s);
		if(b){this.insertBefore(x,b)}else{this.appendChild(x)}
		return x
	},
	CreateItem:function(t,p){
		var p=p||{},x=$(document.createElement(t)),s=(p.style)||{};
		delete p.style; $cpy(x,p); $cpy(x.style,s);
		return x
	},
	//
	Insert:function(p){
		p.appendChild(this);
		return this
	},
	InsertAfter:function(a){
		var p=a.parentNode,b=a.nextSibling;
		if(!b)p.appendChild(this);
		else p.insertBefore(this,b);
		return this
	},
	InsertBefore:function(b){
		b.parentNode.insertBefore(this,b);
		return this
	},
	Remove:function(){
		this.parentNode.removeChild(this);
		return this
	},
	Replace:function(n){
		this.parentNode.replaceChild(n,this);
		return this
	},
	Swap:function(n){
		var s=this.nextSibling,p=this.parentNode;
		this.Replace(n);
		if(!s)p.appendChild(n);
		else p.insertBefore(n,s);
		return this
	},
	//DOM Checks
	contains:function(t)
	{
		var t=t||null;
		do{
			if(t==this)return true;
		}while(t=t.parentNode);
		return false;
	},
	//DOM Enumeration
	Parents:function()
	{
		var e=this.parentNode,r=[];
		while(e&&e.tagName){ r.push(e); e=e.parentNode; }
		return $cpyarray(r)
	},
	//DOM Events
	listen:function(evname,func,scope){
		var fn=E.createWrapper(scope||this,func);
		this.listen_asis(evname,fn);
		fn=null;
		return this;
	},
	listen_asis:function(e,f,c){
		if(this.addEventListener)this.addEventListener(e,f,c||false);
		else if(this.attachEvent)this.attachEvent('on'+e,f);
		return this
	},
	unlisten:function(e,f,c){
		f=E.getWrapper(f);
		if(this.removeEventListener)this.removeEventListener(e,f,c||false);
		else if(this.detachEvent)this.detachEvent('on'+e,f);
		return this
	},
	//Object Behavior
	Behaviours:{},
	behave:function(n,d)
	{
		if(n)this.Behaviours[n]=d;
		for(var e in d){this.listen(e,d[e],false)}
		return this
	},
	unbehave:function(n)
	{
		var d=this.Behaviours[n];
		for(var e in d){this.unlisten(e,d[e],false)}
		delete this.Behaviours[n];
		return this
	},
	canBehave:function(n){ return !(this.Behaviours[n]===undefined) },
	//CSS class
	hasClass:function(c){ return (this.className.split(' ').search(c)!=-1) },
	addClass:function(c){ if(!this.hasClass(c))this.className+=(this.className?' ':'')+c; return this },
	removeClass:function(c){ this.className = this.className.split(' ').filter(function(el){return (el&&el!=c)}).join(' '); return this },
	toggleClass:function(c){ if(!this.hasClass(c))this.className+=(this.className?' ':'')+c;else this.removeClass(c); return this },
	//css properties
	css:function(v,a){ //### untested
		if(typeof(v)=='string')
		{
			var w=/*css2js(*/v/*)*/,r;
			if(arguments.length==1)
			{
				if(this.style && this.style[w])
				{ r=this.style[w]; }
				else if(document.defaultView && document.defaultView.getComputedStyle)
				{ r=document.defaultView.getComputedStyle(this,'')[w]; }
				else if(this.currentStyle)
				{
					if(w=='float')w='styleFloat';
					r=this.currentStyle[w]||this.currentStyle[v];
				}else return false;
				return r.replace(/\b(\d+)px\b/g,'$1');
			}else{
				a=(typeof(a)=='number' && v!='zIndex')?(String(a)+'px'):a;
				this.style[w]=a;
				return this;
			}
		}else if(typeof(v)=='object'){
			for(var x in v){
				this.style[x]=(typeof(v[x])=='number' && x!='z-index')?(String(v[x])+'px'):v[x];
			}
			return this;
		}else{
			var r={},rs;
			if(document.defaultView && document.defaultView.getComputedStyle)
			{
				rs=/*$cpy({},*/document.defaultView.getComputedStyle(this,'')/*)*/;
			}
			else if(this.currentStyle)
			{
				rs=/*$cpy({},*/this.currentStyle/*)*/;
				r['float']=rs['styleFloat'];
			}else
			return false;

/*			for(var k in rs){
				if(typeof r[k] !="function") r[k]=String(rs[k]).replace(/\b(\d+)px\b/g,'$1');
			}*/
			//#### more steps required for color
			// IE behaviour - border is "medium" == 2px by default
			return r;
		}
	},

	'to be continued':true
});

var descend=function(a,b){var t;while((t=b.shift())&&a[t]){a=a[t]};return a};
var prop=function(o,p){return descend(o,p.split('.'))};

probelJS.exm=({
	uid:0,
	ids:{},
	_class:function(x){
		var i=0,j=0,m=this.length;for(;i<m;i++){if((' '+this[i].className+' ').indexOf(' '+x+' ')>=0){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	_tag:function(x){
		var i=0,j=0,m=this.length;for(;i<m;i++){if(this[i].nodeName.toLowerCase()==x.toLowerCase()){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	_id:function(x){
		var i=0,j=0,m=this.length;for(;i<m;i++){if(this[i].id==x){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	_attr:function(x,y,z)
	{
		var i=0,j=0,m=this.length,r;for(;i<m;i++){r=this[i].attributes.getNamedItem(x);if(z((r&&r.value)||undefined,y)){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	_hasattr:function(x)
	{
		var i=0,j=0,m=this.length,r;for(;i<m;i++){r=this[i].attributes.getNamedItem(x);if(r&&r.specified){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	_prop:function(x,y,z)
	{
		var i=0,j=0,m=this.length;for(;i<m;i++){if(z(descend(this[i],x),y)){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	_notattr:function(x,y,z)
	{
		var i=0,j=0,m=this.length,r;for(;i<m;i++){r=this[i].attributes.getNamedItem(x);if(!z((r&&r.value)||undefined,y)){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	_nothasattr:function(x)
	{
		var i=0,j=0,m=this.length,r;for(;i<m;i++){r=this[i].attributes.getNamedItem(x);if(!r||!r.specified){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	_notprop:function(x,y,z)
	{
		var i=0,j=0,m=this.length;for(;i<m;i++){if(!z(descend(this[i],x),y)){if(j!=i)this[j]=this[i];j++}}this.length=j;return this
	},
	Childs:function(tagname)
	{
		var t=$cpy([],probelJS.exm),i=0,j=0,m=this.length,l;for(;i<m;i++){for(j=0,l=this[i].childNodes[0];l=this[i].childNodes[j];j++){if((!tagname||l.nodeName==tagname)&&l.nodeType==1)t.insertUnique(l)}}return $cpyarray(t)
	},
	After:function()
	{
		var t=$cpy([],probelJS.exm),i=0,j=0,m=this.length,n;for(;i<m;i++){for(n=this[i].nextSibling;n;n=n.nextSibling){if(n.nodeType==1){t.insertUnique(n)}}}return $cpyarray(t)
	},
	AfterOne:function()
	{
		var t=$cpy([],probelJS.exm),i=0,j=0,m=this.length,n;for(;i<m;i++){n=this[i];while(n=n.nextSibling){if(n.nodeType==1)t.insertUnique(this[i].nextSibling)}}return $cpyarray(t)
	},
	AllChilds:function(tagname)
	{
		tagname=tagname||'*';var t=$cpy([],probelJS.exm),i=0,j=0,m=this.length,l,r;for(;i<m;i++){r=this[i].getElementsByTagName(tagname);for(l=r[0],j=0;l=r[j];j++){t.insertUnique(l)}}return $cpyarray(t)
	},
	insertUnique:function(el)
	{
		var i=0,j=0,u=0,m=this.length;
		if(!el.__probelJS_uid){el.__probelJS_uid=probelJS.exm.uid++}
		if(!this.ids[el.__probelJS_uid]){this.ids[el.__probelJS_uid]=true;this[this.length]=el}
		return this
	},
	_clean:function()
	{
		var i=0,j=0,m=this.length;for(;i<m;i++){var y=this[i];if(probelJS.browser!='ie'){delete y.__probelJS_uid}else{y.removeAttribute('__probelJS_uid');}}this.ids=({});return this
	},
	add:function(s)
	{
		var t=s;
		if(typeof(t)=='string') t=$$(t);
		for(var i=0,m=t.length;i<m;i++) this.insertUnique(t[i]);
		return this.clean();
	}
// Discuss this one:
/*	,
	walk:function(fn){
		var i=0,m=this.length||0;try{for(;i<m;i++){this[i]=fn($(this[i]),i);}}catch(e){if(e!=Array._breaker)throw e;}return this
	},
	revwalk:function(fn){
		var i=(this.length||0)-1;try{for(;i>=0;i--){this[i]=fn($(this[i]),i);}}catch(e){if(e!=Array._breaker)throw e;}return this
	},
	filter:function(fn){
		var i=0,j=0,m=this.length||0;try{for(;i<m;i++){if(fn($(this[i]))){if(j<i)this[j]=this[i];j++}}}catch(e){if(e!=Array._breaker)throw e;}this.length=j;return this
	}*/
});

//LEVEL 3a: dom-events & DOMReady
var E=
probelJS.event=(probelJS.browser=='ie')?
	function()
	{
		var ev = window.event;
		ev.target = ev.srcElement || document;
		ev.relatedTarget = ev.fromElement!=ev.target ? ev.fromElement : ev.toElement;
		ev.timeStamp = ev.timeStamp || Date();
		//ev.original=window.event;
		var scrolls=probelJS.Offsets.getBodyScrolls();
		//offsets
		ev.mouseX=ev.clientX+scrolls.x;
		ev.mouseY=ev.clientY+scrolls.y;
		ev.preventDefault = function() {
			window.event.returnValue = false;
		};
		ev.noBubble = function(){
			window.event.cancelBubble = true;
		};
		return ev;
	}:
	function(e)
	{
		var ev = e;
		/*if (ev.target.nodeType == 3 || ev.target.nodeType == 8) // defeat Safari bug
			ev.target = ev.target.parentNode;*/
		//ev.timeStamp = ev.timeStamp || Date();
		//fix keys - microsoft model
		ev.mouseButton = ({0:1,1:4,2:2})[ev.button];
		ev.mouseX=ev.pageX;
		ev.mouseY=ev.pageY;
		ev.noBubble=ev.stopPropagation;
		//ev.ctrlKey = ev.metaKey;
		return ev;
	};

$cpy(probelJS.event,{
	destroy:(probelJS.browser=='ie')?function(ev){
		ev.target = ev.relatedTarget = ev.timeStamp = ev.pageX = ev.pageY =
		ev.preventDefault = ev.noBubble = null;
	}:function(){},
	fromEventToGlobal:function(e)
	{
		var x = e.pageX||e.clientX, y = e.pageY||e.clientY;
		if(probelJS.browser=='ie'){
			var scrolls=probelJS.Offsets.getBodyScrolls();
			x+=scrolls.x; y+=scrolls.y;
		}
		return ({x:x,y:y});
	},
	createWrapper:function(obj,fn)
	{
		var fnid=fn.fnid=this.fnid++;

		var wrapfn=this.wrapers[fnid]=function(e){
			e=E(e);
			var retval=wrapfn.fn.call(wrapfn.obj,e);
			E.destroy(e);
			return retval;
		};

		wrapfn.obj=obj;
		wrapfn.fn=fn;

		obj=null;
		fn=null;
		fnid=null;

		return wrapfn
	},
	getWrapper:function(fn)
	{
		if(!fn.fnid)return fn;
		return this.wrapers[fn.fnid] || fn;
	},
	eid:1,
	fnid:1,
	wrapers:[]
});

probelJS.DOMReady=function(f){
	if(!probelJS.DOMReady.fired){ probelJS.DOMReady.funcs.push(f); }
	else{ f(); return this; }
	if(typeof probelJS.DOMReady.fired=="undefined"){
		probelJS.DOMReady.fired=false;		
		var cb=function()
		{
			probelJS.DOMReady.fired=true;
			probelJS.DOMReady.funcs.walk(function(el){el()});
		};
		if(probelJS.browser=='mozilla'||probelJS.browser=='opera')
		{
			$(document).addEventListener("DOMContentLoaded",cb,false);
		}
		else/* if(probelJS.browser=='safari')*/	//using universal method for dom-ready check
		{
			var drtimer=setInterval(function(){if(document.getElementsByTagName('body')[0]===document.body){clearInterval(drtimer);cb()}},10);
		}
/*		else if(probelJS.browser=='ie') //canceled due to filtering problems
		{
			var dummy=location.protocol=="https:"?"https://javascript:void(0)":"javascript:void(0)";
			document.write("<script id=\"__ie_domready\" defer src=\""+dummy+"\"><\/script>");
			$("__ie_domready").onreadystatechange=function(){if(this.readyState=="complete"){cb()}};
		}*/
	}
};
probelJS.DOMReady.funcs=[];

// --------------------- LEVEL 4 ------------------------
// ---  ajax                                          ---
// ------------------------------------------------------

function makeHTTPrequest()
{
	if (window.XMLHttpRequest) return ({ro:new XMLHttpRequest()});
	else if (window.ActiveXObject) return ({ro:new ActiveXObject("Microsoft.XMLHTTP")});
	else return null;
};
probelJS.request = function(params)
{
	var params			= params			|| ({});
	var theend			= false;
	var method			= params.method		|| 'get';
		method			= method.toLowerCase();

	var url				= params.url		|| '';
	var data			= params.data		|| null;
	var sync			= (params.sync == false)?params.sync:true;

	//0 = uninitialized -- //1 = loading ++ //2 = loaded ++ //3 = interactive -- //4 = complete ++
	var loading			= params.loading	|| null;
	var loaded			= params.loaded		|| null;
	var complete		= params.complete	|| null;

	var success			= params.success	|| null;
	var error			= params.error		|| null;

	var timeout			= params.timeout	|| 5000;


	var xmlReqObj = makeHTTPrequest ();
	var xmlReq = xmlReqObj.ro;

	/* setting request limit timer */
	xmlReqObj.timeouted = false;
	var timedout = function() { if(error) error(); xmlReqObj.timeouted = true; }
	var progressLimiter = setTimeout(timedout,timeout);


	datastring = '';
	if(data && typeof(data) == 'object' )
	{
		if(data.length){
			datastring='';
			data.walk(function(el,i){
				if(el instanceof Function)return el;
				if(i) datastring+=',';
				datastring += i+'='+encodeURIComponent(el);
				return el;
			});
		}else
		for(variable in data)
		{
			if(data[variable] instanceof Function)continue;
			if(datastring.length > 1) datastring += '&';
			datastring += encodeURIComponent(variable)+'='+encodeURIComponent(data[variable]);
		}
		if(method == 'get') url +='?'+datastring;
	}else if(data && typeof(data) == 'string')
	{
		datastring=data;
		if(method == 'get') url +='?'+datastring;
	}

	xmlReq.open(method,url,sync);
	xmlReq.setRequestHeader('X-Requested-With','XMLHttpRequest');

	if(method =='post' && datastring)
	{
		xmlReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlReq.setRequestHeader("Content-length", datastring.length);
	}
	xmlReq.onreadystatechange = function()
	{
		if(xmlReq.readyState == 1)
		{
			if(loading) loading(xmlReq);
		}
		else if(xmlReq.readyState == 2)
		{
			if(loaded) loaded(xmlReq);
		}
		else if(xmlReq.readyState == 4)
		{
			/* clear request limiter */
			clearTimeout(progressLimiter);

			if(complete)complete(xmlReq);
			if(xmlReqObj.timeouted) return false;

			if(xmlReq.status == 200 && success)
					success(xmlReq);
		}
	}
	xmlReq.send((method == 'post')?datastring:null);
	return xmlReq;
};
probelJS.getJSON = function(params)
{
	var user_success=params.success;
	var success=function(ajax){
		var obj=eval('('+ajax.responseText+')');
		if(user_success) user_success(obj);
	};
	params.success=success;
	return probelJS.request(params)
};
probelJS.getJS = function(params)
{
	var user_success=params.success;
	var success=function(ajax){
		var res=eval(ajax.responseText);
		user_success(res);
	};
	params.success=success;
	return probelJS.request(params)
};
probelJS.sendForm = function(params)
{
	var type	= (params.type||'json').toLowerCase();
	var frmobj 	= params.form || null;
	if(!frmobj) return false;
	var data 	= [];
	for(var i=0; field = frmobj.elements[i]; i++){
		if((field.type=="checkbox" || field.type=="radio") && !field.checked) continue;
		data.push(encodeURIComponent(field.name)+'='+encodeURIComponent(field.value));
	}
	params.url 		= frmobj.getAttribute('action') || params.url || '';
	params.method 	= frmobj.getAttribute('method') || params.method || 'post';
	params.data 	= data.join('&');
	if(type == 'ajax')		return probelJS.request(params);
	else if(type == 'json')	return probelJS.getJSON(params);
};

// --------------------- LEVEL 5 ------------------------
// ---  linkage functions                             ---
// ------------------------------------------------------

probelJS.getRelativePath=function(){
	//####
};
window.useCSS=probelJS.useCss=function(v){
	$(document.getElementsByTagName("head")[0]).SubItem("link",{href:v,type:"text/css",rel:"stylesheet"});
};
window.include=probelJS.include=function(src)
{
	var scripts=document.getElementsByTagName("script");
	var rx=new RegExp('^'+document.location.protocol+'//'+document.location.hostname+'(.*)$');
	if(scripts.search(function(sc){
		var loc=sc.src.match(rx);
		if(!loc)loc=sc.src;	else loc=loc[1];
		return (loc && loc==src)
	})<0)
	$(document.getElementsByTagName("head"))[0].SubItem("script",{src:src,type:"text/javascript"});
};
window.go=function(url){window.document.location=url;};

// --------------------- LEVEL 6 ------------------------
// ---  selectors                                     ---
// ------------------------------------------------------

$cpyarray=function(tgtobjarr) 
{
	for(var p in probelJS.ex){
		tgtobjarr[p]=(function(pn){
			return function(){var y=arguments;tgtobjarr.walk(function(v){$(v)[pn].apply(v,y);return v});return tgtobjarr}
		})(p);
	}
	for(var p in probelJS.exm){ tgtobjarr[p]=probelJS.exm[p]; }
	return tgtobjarr;
};

probelJS.old$=window.$;
probelJS.old$$=window.$$;

// never actualy used multiple arguments
/*window.$=probelJS.$=function(){
	if(!arguments.length)return probelJS;
	var r=Array.build(arguments);
	r.walk(function(q){
		if(q&&typeof(q)=='object'){if(!q.__probelJS)$cpy(q,probelJS.ex);return q;}
		else if(typeof(q)=='string'){
			q=document.getElementById(q);if(!q.__probelJS)$cpy(q,probelJS.ex);return q;
		}else return q;
	});
	if(r.length==1)return r[0];
	else return $cpyarray(r,probelJS.ex,probelJS.exm); //### Array
};*/

//this one is simplier
var $=window.$=probelJS.$=function(q){
	if(!arguments.length)return probelJS;
	if(q&&typeof(q)=='object'){if(q && !q.__probelJS)$cpy(q,probelJS.ex);return q;}
	else if(typeof(q)=='string'){
		q=document.getElementById(q);if(q && !q.__probelJS)$cpy(q,probelJS.ex);return q;
	}else return q;
};

//css-kind selector
// Using this format:
//  tagname#id.classname[attribute_existance][attribute="equality"]{dom.property="equality"}
//
// operators (configurable):
//  =  - equal
//  ^= - begins with
//  $= - ends with
//  *= - contains
//  |= - starts with string and posibly hyphen
//  ~= - contains whole word
//  %= - matches regexp
//  @= - passed to function, wich returns true/false
// any operator can be preceded with ! reversing it's action
// e.g. img[src!^="/img/"] - find all images with invalid URIs
probelJS.ex.$$=function(str){
	var searcher;
	if(probelJS.ex.$$.prototype.cache[str]){
		searcher=probelJS.ex.$$.prototype.cache[str];
	}else with(probelJS.ex.$$.prototype){
		var result=str,lastresult="";
		var tagname;
		var code=[];
		var fn='';
		var g=[];
		code.push("({");
		code.push("query:function(st){var r=$cpy([],probelJS.exm);r[0]=st||document;");
		while(result!="" && result!=lastresult){
			lastresult=result;
			fn='AllChilds';
			if(g=rx[5].exec(result)){
				result=RegExp.rightContext;
				if(g[1]=='>'){fn='Childs'}
				else if(g[1]=='+'){fn='After'}
				else if(g[1]=='~'){fn='AfterOne'}
			}
			if(g=rx[0].exec(result)){
				tagname=g[1] || '*';
				result=RegExp.rightContext;	//### leeds to debugger fault
				// result=result.substr(g[0].length);	// use alternative method
				// result=result.replace(g[0],"");		// or this one
			}else{ tagname='*'; }
			if(tagname && tagname!='*')	code.push("r=(r."+fn+"('"+tagname.toUpperCase()+"')");
			else code.push("r=(r."+fn+"()");
			code.push("._clean()");
			if(g=rx[1].exec(result)){
				result=RegExp.rightContext;
				code.push("._class('"+g[1]+"')");
			}
			if(g=rx[2].exec(result)){
				result=RegExp.rightContext;
				code.push("._id('"+g[1]+"')");
			}
			while(g=rx[3].exec(result)){
				result=RegExp.rightContext;
				if(g[3]!='' && g[3]!==undefined)
				{ code.push("._"+((g[2]=='!')?'not':'')+"attr('"+g[1]+"',"+g[4]+",this.ops['"+g[3]+"'])"); }
				else
				{ code.push("._"+((g[2]=='!')?'not':'')+"hasattr('"+g[1]+"')"); }
			}
			while(g=rx[4].exec(result)){
				result=RegExp.rightContext;
				code.push("._"+((g[2]=='!')?'not':'')+"prop(['"+g[1].split(".").join("','")+"'],"+g[4]+",this.ops['"+g[3]+"'])");
			}
			code.push(");");
		}
		code.push("this.result=r.walk(probelJS.$);}})");
		//code.push("this.result=r.walk(function(re){return $(re)})}})");
		try{searcher=eval(code.join(''))}catch(e){searcher={query:null}};
		searcher.ops=ops;
		cache[str]=searcher;
	}
	searcher.result=[];
	try{searcher.query(this)}catch(e){searcher.result=[]};
	return $cpyarray(searcher.result);
};
probelJS.ex.$$.prototype.cache=[];
probelJS.ex.$$.prototype.ops={
	"=":function(a,v){return a==v},
	"^=":function(a,v){return a&&a.substr(0,v.length)==v},
	"$=":function(a,v){return a&&a.substr(a.length-v.length)==v},
	"*=":function(a,v){return a&&a.indexOf(v)!=-1},
	"|=":function(a,v){return a&&(a==v||a.substr(0,v.length+1)==v+"-")},
	"~=":function(a,v){return a&&(" "+a+" ").indexOf(" "+v+" ")!=-1},
	"%=":function(a,v){return a&&a.match(v)},
	"@=":function(a,v){try{return v(a)}catch(e){return false}}
};
probelJS.ex.$$.prototype.rx=[
/^\s*(\*|\w*)/,
/^\.([\w-]+)/,
/^#([\w-]+)/,
/^\[(\w+)([!]?)(?:([~%\^*$@]?\=)((?:[^\]'"]|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")+))?]/,
/^\{([\w.\[\]]+)([!]?)([~%\^*$@]?\=)((?:[^\}'"]|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")+)}/,
/^\s*([>+~])?/
];

window.$$=probelJS.$$=function(){ return $(document).$$.apply(document,arguments); };

probelJS.restore$=function(){window.$=probelJS.old$;window.$$=probelJS.old$$};

probelJS.ex.un$=function(deep){
	if(!deep){this.__probelJS=null}
	else{
		for(var k in probelJS.ex){
			if(typeof this[k]=='undefined')continue;
			if(probelJS.browser!='ie') delete this[k];
			else{
				//You know why IE is the slowest browser?
				//Probably because it's forced to run twice more code
				try{ this.removeAttribute(k); }catch(e){}
			}
		}
	}
};

return probelJS;
};

//probelJS     only contains functions, callable without selectors
//probelJS.ex  contains functions for single selected element
//probelJS.exm contains functions for multiple selected elements
//
//Globals:
// window.$    - select by id and/or extend
// window.$$   - select by css and extend result array (elements are not extended)
//               (unlike old versions current modification always returns array )
// window.$cpy - copy objects (used for extensdions andd object cloning)

// ---------------------- LEVEL 7 -----------------------
// ---  Extensions                                    ---
// ------------------------------------------------------

probelJS.Class=function(e,b)
{
	var cl=function(){this.ctor.apply(this,arguments)};
	cl.prototype={};
	cl.prototype=$cpy(cl.prototype,b&&b.prototype);
	cl.prototype=$cpy(cl.prototype,e||{});
	cl.prototype.constructor=cl;
	cl.baseclass=b||null;
	if(b)cl.prototype.base=function(){ b.prototype.ctor.apply(this,arguments) };
	return cl;
};

// ------------------------------------------------------
// ---  Offsets                                       ---
// ------------------------------------------------------

(function(){
	probelJS.Rect = probelJS.Class({
		ctor:function(l,r,t,b){
			if(l){
				switch(typeof(l))
				{
					case 'string':
					case 'number':
						this.left=l;
						this.right=r;
						this.top=t;
						this.bottom=b;
					break;
					case 'object':
						if(l.parentNode)
						{
							var o=$(l).getOffsets();
							//var s=l.css();
							this.left=o.x;
							this.top=o.y;
							this.right=o.x+l.offsetWidth+l.css('borderLeftWidth')+l.css('borderRightWidth');
							this.bottom=o.t+l.offsetHeight+l.css('borderTopWidth')+l.css('borderBottomWidth');
						}else{
							$cpy(this,l);
						}
					break;
				}
			}
		},
		left:0,
		top:0,
		right:0,
		bottom:0,
		width:function(){return this.right-this.left},
		height:function(){return this.bottom-this.top},
		inflate:function(h,v){if(v===undefined)v=h;this.left-=h;this.right+=h;this.top-=v;this.bottom+=v;return this},
		add:function(r){this.left+=r.left;this.right+=r.right;this.top+=r.top;this.bottom+=r.bottom;return this},
		substract:function(r){this.left-=r.left;this.right-=r.right;this.top-=r.top;this.bottom-=r.bottom;return this},
		intersect:function(r){return !!(this.left <= r.right && this.right >= r.left && this.top <= r.bottom && this.bottom >= r.top)},
		toString:function(){ return ('Rect [{0},{1}]-[{2},{3}]').put(this.left,this.top,this.right,this.bottom); },
		valueOf:function(){ return ('Rect [{0},{1}]-[{2},{3}]').put(this.left,this.top,this.right,this.bottom); }
		//#### intersect union combine overlaped
	});
	var B=probelJS.browser;
	var qui=(document.compatMode!="CSS1Compat");
	var IEqui=(probelJS.browser=='ie')&&qui;
	var Fx2=(probelJS.browser=='mozilla')&&(!window.postMessage);
	var N=function(x){
		x=Number(x);
		return(x.isFinite()?x:0);
	};
	probelJS.Offsets={
		getBodyScrolls:function(){
			var top=window.pageYOffset||
				(!IEqui&&document.documentElement&&document.documentElement.scrollTop)||
				(document.body&&document.body.scrollTop);
			var left=window.pageXOffset||
				(!IEqui&&document.documentElement&&document.documentElement.scrollLeft)||
				(document.body&&document.body.scrollLeft);
			return ({x:left,y:top});
		},
		getPageArea:function()
		{
			return (qui)?
				({w:document.documentElement.scrollWidth,h:document.documentElement.scrollHeight}):
				({w:document.body.scrollWidth,h:document.body.scrollHeight});
		},
		getBodyArea:function()
		{
			var w=this.getClientArea(),p=this.getPageArea();
			return ({w:Math.max(w.w,p.w),h:Math.max(w.h,p.h)});
		},
		getClientArea:function()
		{
			if(probelJS.browser=='ie')
			{
				return(qui)?
					({w:document.body.clientWidth,h:document.body.clientHeight}):
					({w:document.documentElement.clientWidth,h:document.documentElement.clientHeight});
			}else{
				return ({w:window.innerWidth,h:window.innerHeight});
			}
		}
	};
	$cpy(probelJS.ex,{
		// get offsets for inner top-left corner of element (width+padding)
		getOffsets:
		(((document.body||document.documentElement).getBoundingClientRect)!==undefined)?
		function()
		{
			var l=0,t=0;
			if(this==document.body || this==document.documentElement)return({x:0,y:0});
			var box=this.getBoundingClientRect();
			l = box.left + N(this.css('borderLeftWidth'))-N(document.documentElement.clientLeft)+N(document.documentElement.scrollLeft);
			t = box.top  + N(this.css('borderTopWidth')) -N(document.documentElement.clientTop)+N(document.documentElement.scrollTop);
			return ({x:l,y:t});
		}:
		function()
		{
			var s=this,l=0,t=0;
			var Top=(document.body||document.documentElement);
			if(this==document.body || this==document.documentElement)return({x:0,y:0});
/*			if(this.getBoundingClientRect)	//IE & FFx 3
			{
				var box=this.getBoundingClientRect();
				l = box.left + N(this.css('borderLeftWidth'))-N(document.documentElement.clientLeft);
				t = box.top  + N(this.css('borderTopWidth')) -N(document.documentElement.clientTop);
				return ({x:l,y:t});
			}*/
			if(B=='opera'){
				l+=N(s.css('borderLeftWidth'));
				t+=N(s.css('borderTopWidth'));
			}
			while(s&&Top!=s){

				l+=N(s.offsetLeft);	t+=N(s.offsetTop);

				if(B=='safari'
					||B=='ie'&&!(/^table$/i.test(s.tagName))
					||B=='mozilla'&&!(/^table|td|th$/i.test(s.tagName)))
				{
					l+=N(s.css('borderLeftWidth'));
					t+=N(s.css('borderTopWidth'));
				}
				//#### find more bugs :)

				//don't stop on iframes: - jQ does not support this one
/*				if(s.tagName=='BODY'||s.tagName=='HTML')
				{
					if(probelJS.browser=='ie'){
						if(!(s=s.ownerDocument.parentWindow.frameElement))break;
						if(s.frameBorder!="0" && s.frameBorder!="no")
						{ 
							l+=2; t+=2; //frameborder width may change!
						}
					}else{
						if(!(s=s.ownerDocument.defaultView.frameElement))break;
					}
					s=$(s);
					continue;
				}*/
				s=$(s.offsetParent);
			}
			
			s=$(this.parentNode);
			var fx_absolute=(this.css('position')=='absolute');
			var ie_relative=(this.css('position')=='relative');

			while(s&&Top!=s)
			{
				//opera reports wrong scrolls for
				if(B=='opera' && (/^tr$/i.test(s.tagName)||/^(inline|table-row)$/i.test(s.css("display")))){
					s=$(s.parentNode);
					continue;
				}

				var pos=s.css('position');
				if(pos=='absolute') fx_absolute=true;
				if(pos=='relative') ie_relative=true;

				l-=N(s.scrollLeft);
				t-=N(s.scrollTop);

				if(Fx2&&(s.css('overflow')!='visible')) //FF 2 has bug with overflow!=visible
				{
					l+=N(s.css('borderLeftWidth'));
					t+=N(s.css('borderTopWidth'));
				}
/*				if(s.tagName=='BODY'||s.tagName=='HTML')
				{
					if(B=='mozilla' && !fx_absolute)
					{
						l+=N(s.css('border-left-width'));
						t+=N(s.css('border-top-width'));
						fx_absolute=false;
					}
					if(B=='ie'){
						if(!(s=s.ownerDocument.parentWindow.frameElement))break;
						if(ie_relative) ie_relative=false;
					}else{
						if(!(s=s.ownerDocument.defaultView.frameElement))break;
					}
					s=$(s);
					continue;
				}*/
				s=$(s.parentNode);
			};
			if(B=='mozilla' && !fx_absolute && s==Top)
			{
				l+=N(s.css('borderLeftWidth'));
				t+=N(s.css('borderTopWidth'));
			}
			if(B=='ie' && !ie_relative && s==Top)
			{
				l+=N(s.css('borderLeftWidth'))+N(s.css('marginLeft'));
				t+=N(s.css('borderTopWidth'))+N(s.css('marginTop'));
			}
			return({x:l,y:t});
		},
		//get size of inner area
		getSize:function()
		{
			var w=N(this.offsetWidth)-N(this.css('borderLeftWidth'))-N(this.css('borderRightWidth')),
				h=N(this.offsetHeight)-N(this.css('borderTopWidth'))-N(this.css('borderBottomWidth'));
			return ({w:w,h:h});
		},
		getOffsetsRelative:function(e)
		{
			var a=e.getOffsets(),b=$(this.offsetParent)?this.offsetParent.getOffsets():({x:0,y:0});
			return ({x:a.x-b.x,y:a.y-b.y});
		},
		getRect:function(k)
		{
			var k = $cpy({
				margin:false,
				border:false,
				padding:true
			},k||{});

			var o=this.getOffsets();
			//var s=this.css();
			var r=new probelJS.Rect();
			if(!k.border) //content rect & padding
			{
				r.left=o.x;
				r.top=o.y;
				r.right=o.x+N(this.clientWidth||
				(N(this.offsetWidth)-N(this.css('borderLeftWidth'))-N(this.css('borderRightWidth')))
				);
				r.bottom=o.y+N(this.clientHeight||
				(N(this.offsetHeight)-N(this.css('borderTopWidth'))-N(this.css('borderBottomWidth')))
				);
				if(!k.padding)	//only content rect
				{
					r.left+=N(this.css('paddingLeft'));
					r.top+=N(this.css('paddingTop'));
					r.right-=N(this.css('paddingRight'));
					r.bottom-=N(this.css('paddingBottom'));
				}
			}else if(!k.margin) //content box & border
			{
				r.left=o.x-N(this.css('borderLeftWidth'));
				r.top=o.y-N(this.css('borderTopWidth'));
				r.right=r.left+N(this.offsetWidth);
				r.bottom=r.top+N(this.offsetHeight);
			}else{			//box including margin
				r.left=o.x-N(this.css('borderLeftWidth'));
				r.top=o.y-N(this.css('borderTopWidth'));
				r.right=r.left+N(this.offsetWidth)+N(this.css('marginRight'));
				r.bottom=r.top+N(this.offsetHeight)+N(this.css('marginRottom'));
				r.left-=N(this.css('marginLeft'));
				r.top-=N(this.css('marginTop'));
			}
			return r;
		},
		setPosition:function(x)
		{
			this.style.left=x.x+'px';
			this.style.top=x.y+'px';
			return this;
		},
		setOffset:function(x)
		{
			var p=x.relative
				||this.offsetParent && $(this.offsetParent).getOffsets()
				||{x:0,y:0};
			var s=this.css('position');
			var l=N(this.css('borderLeftWidth')),
				t=N(this.css('borderTopWidth'));
			if(s!='absolute')
			{
				if(s!='relative')this.css('position','absolute');
				else{
					l+=N(this.offsetLeft)-N(this.css('left')),
					t+=N(this.offsetTop)-N(this.css('top'));
					this.css('left',x.x-p.x-l);
					this.css('top', x.y-p.y-t);
					return this;
				}
			}
			this.css('left',x.x-p.x-l);
			this.css('top', x.y-p.y-t);
			return this;
		},
		//set padding-box size
		setSize:function(sz)
		{
			sz.h=sz.h||0;
			sz.w=sz.w||0;
			var q=this.getBoxType();
			//var s=this.css();
			if(!q)
			{
				sz.h-=N(this.css('paddingTop'))+N(this.css('paddingBottom'));
				sz.w-=N(this.css('paddingLeft'))+N(this.css('paddingRight'));
				//sz.h-=N(s.paddingTop)+N(s.paddingBottom);
				//sz.w-=N(s.paddingLeft)+N(s.paddingRight);
			}else if(q==2){// mozilla has more complex sizing
				sz.h+=N(this.css('borderTopWidth'))+N(this.css('borderBottomWidth'));
				sz.w+=N(this.css('borderLeftWidth'))+N(this.css('borderRightWidth'));
			}
			try{
				this.style.width=sz.w+'px';
				this.style.height=sz.h+'px';
			}catch(e){
				sysconsole.d$(sz);
			}
			return this;
		},
		setRect:function(r,k)
		{
			var k = $cpy({
				margin:false,
				border:false,
				padding:true,	
				relative:null
			},k||{});

			//var s=this.css();
			if(!k.padding)	//only content rect
			{
				//
				r.left-=N(this.css('paddingLeft'));
				r.top-=N(this.css('paddingTop'));
				r.right+=N(this.css('paddingRight'));
				r.bottom+=N(this.css('paddingBottom'));
			}else if(!k.border) //content rect & padding
			{
			}else if(!k.margin) //content box & border
			{
				r.left+=N(this.css('borderLeftWidth'));
				r.top+=N(this.css('borderTopWidth'));
				r.right-=N(this.css('borderRightWidth'));
				r.bottom-=N(this.css('borderBottomWidth'));
			}else{			//box including margin
				r.left+=N(this.css('borderLeftWidth'))+N(this.css('marginLeft'));
				r.top+=N(this.css('borderTopWidth'))+N(this.css('marginTop'));
				r.right-=N(this.css('borderRightWidth'))+N(this.css('marginRight'));
				r.bottom-=N(this.css('borderBottomWidth'))+N(this.css('marginBottom'));
			}
			this.setSize({w:r.width(),h:r.height()}).setOffset({x:r.left,y:r.top,relative:k.relative});
			return this;
		},
		//returns:
		// 0 - W3C box model
		// 1 - IE box model
		// 2 - Full box sizing (content+padding+border)
		getBoxType:function()
		{
			if(IEqui)return 1;
			else if(probelJS.browser=='mozilla')
			{
				var y=this.css('MozBoxSizing'); //the simpliest way is to ask
				if(y=='padding-box')return 1;
				else if(y=='border-box')return 2;
			}
			else if((qui?/^(input|select|textarea)$/i:/^select$/i).test(this.tagName))return 1;
			return 0;
		},

		// attachment
		attachment:function(forobj,params)
		{
			if(!this.is_shown())return false;
			var rect1 = this.getRect(),rect2 = forobj.getRect(),rect3 = new probelJS.Rect;
			var params=$cpy({
				left:0,
				right:0,
				top:0,
				bottom:0,
				anchors:'l-t-'
			},params);

				 if(params.anchors.charAt(0)=='l'){ rect3.left  = rect2.left; }
			else if(params.anchors.charAt(0)=='r'){ rect3.left  = rect2.right; }
			else if(params.anchors.charAt(0)=='c'){ rect3.left  = (rect2.left + rect2.right)/2; }
			else if(params.anchors.charAt(0)=='-'){ rect3.left  = rect1.left; }

				 if(params.anchors.charAt(1)=='l'){ rect3.right = rect2.left; }
			else if(params.anchors.charAt(1)=='r'){ rect3.right = rect2.right; }
			else if(params.anchors.charAt(1)=='c'){ rect3.right = (rect2.left + rect2.right)/2; }
			else if(params.anchors.charAt(1)=='-'){ rect3.right = rect1.right; }

				 if(params.anchors.charAt(2)=='t'){ rect3.top   = rect2.top; }
			else if(params.anchors.charAt(2)=='b'){ rect3.top   = rect2.bottom; }
			else if(params.anchors.charAt(2)=='c'){ rect3.top   = (rect2.top + rect2.bottom)/2; }
			else if(params.anchors.charAt(2)=='-'){ rect3.top   = rect1.top; }

				 if(params.anchors.charAt(3)=='t'){ rect3.bottom= rect2.top; }
			else if(params.anchors.charAt(3)=='b'){ rect3.bottom= rect2.bottom; }
			else if(params.anchors.charAt(3)=='c'){ rect3.bottom= (rect2.top + rect2.bottom)/2; }
			else if(params.anchors.charAt(3)=='-'){ rect3.bottom= rect1.bottom; }

				 if(params.anchors.charAt(0)=='-'){ rect3.left  = rect3.right  - rect1.width();  }
			else if(params.anchors.charAt(1)=='-'){ rect3.right = rect3.left   + rect1.width();  }
				 if(params.anchors.charAt(2)=='-'){ rect3.top   = rect3.bottom - rect1.height(); }
			else if(params.anchors.charAt(3)=='-'){ rect3.bottom= rect3.top    + rect1.height(); }

			rect3.left  +=params.left;
			rect3.right +=params.right;
			rect3.top   +=params.top;
			rect3.bottom+=params.bottom;

			this.setRect(rect3);

			return this;
		},
		'to be continued':true
	});
})();

// ------------------------------------------------------
// ---  Cookies                                       ---
// ------------------------------------------------------

probelJS.Cookies={
	get:function(name){
		var n = name + "=",res=null;
		document.cookie.split(';').walk(function(c){
			if(c.ltrim().indexOf(n)==0) res=c.substr(n.length);
		});
		return res;
	},
	set:function(name,path,expires){
		if (expires) {
			var date = new Date();
				date.setTime(date.getTime()+(expires*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		var path = path || '/';
		document.cookie = name+"="+value+expires+"; path="+path;
	},
	remove:function(name){
		probelJS.Cookies.set(name,'/',-60);
	},
	getAll:function(){
		var res={};
		document.cookie.split(';').walk(function(c){
			var v=c.match(/^(.*?)[=](.*)/);
			res[v[1]]=v[2];
		});
		return res;
	}
};

// ------------------------------------------------------
// ---  UI extensions                                 ---
// ------------------------------------------------------

probelJS.ui={
	_props:{

	},
	hold:{
		run:null,
		wait:null
	}
};

$cpy(probelJS.ex,{
	//Display property
	hide:function(){ this.style.display='none'; return this },
	show:function(){ this.style.display=''; return this },
	toggle:function(){ if(this.is_shown())this.hide();else this.show(); return this },
	swap:function(a){ if(this.is_shown()){this.hide();a.show()}else{this.show();a.hide()} return this },
	is_shown:function(){ return (this.style.display!='none'); }
});

// ------------------------------------------------------
// ---  forms                                         ---
// ------------------------------------------------------
(function(){
	probelJS.Forms={
		enable_childs:function(el,enabled,prams)	//disable or enablre elements (supports anchors) 
		{
			$cpy({ selector:['input','textarea','button'],tabIndex:0 },params);
			var res=[];
			params.selector.walk(function(s){ 
				el.$$(s).walk(function(x){
					x.disabled=!!enabled;
					if(x.nodeName=='A'){
						if(!enable) x.tabIndex=prams.tabIndex;
						else if(probelJS.browser!='opera'){
							x.tabIndex=-1;
						}else{				// in opera anchors are not selectable,
							x.tabIndex='';	// ulnless they have non-empty tabIndex
						}
					}
				})
			});
		}
	};

	$cpy(probelJS.ex,{
		Value:function(v){
			if(v===undefined)return (this.value);
			else this.value = v;
			return this;
		},
		validate:function(){return true},
		require:function(reg){
			var el=this;
			el.lastvalue=el.value;
			el.listen('onkeyup',function(){
				if(!el.value.match(reg))el.value=el.lastvalue;
				else el.lastvalue=el.value;
			});
		}
	});

	probelJS.DataSource = probelJS.Class({
		ctor:function(params){
			$cpy(this,params);
			if(typeof(this.usehidden)=='string')
			{
				this.usehidden = $$('form')[0].SubItem('input',{type:'hidden',name:this.usehidden});
			}else if(this.usehidden && this.usehidden.value!==undefined && !this.data){
				this.Value(String(this.usehidden.value));
			}
		},
		usehidden:false,
		data:null,
		adapters:[],
		SetHiddenData:function(x){
			this.usehidden.Value(String(x));
		},
		Update:function(a){
			if(this.usehidden){	this.SetHiddenData(this.data) }
			if(this.adapters){
				for(var i=0,m=this.adapters.length;i<m;i++)
				{
					if(a!==this.adapters[i]) this.adapters[i].Update();
				}
			}
		},
		Convert:function(x){return x},
		Value:function(s,a){
			if(s===undefined){ 
				return this.data;
			}else{ 
				this.data=this.Convert(s);
				this.Update(a);
				return s;
			}
		},
		RegAdapter:function(a){   this.adapters.push_uniq(a); },
		UnregAdapter:function(a){ this.adapters.remove(a);    }
	});

	probelJS.Adapter = probelJS.Class({
		ctor:function(params){
			$cpy(this,params);
			this.Element=$(this.Element);
			var _this=this;
			if(this.Element){
				this.Element.Value=function(s){
					_this.Value(_this.Element.value);
					_this.Update();
				};
				this.BindEvent();
			}
			if(this.DataSource){
				this.DataSource.RegAdapter(this);
			}
		},
		useInputTimeout:null,
		BindEvent:function(){
			this.Element.listen('blur',function(e){
				this.Value(this.Element.value);
				this.Update();
			},this);
			if(this.useInputTimeout){
				var _this=this;
				this.Element.onInputTimeout(function(e){ _this.Value(_this.Element.value) },this.useInputTimeout);
			}
		},
		Element:null,
		DataSource:null,
		Value:function(s){
			if(s===undefined){
				return this.DataSource.Value();
			}else{
				this.DataSource.Value(s,this);
				return s;
			}
		},
		Update:function(){
			this.Element.value = this.Value();
		}
	});

	probelJS.Validator = probelJS.Class({
		ctor:function(params){
			$cpy(this,params);
			this.Element=$(this.Element);		
			var _this=this;
			this.BindEvents();
		},
		Element:null,
		Validate:function(){return true},
		BindEvents:function(){}
	});

	probelJS.FinalValidator = probelJS.Class({
		BindEvents:function(){
			var _this=this;
			$(this.Element).onInputTimeout(function(){_this.Check()});
		},
		Patern:null,
		CaseInsensitive:true,
		onInvalid:false,
		Validate:function(){
			if(typeof(this.Patern)=='string') this.Patern=new RegExp(this.Patern,this.CaseInsensitive?'mi':'m');
			return this.Patern.test(this.Element.Value());
		},
		Check:function(){
			if(this.onInvalid) this.onInvalid(this.Validate());
		}
	},probelJS.Validator);

	probelJS.InputValidator = probelJS.Class({
		BindEvents:function(){
			var _this=this;
			$(this.Element).listen('keyup',function(){this.Check()},this);
			$(this.Element).listen('blur',function(){this.Check()},this);
			this.LastValue=this.Element.Value();
		},
		Patern:null,
		LastValue:'',
		CaseInsensitive:true,
		onInvalid:false,
		Validate:function(){
			if(typeof(this.Patern)=='string') this.Patern=new RegExp(this.Patern,this.CaseInsensitive?'mi':'m');
			return this.Patern.test(this.Element.Value());
		},
		Check:function(){
			//if(this.onInvalid) this.onInvalid(this.Validate());
			if(!this.Validate()){ this.Element.Value(this.LastValue); }
			else{ this.LastValue=this.Element.Value(); }
		}
	},probelJS.Validator);

})();

// ------------------------------------------------------
// ---  complex behaviour                             ---
// ------------------------------------------------------

$cpy(probelJS.ex,{
	onInputTimeout:function(fn,params)
	{
		params=$cpy({
			timeout:300,
			blur_cancel:false
		},params||{});
		var timer=0;
		var tm=function()
		{
			try{clearTimeout(timer);}catch(e){}
			timer=setTimeout(fn,params.timeout);
		};
		this.listen('keyup',tm);
		this.listen('click',tm);
		this.listen('focus',tm);
		if(!params.blur_cancel) this.listen('change',tm);
		if(params.blur_cancel) this.listen('focus',function(){try{clearTimeout(timer);}catch(e){}});

		return this;
	},
	deselectable:function(cb,params)
	{
		var el=this;
		$(document).listen('mousedown',function(v){
			if(!el.contains(v.target||v.srcElement))
			{
				if(cb&&(el.style.display!='none')){ cb() }
				el.hide()
			}
		});
		return this
	},
	labeled: function(args)
	{
		var _this = this;
		var args=$cpy({
			label:'Type here',
			dcolor:'#797979',
			acolor:this.style.color||'',
			onDisplay:null,
			onHide:null,
			check:/^$/
		},args);
		_this.listen('blur',function(event){
			if(args.check.test(_this.value))
			{
				_this.value=args.label;
				_this.style.color=args.dcolor;
				_this.Labeled=true;
			}else{
				_this.Labeled=false;
			}
		});
		_this.listen('focus',function(event){
			if(_this.value == args.label && _this.Labeled)
			{
				_this.value = '';
				_this.style.color = args.acolor;
				_this.Labeled=false;
			}
		});
		if(args.check.test(_this.value))
		{
				_this.value=args.label;
				_this.style.color=args.dcolor;
				_this.Labeled=true;
		}
		return this;
	},	
	holdable:function(fn,tm1,tm2,scope)
	{
		var th=this;
		var tm1=tm1||100;
		var tm2=tm2||700;

		this.listen('mousedown',function(){
			if(probelJS.ui.hold.wait || probelJS.ui.hold.run)return;

			probelJS.ui.hold.wait=setTimeout(function(){
				probelJS.ui.hold.run=setInterval(fn,tm1);
				probelJS.ui.hold.wait=null;
			},tm2);
		});
		this.listen('mouseup',function(){
			if(probelJS.ui.hold.run){ clearInterval(probelJS.ui.hold.run);  probelJS.ui.hold.run=null; };
			if(probelJS.ui.hold.wait){ clearTimeout(probelJS.ui.hold.wait); probelJS.ui.hold.wait=null; };
		});
		this.listen('mouseout',function(){
			if(probelJS.ui.hold.run){ clearInterval(probelJS.ui.hold.run);  probelJS.ui.hold.run=null; };
			if(probelJS.ui.hold.wait){ clearTimeout(probelJS.ui.hold.wait); probelJS.ui.hold.wait=null; };
		});
	},
	centered:function(h,v)
	{
		if(this.style.display == 'none') return this;

		var h = h || true;
		var v = v || true;

		var x = 0;
		var y = 0;

		var s = this.getSize();
		var ws = probelJS.Offsets.getClientArea();
		s.h*=0.5; s.w*=0.5;

		var ofs=new probelJS.Rect();

		x = ws.w/2; y = ws.h/2;
		
		var scrollspos = probelJS.Offsets.getBodyScrolls();
		x += scrollspos.x;
		y += scrollspos.y;

		x -= s.w;
		y -= s.h;

		this.setOffset({x:x,y:y});
		return this;
	}
});

// ------------------------------------------------------
// ---  darg & drop                                   ---
// ------------------------------------------------------

// types of anchoring
// 0 - no anchors, using left property
// 1 - no anchors, using right property
// 2 - no anchors, using both left & right - noIE
// 3 - left anchor, using width
// 4 - left anchor, using right & width
// 5 - left anchor, using right
// 6 - right anchor, using left & width
// 7 - right anchor, using width
// 8 - right anchor, using left
// 9 - both anchors, no movement posible

/*probelJS.ex.move=function(s){
	var l=this.css('left');
	var r=this.css('right');
	var q=(l==undefined?0:1)+(r==undefined?0:2);
	if(!q)q=1;
	if(q&1) this.css('left',l+s.x);
	if(q&2) this.css('right',r-s.x);

	var t=this.css('top');
	var b=this.css('bottom');
	q=(t==undefined?0:1)+(b==undefined?0:2);
	if(!q) q=1;
	if(q&1) this.css('top',l+s.y);
	if(q&2) this.css('bottom',r-s.y);
};*/

(function(){
	probelJS.drag={
		Current:null,
		RectStart:{},
		RectParent:{},
		MouseStartX:0,
		MouseStartY:0,
		Active:false,
		onMove:function(e)
		{
			if(probelJS.drag.Current===null)return;
			var strafe=({
				x: e.mouseX-dr.MouseStartX,
				y: e.mouseY-dr.MouseStartY
			});

			if(!dr.Active && drc.Threshold)
			{
				if(typeof(drc.Threshold)=='function')
				{
					if(!drc.Threshold(strafe))return false;
				}else if(typeof(drc.Threshold)=='number'){
					if(Math.abs(strafe.x)+Math.abs(strafe.y) < drc.Threshold)return false;
				}else if(drc.Threshold.x || drc.Threshold.y){
					if(Math.abs(strafe.x) < drc.Threshold.x || Math.abs(strafe.y) < drc.Threshold.y)
						return false;
				}
				dr.Active=true;
				if(drc.onDragActive)drc.onDragActive(dr);
			}

			var rc=new probelJS.Rect();
			var crc=drc.ConstraintRect||null;
			if(drc.ConstraintBase&&(drc.ConstraintDynamic||!crc))
			{
				var crc=drc.ConstraintBase.getRect();
				if(drc.Constraints)	crc.add(drc.Constraints);
			}

			rc.left  = dr.RectStart.left   + ((drc.Anchors.left)?0:strafe.x);
			rc.right = dr.RectStart.right  + ((drc.Anchors.right)?0:strafe.x);
			rc.top   = dr.RectStart.top    + ((drc.Anchors.top)?0:strafe.y);
			rc.bottom= dr.RectStart.bottom + ((drc.Anchors.bottom)?0:strafe.y);
			if(crc)
			{
				crc.substract(rc);
				if(crc.left > 0){
					if(!drc.Anchors.left) 	rc.left += crc.left;
					if(!drc.Anchors.right) 	rc.right += crc.left;
				}
				if(crc.right < 0){
					if(!drc.Anchors.left) 	rc.left += crc.right;
					if(!drc.Anchors.right) 	rc.right += crc.right;
				}
				if(crc.top > 0){
					if(!drc.Anchors.top) 	rc.top += crc.top;
					if(!drc.Anchors.bottom)	rc.bottom += crc.top;
				}
				if(crc.bottom < 0){
					if(!drc.Anchors.top) 	rc.top += crc.bottom;
					if(!drc.Anchors.bottom)	rc.bottom += crc.bottom;
				}
			}

			if(drc.beforeDrag){ drc.beforeDrag(drc,rc); };

			if(drc.ParentDynamic)	drc.Element.setRect(rc);
			else					drc.Element.setRect(rc,{relative:dr.RectParent});

			if(drc.onDrag){ drc.onDrag(drc,rc); };
			
			e.noBubble();
			e.preventDefault();

			strafe=null;

			return false;
		},
		onUp:function(e)
		{
			if(probelJS.drag.Current===null) return;
			$(document)
				.unlisten('mousemove',probelJS.drag.onMove)
				.unlisten('mouseup',probelJS.drag.onUp);

			if(dr.Active)
			{
				if(probelJS.drag.Current.onDragEnd) probelJS.drag.Current.onDragEnd(dr);
				if(dr.Revert){ // reverse drag
					drc.Element.setRect(dr.RectStart)
				}
				e.noBubble();
				e.preventDefault();
			}
			probelJS.drag.Current = null;
			return false;
		},
		Revert:false
	};
	var dr=probelJS.drag;
	var drc=dr.Current;
	probelJS.ex.draggable=function(p)
	{
		var th=this;
		//if(th.drag)return this;
		var p=$cpy({
			Anchors:{
				left: false,
				right: false,
				top: false,
				bottom: false
			},
			Placeholder: false,
			Element: th,
			Handle: th,
			Constraints: null,
			ConstraintBase: $(th.parentNode),
			ConstraintDynamic:false,
			ParentDynamic:false,
			Style: {},
			Threshold: 0,
			Snap: false,
			beforeDrag:false,
			onDrag: false,
			beforeDragStart: false,
			onDragStart: false,
			onDragActive: false,
			onDragEnd: false,

			DropTargets:null
			
		},p);

		if(p.ConstraintBase==document){
			p.ConstraintBase=$(document.body);
		}

		p.Handle.listen('mousedown',function(e){
			if(probelJS.drag.Current)return;
			probelJS.drag.Current = drc = p;
			if(p.beforeDragStart && !p.beforeDragStart(drc))return true;
			probelJS.drag.MouseStartX=e.mouseX;
			probelJS.drag.MouseStartY=e.mouseY;
			probelJS.drag.RectStart=th.getRect();
			probelJS.drag.RectParent=$(th.offsetParent).getOffsets();
			probelJS.drag.Active=drc.Threshold?false:true;
			probelJS.drag.Revert=false;
			//$$('iframe').walk(function(el){});
			$(document)	.listen('mousemove',probelJS.drag.onMove)
						.listen('mouseup',probelJS.drag.onUp);
			if(p.onDragStart)p.onDragStart(drc);
			e.noBubble();
			e.preventDefault();
			return false;
		});
	};
})();
/**/

// ------------------------------------------------------
// ---  Hints                                         ---
// ------------------------------------------------------
new function(){
	probelJS.Hint = probelJS.Class({
		ctor:function(params){
			$cpy(this,params);
			this.HintElement=$(this.HintElement);
			this.Shift.x=this.Shift.x||10;
			this.Shift.y=this.Shift.y||10;

			this.Element.listen('mousemove',this.onMove,this);
			this.Element.listen('mouseout',this.onOut,this);

			$(this.HintElement.offsetParent);
		},
		HintElement:null,
		Element:null,
		WarmUp:500,
		CoolDn:500,
		Shift:{x:10,y:10},
		onShow:null,
		onHide:null,

		ParentRect:null,
		ElementRect:null,
		Tracking:true,
		
		Update:function(){
			this.HintElement.setOffset({x: probelJS.HintMgr.MouseX + this.Shift.x,
										y: probelJS.HintMgr.MouseY + this.Shift.y,
										relative: this.ParentRect
			});
		},
		Show:function(){
			this.HintElement.show();
			this.ParentRect = this.HintElement.offsetParent.getOffsets();
			this.Update();
			if(this.onShow) this.onShow();
		},
		Hide:function(){
			this.HintElement.hide();
			if(this.onHide) this.onHide();
		},
		onMove:function(e){
			probelJS.HintMgr.MouseX=e.mouseX;
			probelJS.HintMgr.MouseY=e.mouseY;
			if(probelJS.HintMgr.State==3)
			{
				probelJS.HintMgr.Show(this);

				if(probelJS.HintMgr.Timer) clearTimeout(probelJS.HintMgr.Timer);
				probelJS.HintMgr.Timer = 0;
			}
			if(probelJS.HintMgr.State>=2){

				probelJS.HintMgr.Show(this);
				if(this.Tracking)this.Update();

			}else if(probelJS.HintMgr.State==1 || probelJS.HintMgr.State==0 ){

				probelJS.HintMgr.State = 1;
				probelJS.HintMgr.Current = this;

				if(probelJS.HintMgr.Timer) clearTimeout(probelJS.HintMgr.Timer);

				probelJS.HintMgr.Timer = setTimeout(function(){
					probelJS.HintMgr.State=2;
					probelJS.HintMgr.Current.Show();
				},this.WarmUp);
			}
		},
		onOut:function(e){
			if(probelJS.HintMgr.State == 1)
			{
				if(probelJS.HintMgr.Timer) clearTimeout(probelJS.HintMgr.Timer);
				probelJS.HintMgr.Timer = 0;
		
				probelJS.HintMgr.State = 0;

			}else if(probelJS.HintMgr.State==2){

				if(probelJS.HintMgr.Timer) clearTimeout(probelJS.HintMgr.Timer);

				probelJS.HintMgr.Timer = setTimeout(function(){
					probelJS.HintMgr.Hide();
				},this.CoolDn);

				probelJS.HintMgr.State = 3;
			}
		}
	});

	probelJS.HintMgr={
		Current:null,
		State:0,
		Timer:0,
		MouseX:0,
		MouseY:0,
		Show:function(h){
			if(this.Current!==h){
				if(this.Current)this.Current.Hide();
				this.Current=h;
				this.Current.Show();
			}
			this.State=2;
		},
		Hide:function(){
			if(this.Current) this.Current.Hide();
			this.State=0;
			this.Current=null;
		}
	};

	probelJS.ex.hint=function(params)
	{
		new probelJS.Hint({
			Element:this,
			WarmUp: params.warmup || 500,
			CoolDn: params.cooldn || 500,
			HintElement: $(params.hint_el),
			Shift: { 
				x: params.shift && params.shift[0] || 10,
				y: params.shift && params.shift[1] || 10 
			},
			onShow: params.onshow,
			onHide: params.onhide

		});

		return this;
	};
};
// ------------------------------------------------------
// ---  Data integration                              ---
// ------------------------------------------------------

// ------------------------------------------------------
// ---  Components                                    ---
// ------------------------------------------------------

probelJS.Comp={
		__id:0,
		GenID:function(){ return (probelJS.Comp.__id++) }
	};


probelJS.Comp.Base=probelJS.Class({
	SelfNode:null,
	Parent:null,
	Replacing:null,
	BeforeRender:function(){},
	AfterRender:function(){}
});

/// --- CHECK BOX --- ///
/*probelJS.Comp.Tree = probelJS.Class(function(params){
	$cpy(this,params);
	var _this=this;
},{
	Nodes:[],
	Render:function(p)
	{
		var ndp=this.SelfNode=p.SubItem('div',{className:"tree_node_block root"});
		this.Nodes.walk(function(nd){ nd.Render(ndp); return nd});
	}
},probelJS.Comp.Base);*/

probelJS.ex.megacheckbox=function(style)
{
	var cb = this;
	var a = $(cb.parentNode).SubItem('a',{
		href:'javascript:void(0)',
		className:(cb.checked)?'xpcheck_on':'xpcheck_off',
		checked:cb.checked,
		style:{cssText:cb.style.cssText}
	},cb);
	cb.megareplaced=a;
	a.set=function(v){
	cb.checked = (a.checked = v);
		a.className = (a.checked)?'xpcheck_on':'xpcheck_off';
	};
	a.listen('click',function(){
		a.set(!a.checked);
		if(cb.onchange) cb.onchange();
	});

	cb.style.display='none';
	return this;
};

/// --- RADIOBUTTON --- ///

probelJS.ex.megaradiobutton=function(style)
{
	var cb = this;
	var a = $(cb.parentNode).SubItem('a',{
		href:'javascript:void(0)',
		className:(cb.checked)?'inlbox xpradio_on':'inlbox xpradio_off',
		checked:cb.checked,
		style:{cssText:cb.style.cssText}
	},cb);
	cb.megareplaced=a;
	a.set=function(v){
		if(v)
		{
			var els=(cb.form&&cb.form.elements)||$$('input[type="radio"]');
			Array.clone(els).walk(function(el){
				if(el.type!='radio' || el.name!=cb.name)return;
				//if(el===cb) return;
				el.megareplaced.set(false);
			});
		}
		cb.checked = (a.checked = v);
		a.className = (a.checked)?'inlbox xpradio_on':'inlbox xpradio_off';
	};
	a.className = (a.checked)?'inlbox xpradio_on':'inlbox xpradio_off';
	a.listen('click',function(){
		a.set(true);
		if(cb.onchange)cb.onchange();
	});

	cb.style.display='none';
	return this;
};

/// --- REGULAR BUTTON --- ///
probelJS.ex.megabutton=function(style){

	if(this.style.display=='none')return this;
	var bt = this;

	var style = (style || 'xpbutton2');

	var pe = document.createElement("span");
		pe.className = 'inlbox';
		pe.setAttribute('unselectable','on');
		//if(bt.onclick) $(pe).addEvent('click',function(event){ return bt.onclick(); });
	var ped = document.createElement("div");
		ped.className = style;

	var cli = document.createElement("div");
		cli.className = 'left';
	var cri = document.createElement("div");
		cri.className = 'right';
	var ccc = document.createElement("div");
		ccc.className = 'center';
	var ccb = document.createElement("button");

		ped.style.width = 	(bt.style.width && (String(parseInt(bt.style.width)-0)+'px')) ||
							(bt.offsetWidth && (String(bt.offsetWidth-0)+'px')) ||
							'';
		ped.style.margin = bt.style.margin;
		ccb.innerHTML = bt.value;
		if(bt.tabIndex>=0){ ccb.tabIndex=bt.tabIndex; }
		if(bt.title!==undefined){ ccb.title=bt.title; }

		$(ped).mg_button_release=function(){ ped.className = style; }
		$(ped).onmousedown = function(){
			ccb.focus();
			ped.className = style+'_active';
			ped.onmouseup=function(){ ped.mg_button_release(); /*if(bt.onclick)bt.onclick();*/ bt.click(); };
			ped.onmouseout=function(){ ped.mg_button_release(); };
			return false;
		};

		$(ccb).listen('focus',function(e){});
		$(ccb).listen('blur',function(e){});
		$(ccb).listen('keydown',function(e){
			if(e.keyCode==13 || e.keyCode==32) ped.className = style+'_active';
			//return false;
		});
		$(ccb).listen('keyup',function(e){
			ped.mg_button_release();
			if(e.keyCode==13 || e.keyCode==32) bt.click();
			//return false;
		});
		ccc.appendChild(ccb);

		ped.appendChild(ccc);
		ped.appendChild(cri);
		ped.appendChild(cli);

		bt.style.display = 'none';

		pe.appendChild(ped);

		bt.parentNode.insertBefore(pe,bt);

	return this;
};

/// --- TREE --- ///
probelJS.Comp.Tree = probelJS.Class({
	ctor:function(params){
		$cpy(this,params);
		var _this=this;
		if(!_this.Parent && (!_this.Replacement || !(_this.Parent=_this.Replacement.parentNode)))return false;
		_this.Nodes.walk(function(n,i){
			if(n.constructor==probelJS.Comp.Tree.SubNode)return n;
			n.Tree=_this;
			return new probelJS.Comp.Tree.SubNode(n);
		});
		_this.Build(_this.Parent);
	},
	Nodes:[],
	Build:function(p)
	{
		var ndp=this.SelfNode=p.SubItem('div',{className:"tree_node_block root"});
		this.Nodes.walk(function(nd){ nd.Render(ndp); return nd});
	},
	Selected:null,
	SignalSelect:function(node){
		var res;
		if(this.OnSelect)res=this.OnSelect(node);
		if(res)return;
		if(this.Selected && this.Selected.OnBlur) this.Selected.OnBlur();
		this.Selected=node;
		if(node.OnFocus) node.OnFocus();
	},
	OnSelect:null
},probelJS.Comp.Base);

probelJS.Comp.Tree.SubNode=probelJS.Class({
	ctor:function(params,level){
		var _this=this;
		$cpy(this,params);
		this.Level=level||0;
		this.SelfNode=this.SubTreeNode=this.PlusButton=null; //do not allow this to be filled by parameters
		if(!this.OnFetch)
		{
			this.Nodes = this.Nodes || [];
			this.Nodes.walk(function(n,i){
				if(n.constructor==probelJS.Comp.Tree.SubNode)return n;
				n.Tree=_this.Tree;
				n.ParentNode=_this;
				return new probelJS.Comp.Tree.SubNode(n,level+1);
			});
		}
	},
	Tree:null,
	Title:'',
	Href:'javascript:;',
	State:0,
	Level:0,
	ParentNode:null,
	SubTreeNode:null,
	PlusButton:null,
	Nodes:[],
	OnFetch:null,
	SelfNode:null,
	CustomStyle:null,
	RenderSelf:function(p){
		var sn=$(probelJS.HTML('<div class="tree_node_leaf '+(this.CustomStyle?(this.CustomStyle):'')
			+'"><span class="tree_item_line"></span>'+
			'<a class="tree_node_title" href="'+this.Href+'">'+this.Title+'</a>'+
			'</div>')[0]);
		var _this=this;
		if(!this.SelfNode)sn.Insert(p);
		else this.SelfNode.Replace(sn);
		this.SelfNode=sn;
		sn.$$('a.tree_node_title')[0].listen('click',function(e){
			this.Tree.SignalSelect(this);
		},this);
		//this.SelfNode.Insert(p);
	},
	RenderSubs:function(p){
		if(!this.OnFetch&&!this.Nodes.length)return;
		var sn=$(probelJS.HTML('<div class="tree_node_subs"><div class="tree_node_block"></div>'+
			'<span class="tree_item_plus"></span></div>')[0]);
		var _this=this;
		var pl=this.PlusButton=sn.$$('span.tree_item_plus')[0];
		var c=$(sn.firstChild);
		if(pl)$(pl).listen('click',function(){
			if(_this.State)_this.Collapse();
			else _this.Expand();
		});
		if(!this.SubTreeNode)sn.Insert(p);
		else this.SubTreeNode.Replace(sn);
		this.SubTreeNode=sn;
		if(this.Nodes&&this.Nodes.length){ this.Nodes.walk(function(el){ el.Render(c); return el }); }
		if(!this.State)this.Collapse();
	},
	Render:function(p){
		this.RenderSelf(p);
		this.RenderSubs(p);
		//this.RenderSubs(this.SelfNode);
	},
	Expand:function(){
		if(this.OnFetch) 
		{
			var _this=this;
			var newNodes = this.OnFetch();
			if(this.Nodes)this.Nodes.walk(function(n){n.Delete();return n;});
			this.Nodes = newNodes;
			this.Nodes.walk(function(n,i){
				if(n.constructor==probelJS.Comp.Tree.SubNode)return n;
				n.Tree=_this.Tree;
				n.ParentNode=_this;
				return new probelJS.Comp.Tree.SubNode(n,_this.Level+1);
			});
			if(this.Nodes&&this.Nodes.length){
				this.Nodes.walk(function(el){
					el.Render(_this.SubTreeNode.firstChild);
					return el;
				});
			}
		}
		if(!this.Nodes.length)return;
		this.State=1;
		this.SubTreeNode.firstChild.show();
		this.PlusButton.removeClass('closed');
	},
	Collapse:function(){
		if(!this.OnFetch&&!this.Nodes.length)return;
		this.State=0;
		this.SubTreeNode.firstChild.hide();
		this.PlusButton.addClass('closed');
	},
	Delete:function()
	{
		if(this.Nodes)this.Nodes.walk(function(n){n.Delete();return n;});
		this.SelfNode.Remove(); this.SelfNode=null;
		this.SubTreeNode.Remove(); this.SubTreeNode=null;
		this.PlusButton=null;
	},
	//  select \ blur events
	OnFocus:null,
	OnBlur:null
},probelJS.Comp.Base);


probelJS.ex.megaHorizontalScroll=function(scrfor)
{
	var imgdir="/img/components/default";
	var _scroll={
		position:0,
		active:false,
		tracker:null,
		left:null,
		right:null,
		body:this,
		scrfor:scrfor,
		lp:0,rp:0,ts:0,max:0,
		StartRect:null,
		read_scroll:function(x){
			this.lp = this.left.getSize().w+1;
			this.rp = this.right.getSize().w+1;
			this.ts = this.tracker.getSize().w;
			this.max = this.scrfor.getSize().w - this.lp - this.rp - this.ts;
			var x = this.scrfor.scrollLeft * this.max / (this.scrfor.scrollWidth - this.scrfor.getSize().w);
			if( !x.isFinite() || x < 0 ) x=0;
			else if(x > this.max) x = this.max;
			this.position = x;
			this.updateScroll(x);
		},
		updateScroll:function(x){
			this.tracker.style.left = (x + this.lp) + 'px';
			x /= this.max;
			this.scrfor.scrollLeft = (this.scrfor.scrollWidth - this.scrfor.getSize().w)*x;
		},
		startX:0,startY:0,
		onMove:function(e){
			var x = this.position + e.mouseX - this.startX;
			if(x < 0) x = 0;
			else if(x > this.max) x = this.max;
			this.updateScroll(x);
			e.noBubble();
			e.preventDefault();
			return false;
		},
		onUp:function(e)
		{
			var x = this.position + e.mouseX - this.startX;
			if(x < 0) x = 0;
			else if(x > this.max) x = this.max;
			this.position = x;
			$(document).unlisten('mousemove',this.onMove);
			$(document).unlisten('mouseup',this.onUp);
			e.noBubble();
			e.preventDefault();
			this.active=false;
			return false;
		},
		onDown:function(e){
			if(this.active)return false;
			this.active=true;
			this.lp = this.left.getSize().w+1;
			this.rp = this.right.getSize().w+1;
			this.ts = this.tracker.getSize().w;
			this.max = this.scrfor.getSize().w - this.lp - this.rp - this.ts;

			if(this.position < 0) this.position = 0;
			else if(this.position > this.max) this.position = this.max;

			this.startX = e.mouseX; this.startY = e.mouseY;
			$(document).listen('mousemove',this.onMove,this);
			$(document).listen('mouseup',this.onUp,this);
			e.noBubble();
			e.preventDefault();
			return false;
		},
		Set:function(e){
			var off = this.tracker.getRect();
			this.position += (e.mouseX - off.left - off.width()/2);

			this.onDown(e);
			this.updateScroll(this.position);
		}
	};
	
	this.css('backgroundColor','#EEEDE5');
	this.css('backgroundImage',imgdir+"/scrollbar_bg.gif");
	this.css('backgroundPosition','center');
	this.css('heigth',13);
	if(this.css('position')!='absolute')this.css('position','relative');
	
	_scroll.left=this.SubItem('img',{
		src:imgdir+"/scrollbar_left.gif",
		style:{
			'position': 'absolute',
			'left': '0',
			'top': '0',
			'border': '0px clear'
		}
	});
	_scroll.left.listen('mousedown',function(){ 
		this.position-=20; 
		if(this.position<0)this.position=0; 
		this.updateScroll(this.position);
	},_scroll);
	_scroll.left.holdable((function(){
		this.position-=20;
		if(this.position<0)this.position=0; 
		this.updateScroll(this.position);
	}).closure(_scroll),50,300);

	_scroll.right=this.SubItem('img',{
		src:imgdir+"/scrollbar_right.gif",
		style:{
			'position': 'absolute',
			'right': '0',
			'top': '0',
			'border': '0px clear'
		}
	});
	_scroll.right.listen('mousedown',function(){ 
		this.position+=20; 
		if(this.position>this.max)this.position=this.max; 
		this.updateScroll(this.position);
	},_scroll);
	_scroll.right.holdable((function(){
		this.position+=20; 
		if(this.position>this.max)this.position=this.max; 
		this.updateScroll(this.position);
	}).closure(_scroll),50,300);

	_scroll.tracker=this.SubItem('img',{
		src:imgdir+"/scrollbar_tracker.gif",
		style:{
			'position': 'relative',
			'left': _scroll.lp+'px',
			'top': '0',
			'border': '0px clear'
		}
	});

	this.listen('mousedown',function(e){ this.Set(e) },_scroll);

	scrfor.style.overflow='hidden';
	$(window).listen('resize',_scroll.read_scroll,_scroll);
	_scroll.tracker.listen('mousedown',_scroll.onDown,_scroll);
	_scroll.read_scroll();

	return this;
};
probelJS.ex.megaVerticalScroll=function(scrfor)
{
	var imgdir="/img/components/default";
	var _scroll={
		position:0,
		active:false,
		tracker:null,
		left:null,
		right:null,
		body:this,
		scrfor:scrfor,
		lp:0,rp:0,ts:0,max:0,
		StartRect:null,
		read_scroll:function(x){
			this.lp = this.left.getSize().h+1;
			this.rp = this.right.getSize().h+1;
			this.ts = this.tracker.getSize().h;
			this.max = this.scrfor.getSize().h - this.lp - this.rp - this.ts;
			var x = this.scrfor.scrollTop * this.max / (this.scrfor.scrollHeight - this.scrfor.getSize().h);
			if( !x.isFinite() || x < 0 ) x=0;
			else if(x > this.max) x = this.max;
			this.position = x;
			this.updateScroll(x);
		},
		updateScroll:function(x){
			this.tracker.style.top = (x + this.lp) + 'px';
			x /= this.max;
			this.scrfor.scrollTop = (this.scrfor.scrollHeight - this.scrfor.getSize().h)*x;
		},
		startX:0,startY:0,
		onMove:function(e){
			var x = this.position + e.mouseY - this.startY;
			if(x < 0) x = 0;
			else if(x > this.max) x = this.max;
			this.updateScroll(x);
			e.noBubble();
			e.preventDefault();
			return false;
		},
		onUp:function(e)
		{
			var x = this.position + e.mouseY - this.startY;
			if(x < 0) x = 0;
			else if(x > this.max) x = this.max;
			this.position = x;
			$(document).unlisten('mousemove',this.onMove);
			$(document).unlisten('mouseup',this.onUp);
			e.noBubble();
			e.preventDefault();
			this.active=false;
			return false;
		},
		onDown:function(e){
			if(this.active)return false;
			this.active=true;
			this.lp = this.left.getSize().h+1;
			this.rp = this.right.getSize().h+1;
			this.ts = this.tracker.getSize().h;
			this.max = this.scrfor.getSize().h - this.lp - this.rp - this.ts;

			if(this.position < 0) this.position = 0;
			else if(this.position > this.max) this.position = this.max;

			this.startX = e.mouseX; this.startY = e.mouseY;
			$(document).listen('mousemove',this.onMove,this);
			$(document).listen('mouseup',this.onUp,this);
			e.noBubble();
			e.preventDefault();
			return false;
		},
		Set:function(e){
			var off = this.tracker.getRect();
			this.position += (e.mouseY - off.top - off.height()/2);

			this.onDown(e);
			this.updateScroll(this.position);
		}
	};
	
	this.css('backgroundColor','#EEEDE5');
	this.css('backgroundImage',imgdir+"/scrollbar_vert_bg.gif");
	this.css('backgroundPosition','center');
	this.css('heigth',13);
	if(this.css('position')!='absolute')this.css('position','relative');
	
	_scroll.left=this.SubItem('img',{
		src:imgdir+"/scrollbar_top.gif",
		style:{
			'position': 'absolute',
			'left': '0',
			'top': '0',
			'border': '0px clear'
		}
	});
	_scroll.left.listen('mousedown',function(){ 
		this.position-=20; 
		if(this.position<0)this.position=0;
		this.updateScroll(this.position);
	},_scroll);
	_scroll.left.holdable((function(){
		this.position-=20;
		if(this.position<0)this.position=0; 
		this.updateScroll(this.position);
	}).closure(_scroll),50,300);

	_scroll.right=this.SubItem('img',{
		src:imgdir+"/scrollbar_bottom.gif",
		style:{
			'position': 'absolute',
			'left': '0',
			'bottom': '0',
			'border': '0px clear'
		}
	});
	_scroll.right.listen('mousedown',function(){ 
		this.position+=20; 
		if(this.position>this.max)this.position=this.max; 
		this.updateScroll(this.position);
	},_scroll);
	_scroll.right.holdable((function(){
		this.position+=20; 
		if(this.position>this.max)this.position=this.max; 
		this.updateScroll(this.position);
	}).closure(_scroll),50,300);

	_scroll.tracker=this.SubItem('img',{
		src:imgdir+"/scrollbar_vert_tracker.gif",
		style:{
			'position': 'relative',
			'left':'0',
			'top': _scroll.lp+'px',
			'border': '0px clear'
		}
	});

	this.listen('mousedown',function(e){ this.Set(e) },_scroll);

	scrfor.style.overflow='hidden';
	$(window).listen('resize',_scroll.read_scroll,_scroll);
	_scroll.tracker.listen('mousedown',_scroll.onDown,_scroll);
	_scroll.read_scroll();

	return this;
};
