// ========================================= EFFECTS
function EFFECT()
{
this.Tline=function(pos) {
    return pos;
}
this.Tsin=function(pos) {
    return (-Math.cos(pos*Math.PI)/2) + 0.5;
}
this.Treverse=function(pos) {
	return 1-pos;
}
this.Trand=function(pos) {
	return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4;
}
this.Tspeedup=function(pos) {
    return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
}
this.Tpulse=function(pos, pulses) { 
	pulses = pulses || 4; 
	return (
		Math.round((pos % (1/pulses)) * pulses) == 0 ? 
		((pos * pulses * 2) - Math.floor(pos * pulses * 2)) : 
		1 - ((pos * pulses * 2) - Math.floor(pos * pulses * 2))
	);
}

this.parent=function()
{
	this.end=0;
	this.node=false;
	this.begin=false;
	this.step=function (rate) {this.set(this.begin-0+(this.end-this.begin)*rate);}
	this.get=function () {}
	this.set=function (val) {}
	this.trans=function (a) {return effect.Tline(a);}
}

this.Ecolor=function()
{
	this.end=[128,128,128];
	this.step=function (rate) {
		this.set('rgb('+
		Math.round(this.begin[0]-0+(this.end[0]-this.begin[0])*rate)+','+
		Math.round(this.begin[1]-0+(this.end[1]-this.begin[1])*rate)+','+
		Math.round(this.begin[2]-0+(this.end[2]-this.begin[2])*rate)+')');
	}
	this.get=function () {
		this.node.eff_color=this.begin=sys.create_color(this.node.style.color);
	}
	this.set=function (color) {
		this.node.style.color=color;
	}
}
this.Ecolor.prototype=new this.parent;

this.Eopacity=function()
{
	this.get=function () {
		if (sys.is_ie) {if (!this.node.filters.alpha) {this.begin=1;} else {this.begin=this.node.filters.alpha.opacity/100;}}
		else {this.begin=this.node.style.opacity; if (this.begin=='') {this.begin=1;}}
		this.node.eff_opac=this.begin;
	}
	this.set=function (opac) {
		this.node.style.opacity = opac;
		this.node.style.KhtmlOpacity = opac;
		this.node.style.filter = 'alpha(opacity=' + opac*100 + ')';
	}
}
this.Eopacity.prototype=new this.parent;

this.Ewidth=function()
{
	this.get=function () {
		this.node.eff_width=this.begin=this.node.offsetWidth;
		this.node.style.overflow='hidden';
	}
	this.set=function (val) {
		if (Math.round(val)==0) {sys.d(this.node,0);} else {sys.d(this.node,1);}
		this.node.style.width=val;
	}
}
this.Ewidth.prototype=new this.parent;

this.Eheight=function()
{
	this.get=function () {
		this.node.eff_height=this.begin=this.node.offsetHeight;
		this.node.style.overflow='hidden';
	}
	this.set=function (val) {
		if (Math.round(val)==0) {sys.d(this.node,0);} else {sys.d(this.node,1);}
		this.node.style.height=val;
	}
}
this.Eheight.prototype=new this.parent;

this.Etest=function()
{
	this.end=5;
	this.begin=false;
	this.trans=function (a) {return effect.Tline(a);}
	this.get=function() {this.begin=0;}
	this.step=function(rate) {alert(this.begin+(this.end-this.begin)*rate);}
}
this.Etest.prototype=new this.parent;
}
effect=new EFFECT();

function EFF()
{
	this.assign=function (id,name) {this[name]=sys.g(id); sys.g(id).effect=this;}
	this.timer=false;
	this.stack={};
	this.it=0;
	this.inc=0;
	this.after=sys.none;
	this.timer_f=function () {
		this.it++;
		if (this.it>this.endit) {clearInterval(this.timer); this.timer=0; this.f=this.after; this.after=sys.none; this.f(1); }
		else {
			var i;
			for(i in this.stack)
			{if (this.stack[i]!=null) {this.stack[i].step(this.stack[i].trans(this.it/this.endit));}}
		}
	}
	this.start=function(count,obj,after) {
		this.it=0;
		this.endit=count;
		if (this.timer) {clearInterval(this.timer); this.timer=0;}

		var i;
		for(i in this.stack)
		{
			if (!obj[i] && this.stack[i]!=null) 
			{
				this.stack[i].step(1);
				this.stack[i]=null;
			}
		}

		this.after(0);
		this.after=after||sys.none;

		for(i in obj)
		{
			this.stack[i]=obj[i];
			this.stack[i].get();
		}

		var ths=this;
		this.timer=setInterval(function () {ths.timer_f();},10);
	}
}

// ========================================= NAMESPACES
function NS()
{
	//------------------------- родная система
	this.assign=function (id,name) {if (!id || !sys.g(id)) {console.log(id+" не найден");} this[name]=sys.g(id); sys.g(id).object=this;}
	this.assign_sp=function (id,name,str) {if (!this["ASSIGN"+str]) {this["ASSIGN"+str]={};} this["ASSIGN"+str][name]=id; this.assign(id,name);}
	this.new_assign=function (count,new_i) {
		for(var ii in this["ASSIGN"+count]) {
			r=new RegExp("%".repeat(count));
			this.assign(this["ASSIGN"+count][ii].replace(r,new_i),ii.replace(r,new_i));
		}
	}
	
	//-------------------------- классовая система
	
	this.assign_arr=function() {
		for(var i = 0; this.assign_arr.arguments[i]; i+=2) {
			this["N"+this.assign_arr.arguments[i+1]]=this.assign_arr.arguments[i];
		}
	}
	this.link=function(obj,callback) {
		this.obj=obj;	
		this.callback=callback||{};
	}
	this.call=function(name,par) {if (this.callback[name]) {this.obj[this.callback[name]](par);}}
	
	this.assign_c=function (obj,name) {this["N"+name]=obj;}
	this.assign_sys_c=function (id,name) {this[name]=sys.g(id); sys.g(id).object=this;}
	this.assign_sp_c=function (id,name) {
		this.assign_sys_c(id,name);
		for(var i=2; str=this.assign_sp_c.arguments[i]; i++) {
			if (!this["ASSIGN"+str]) {this["ASSIGN"+str]={};} this["ASSIGN"+str][name]=id;
		}
	}
	this.trace_obj=function(str,id,name) {
		if (sys.g(id)) {str="OK "+str+";";} else {str="ERR "+str+";";}
		this.c(str,id+";",name);
	}
	this.new_assign_c=function (what,where,count,new_i) {
		var pr="%".repeat(count);
		var n=sys.node_copy(what,where,new_i,null,pr);
		var r=new RegExp(pr);
		sys.d(n,1);
		for(var ii in this["ASSIGN"+count]) {
			this.assign_sys_c(this["ASSIGN"+count][ii].replace(r,new_i),ii.replace(r,new_i));
		}
		return n;
	}

	this.clone=function(par,count,new_i) {
		old=par;
		par=sys.copy(par);
		var pr="%".repeat(count);
		var r=new RegExp(pr);
		for(var ii in par["ASSIGN"+count]) {
			par.assign_sys_c(par["ASSIGN"+count][ii].replace(r,new_i),ii.replace(r,new_i));
		}
		for(var i=1;par["ASSIGN"+i];i++) {
			par["ASSIGN"+i]={};
			for(var ii in old["ASSIGN"+i]) {
				par["ASSIGN"+i][ii]=old["ASSIGN"+i][ii].replace(r,new_i);
			}
		}
		return par;
	}
	this.eff=function (name,par) {
		if (this["E"+name]) {this["E"+name](par);}
	}
	this.debug=1;
	this.c=function(q,w,e) {
		if (this.debug && !pause) {
			console.log(q,w,e);
			if (!("console" in window) || !("firebug" in console)) {if (typeof(w)=="object") {console.dir(w);}}
		}
	}
	this.d=function() {
		if (this.debug && !pause) {
			return console;
		}
	}
	this.def=function(obj,fi) {
		for(var i in fi) {if (!this["N"+fi[i]]) {this["N"+fi[i]]=obj["N"+fi[i]];}}
	}
}

// ========================================= POSITION
function POSITION()
{
	this.absolute=function (node,x,y) {node.style.position='absolute'; node.style.left=x+'px'; node.style.top=y+'px';}
	this.to_node=function (node,to,h,v) {
		var pos=this.get_position(to);
		node.style.position='absolute';
		// ok gays lets do it well! :)

		if (node.offsetHeight+pos[1]>document.body.offsetHeight) {v=0;} // Если мы проламываем низ экрана, показываем над
		if (node.offsetWidth+pos[0]>document.body.offsetWidth) {h=0;} // Если мы проламываем правую сторону экрана, показываем левее

		if (h==0) {pos[0]-=node.offsetWidth;}
		if (h==2) {pos[0]+=to.offsetWidth/2-node.offsetWidth/2;}
		if (h==3) {pos[0]+=to.offsetWidth-node.offsetWidth;}
		if (h==4) {pos[0]+=to.offsetWidth;}
		if (v==0) {pos[1]-=node.offsetHeight+15;}
		if (v==2) {pos[1]+=to.offsetHeight/2-node.offsetHeight/2;}
		if (v==3) {pos[1]+=to.offsetHeight-node.offsetHeight;}
		if (v==4) {pos[1]+=to.offsetHeight;}
		this.absolute(node,pos[0],pos[1]);
	}
	this.point_distance=function (x1,y1,x2,y2) {return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
	this.point_direction=function (x1,y1,x2,y2) {y1=-y1; y2=-y2; var temp=Math.atan(Math.abs((y1-y2)/(x1-x2)))*180/Math.PI; if (x2-x1>0) {if (y1-y2>0) {temp=360-temp;}} else {if (y1-y2>0) {temp=180+temp;} else {temp=180-temp;}} return temp;}
	this.is_among=function (x1,x2,x3) {if (Math.min(x1,x2)<=x3 && x3<=Math.max(x1,x2)) {return true} else {return false}}
	this.collision=function (x1,y1,x2,y2,x3,y3,x4,y4) {if ((sys.is_among(x1,x2,x3) || sys.is_among(x3,x4,x1)) && (sys.is_among(y1,y2,y3) || sys.is_among(y3,y4,y1))) {return true} else {return false}}
	// не использовать с position relative/absolute в элементах выше данного
	this.get_position=function(node)
	{
		var x=y=0,o_n=node; /*o_p=node.style.position; node.style.position='relative';*/
		while(node){ x+=node.offsetLeft;y+=node.offsetTop; node=node.offsetParent;} /*o_n.style.position=o_p;*/
		return [x,y];
	}
	this.show_pos=function(x,y) {
	    var t=sys.node_create();
	    t.style.position="absolute";
	    t.style.left=x-2;
	    t.style.top=y-2;
	    t.style.width=4;
	    t.style.height=4;
	    t.style.zIndex=9999;
	    //t.innerHTML="q";
	    t.style.backgroundColor="green";
	    sys.node_insert(t,0,document.body);
	}
	
	this.x=function(node) {var x=0; while(node){ x+=node.offsetLeft; node=node.offsetParent;} return x;}
	this.y=function(node) {var y=0; while(node){ y+=node.offsetTop; node=node.offsetParent;} return y;}
}
position=new POSITION();

// ========================================= HTML OBJECTS
function H_ORDER_LIST() {
	this.list={}; // по ид получаем нод и позицию
	this.pos=[]; // по позиции получаем ид
	var ths=this;
	this.init_item=function(id,cont,up,down) {
		var i=this.pos.length;
		this.list[id]={'node':cont,'pos':i,'up':up,'down':down};
		this.pos[i]=id;
		sys.add_handler(up,"onclick",function(e,o,p){ths.up(p);},id);
		sys.add_handler(down,"onclick",function(e,o,p){ths.down(p);},id);
		this.hide_but();
	}
	this.rem=function(id) {
		var my_pos=this.list[id].pos;
		for(var i=my_pos;i<this.pos.length-1;i++) {
			this.pos[i]=this.pos[i+1];
			this.list[this.pos[i]].pos=i;
		}
		this.pos.pop();
		this.list[id]=undefined;
		this.hide_but();
	}
	this.down=function(it) {
		var my_pos=this.list[it].pos;
		if (my_pos+1<this.pos.length) {
			this.swap(it,this.pos[my_pos+1]);
		}
	}
	this.up=function(it) {
		var my_pos=this.list[it].pos;
		if (my_pos>0) {
			this.swap(it,this.pos[my_pos-1]);
		}
	}
	this.swap=function(a,b) {
		if (this.list[a].node.nextSibling==this.list[b].node) {
			sys.node_insert(this.list[b].node,this.list[a].node);
		} else if (this.list[a].node.previousSibling==this.list[b].node) {
			sys.node_insert(this.list[a].node,this.list[b].node);
		} else {
			var bef_a=this.list[a].node.nextSibling;
			var par_a=this.list[a].node.parentNode;
			var bef_b=this.list[b].node.nextSibling;
			var par_b=this.list[b].node.parentNode;
			sys.node_insert(this.list[a].node,bef_b,par_b);
			sys.node_insert(this.list[b].node,bef_a,par_a);
		}
		if (this.ex && this.ex_swap) {
			this.ex[this.ex_swap](a,this.list[b].pos);
			this.ex[this.ex_swap](b,this.list[a].pos);
		}
		this.pos[this.list[a].pos]=b;
		this.pos[this.list[b].pos]=a;
		var t=this.list[a].pos;
		this.list[a].pos=this.list[b].pos;
		this.list[b].pos=t;
		this.hide_but();
	}
	this.hide_but=function() {
		if (this.pos.length>0) {
			sys.d(this.list[this.pos[0]].up,0);
			sys.d(this.list[this.pos[this.pos.length-1]].down,0);
			if (this.pos.length>1) {
				sys.d(this.list[this.pos[1]].up,1);
				sys.d(this.list[this.pos[this.pos.length-2]].down,1);
			}
		}
	}
}

/* ----------------------------------------------------------------------------------------------------- */
/* 												System                                                   
/* ----------------------------------------------------------------------------------------------------- */
function SYSTEM()
{
var ths=this;
this.none=function() {;}
	// --------------------------------- Text
this.decorrect_text=function (t) {
	t=t.replace(/<BR>/ig,"\n");
	t=t.replace(/<BR\/>/ig,"\n");
	t=t.replace(/<BR \/>/ig,"\n");
	t=t.replace(/&#32;/ig," ");
	t=t.replace(/&nbsp;/ig," ");
	return t;
}
	// --------------------------------- User
this.message=function(a) {
	alert(a);
}
this.question=function(a,b) {
	if (!b) {
		return confirm(a);
	} else {
		alert('Нужен нормальный скрипт!!!');
		return 0;
	}
}
	// --------------------------------- Color
this.create_color = function (color){
	if (color.substr(0,3)=='rgb')
	{
		return color.substr(4,color.length-5).split(',');
	}
	else if (color.length==4)
	{
		var q=color.substr(1,1);
		var w=color.substr(2,1);
		var e=color.substr(3,1);
		return [parseInt(q+''+q, 16),parseInt(w+''+w, 16),parseInt(e+''+e, 16)];
	} else {
		return [parseInt(color.substr(1,2), 16),parseInt(color.substr(3,2), 16),parseInt(color.substr(5,2), 16)];
	}
};
	// --------------------------------- DOM
	// create
this.text_create=function(val) {return document.createTextNode(val);}
this.hid_create=function(nm,v) {n=document.createElement("input");n.type="hidden";n.value=v;n.name=nm;return n;}
this.node_create=function(a) {if (!a) {a="DIV";} return document.createElement(a);}
this.node_add=function() {return document.body.appendChild(document.createElement("DIV"));}
this.create_el=function(html,doc) {var t; doc=doc||document; t=doc.createElement("DIV"); t.innerHTML=html; return t.firstChild;}
	// remove
this.node_remove=function (node) {return node.parentNode.removeChild(node);}
this.node_remove_self=function (node) {while(node.childNodes[0]) {node.parentNode.insertBefore(node.childNodes[0],node);} this.remove_node(node);} 
this.node_clear=function (node) {while(node.firstChild) {node.removeChild(node.firstChild)}}
	// 
this.node_copy=function (node,to,id,before,format) {if (node && to) {nn=this.node_insert(node.cloneNode(1),before,to); this.node_go_id(nn,id,format); /*if (!this.is_ie) {this.copy_prop_r(nn,node);}*/ return nn;}}
this.node_move_ch=function (node,to) {while(node.childNodes[0]) {to.appendChild(node.childNodes[0]);}} 
this.node_rpl=function(node,nn) {ret=node.parentNode.insertBefore(nn,node); this.node_remove(node); return ret;}
	// move
this.node_insert=function(node,before,parent) {parent=parent||node.parentNode; if (before) {return parent.insertBefore(node,before);} else {return parent.appendChild(node);}}
this.node_replace=function(node,nn,id) {if (node && nn) {ret=node.parentNode.insertBefore(nn,node); this.node_remove(node); this.node_go_id(ret,id); return ret;}}
	// find
this.go=function (node,f) {if (node.nodeType==1) {f(node); for(var i=0;i<node.childNodes.length;i++) {this.go(node.childNodes[i],f);}}}
this.parent=function (p,f) {while(true) {if (p.nodeName=='BODY' || p.nodeName=='#document') {return false;} else if (f(p)) {return p;} else {p=p.parentNode;}}}
this.find_form=function (n) {return this.parent(n,function(n) {if (n.nodeName=='FORM') {return 1;} return 0;});}
this.find=function (node,f) {var i,t; 
	for(i=0;i<node.childNodes.length;i++) {
		if (node.childNodes[i].nodeType==1) {
			if (f(node.childNodes[i])) {return node.childNodes[i];} 
			t=this.find(node.childNodes[i],f);
			if (t) {return t;}
	}}  return false;
}
	// id
this.uidv=0;
this.uid=function() {this.uidv++; return this.uidv;}
this.g=function (s) {return document.getElementById(s);}
this.node_go_id=function (node,id,format) {
	if (format!=undefined && id!=undefined) {r=new RegExp(format); this.go(node,function(n) {if (n.id) {n.id=n.id.replace(r,id);} if (n.name) {n.name=n.name.replace(r,id);}});}
	else if (id!=undefined) {this.go(node,function(n) {if (n.id) {n.id+=id;}});}
}

	// --------------------------------- forms
this.form_submit=function(t) {f=this.parent(t,function (n) {if (n.nodeName=='FORM') {return 1;} else {return 0;}}); if (f.onsubmit) {f.onsubmit(); f.onsubmit=null;} f.submit();} 
this.form_reset=function(t) {
	f=this.parent(t,function (n) {if (n.nodeName=='FORM') {return 1;} else {return 0;}}); 
	this.go(f,function (n) {if (n.defaultValue!=undefined) {n.value=defaultValue;} if (n.object!=undefined && n.object.defaultValue!=undefined) {n.object.defaultValue();}});
	} 
	// --------------------------------- cloning
this.c=function (a) {return a;}
this.copy=function (o) {var n={}; for (var i in o) {n[i]=o[i];} return n;}
this.copy_r=function (o) {var n={}; for (var i in o) {if (typeof(o[i])=='object') {n[i]=this.copy_r(o[i]);} else {n[i]=o[i];}} return n;}
this.copy_prop_r=function (n1,n2) {if (n1.nodeType==1) {
	//if (n2.object) {n1.object=this.copy_r(n2.object);}
	//if (n2.handler_stack) {n1.handler_stack=this.copy_r(n2.handler_stack);}
	for(var i=0;i<n1.childNodes.length;i++) {this.copy_prop_r(n1.childNodes[i],n2.childNodes[i]);}}
}
	// --------------------------------- 
this.style=function(obj,str) {
	str=str.split(";");
	for(i in str) {
		str[i]=str[i].split(":");
		if (str[i][0]=='background-color') {str[i][0]='backgroundColor';}
		else if (str[i][0]=='background-image') {str[i][0]='backgroundImage';}
		else if (str[i][0]=='font-size') {str[i][0]='fontSize';}
		else if (str[i][0]=='font-weight') {str[i][0]='fontWeight';}
		//alert(str[i][0]+';'+str[i][1]);
		obj.style[str[i][0]]=str[i][1];
	}
}
this.hex=function() {
	var a=['1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f'];
	var str='';
	for(var i=0;i<32;i++) {str+=a[sys.rand(0,15)];}
	return str;
}
this.rand=function(min,max) {
	return Math.round(Math.random()*(max-min))+min;
}
this.check_empty=function(val) {
	return val.replace(/[ \x0a\x0d]/g,"");
}
this.uniq_num=function() {
	var s=(Math.round(Math.random()*100000000)+''+Math.round(Math.random()*100000000)+''+Math.round(Math.random()*100000000)+''+Math.round(Math.random()*100000000));
	for(var i=s.length;i<32;i++) {s="0"+s;}
	return s;
}
this.d=function (node,a) {if (a==1 || (a==-1 && node.style.display=='none')) {node.style.display='';} else {if (node.style.display!='none') {node.style.display='none';}}}
this.dd=function (node,parent,before) {if (!parent) {this.node_insert(node,null,sys.g("sys_hide_div")); this.d(node,0);} else {this.node_insert(node,before,parent); this.d(node,1);}}
this.dis=function (node,a) {if (a==1 || (a==-1 && node.disabled==0)) {node.disabled=1;} else {if (node.disabled!=0) {node.disabled=0;}}}
this.deny_select=function (node) {alert('НУЖЕН НОРМ СКРИПТ НА ЗАПРЕТ ВЫДЕЛЕНИЯ');}
	//system_message
this.sm=function (text) {if (typeof(text)=='object') {var text2=text,i; text=''; for(i in text2) {text+=i+':'+text2[i]+'; ';}}var node=document.body.appendChild(document.createElement('DIV')); node.innerHTML=text;}
this.al=function (text) {if (typeof(text)=='object') {var text2=text,i; text=''; for(i in text2) {text+=i+':'+text2[i]+';\n';}} alert(text);}
	//function_merge
this.fm=function (f1,f2) {if (f2) {return function (e) {f1(e);f2(e);}} else {return f1;}}
	//convert size
this.lsize=function(sz) {
	if (sz>1024*1024) {sz=Math.round(sz/(1024*10.24))/100+' Гб';}
	else if (sz>1024) {sz=Math.round(sz/(10.24))/100+' Мб';}
	else if (sz>1) {sz=Math.round(sz)+' Кб';}
	else if (sz<3/1024) {sz=Math.round(sz*1024*8)+' бит';}
	else {sz=Math.round(sz*1024)+' б';}
	return sz;
}
this.lnumb=function(num,arr) {
	if (num<0) {num=-num;}
	var l=num%10;
	if (num>9 && num<21) {l=9;}

	if (l==1) {return arr[0];}
	if (l>1 && l<5) {return arr[1];}
	return arr[2];
}
this.opac=function(node,opac) {
	node.style.opacity = opac;
	node.style.KhtmlOpacity = opac;
	node.style.filter = 'alpha(opacity=' + opac*100 + ')';
}
	// --------------------------------- anchors
this.move_to=function (n,how) {
	if (typeof(n)=='string') {var tn=n; n=''; for(var i=0;i<document.anchors.length; i++) {if (document.anchors[i].name==tn) {n=document.anchors[i]; break;}}}
	if (n) {n.scrollIntoView(how);}
	}
	// --------------------------------- events
this.add_handler=function (obj, ev, func, par)
{
if (!obj.handler_stack) {obj.handler_stack={};}
if (!obj.handler_stack[ev]) {
  obj.handler_stack[ev]=[];
  if (obj[ev]) {obj.handler_stack[ev][0]=[obj[ev],null];}
  obj[ev]=function (e) {var ret; for (var i=0; i<obj.handler_stack[ev].length; i++) {if (obj.handler_stack[ev][i]==undefined) {obj.handler_stack[ev].splice(i, 1); i--;} else {ret=obj.handler_stack[ev][i][0](e,obj,obj.handler_stack[ev][i][1]);}} return ret;}
  }
obj.handler_stack[ev][obj.handler_stack[ev].length]=[func,par];
}
this.ah=this.add_handler;

this.clear_handler=function (obj, ev)
{
	if (obj.handler_stack && obj.handler_stack[ev]) {obj.handler_stack[ev]=[];}
}

this.remove_handler=function (obj, ev, func)
{
if (obj.handler_stack)
if (obj.handler_stack[ev]) {
  for (var i=0; i<obj.handler_stack[ev].length; i++) {if (obj.handler_stack[ev][i] && obj.handler_stack[ev][i][0]==func) {obj.handler_stack[ev][i]=undefined; return 0;}}
  }
}
	// --------------------------------- browser
if (navigator.userAgent.indexOf("MSIE") == -1) {this.is_ie=0;} else {this.is_ie=1;}
if (window.opera) {this.is_opera=1;} else {this.is_opera=0;}

this.data = [
	{t:'A', what:'Firefox', mean:'FF'},
	{t:'A', what:'MSIE', mean:'IE'},
	{t:'A', what:'Netscape', mean:'NS'},
	{t:'V', what:'Apple', mean:'SF'},
	{t:'A', what:'Gecko', mean:'MZ'},
	{t:'V', what:'KDE', mean:'KN'},
	{t:'V', what:'Mozilla', mean:'NS'}
];

for (var i=0;i<this.data.length;i++)	{
	if (this.data[i].t=='A') {this.prop=navigator.userAgent;}
	if (this.data[i].t=='V') {this.prop=navigator.vendor;}
	if (this.prop.indexOf(this.data[i].what) != -1) {this.browser = this.data[i].mean; break;}
	if (window.opera) {this.browser = 'OP'; break;}
	this.browser = 'XZ';
}

if (this.browser=='SF') {this.is_safari=1;} else {this.is_safari=0;}

	// ========================================= Screen
//this.disscrpause=0;
this.disable_screen=function(opac,f) {
    if (!opac) var opac=0.8;
    this.enable_screen();
    this.disscr=this.node_add();
    this.disscr.style.height=document.body.scrollHeight;
    this.disscr.style.width=document.body.scrollWidth;
    this.disscr.style.backgroundColor="black";
    this.disscr.style.position="absolute";
    this.disscr.style.top=0;
    this.disscr.style.left=0;
    this.disscr.style.zIndex=999999;    
    this.disscr.style.opacity = opac;
    this.disscr.style.KhtmlOpacity = opac;
    this.disscr.style.filter = "alpha(opacity=" + opac*100 + ")";
    
    this.overdis=this.node_add();
    this.overdis.innerHTML='<table class="fixed" style="width: 100%; height: 100%;"><tbody><tr><td style="width:50%"/><td id="disscr_id"></td><td style="width:50%"/></tr></tbody></table>';
    var t=this.overdis.firstChild;
    t.style.zIndex=9999999;
    t.style.width=document.body.clientWidth;
    t.style.height=document.body.clientHeight;
    //this.add_handler(this.disscr,"onclick",function() {ths.enable_screen();});    
    this.add_handler(t,"onclick",function() {ths.enable_screen(f);});    

    return sys.g("disscr_id");
}
this.wait_disable_screen=function(f){/*alert("wait;"+disscrpause);*/disscrpause=1;}
this.enable_screen=function(f) {/*alert("enable;"+disscrpause);*/
	if (disscrpause) {disscrpause=0;} else {
		if (this.disscr) {
			if (f) f();
			if (this.disscr) {
				this.node_remove(this.disscr); 
				this.node_remove(this.overdis);
				this.disscr=0;
			}
		}
	}
}
this.getTime=function () {
    return new Date().getTime();
}

this.getTimeDelta=function (timeBegin, timeEnd) {
    timeEnd = timeEnd || getTime();
    return timeEnd - timeBegin;
}
}
disscrpause=0;

sys=new SYSTEM();
s=sys;

document.re_position=function() {};


function SEL() {
	this.setCursor=function (txtarea, start, end){
		if(txtarea.createTextRange) {
			var range = txtarea.createTextRange();
			range.move("character", start);
			range.select();
		} else if(txtarea.selectionStart) {
			txtarea.setSelectionRange(start, end);
		}
	}
	
	this.getCursor=function (input)
	{
		var result = { start: 0, end: 0 };
		if (input.setSelectionRange)
		{
			result.start= input.selectionStart;
			result.end = input.selectionEnd;
		}
		else if (!document.selection) { return 0; }
		else if (document.selection && document.selection.createRange)
		{
			var range = document.selection.createRange();
			var stored_range = range.duplicate();
			stored_range.moveToElementText(input);
			stored_range.setEndPoint('EndToEnd', range);
			result.start = stored_range.text.length - range.text.length;
			result.end = result.start + range.text.length;
		}
		return result;
	} 
	
	this.insert_tag = function(txtarea,starttag,endtag){
		txtarea.focus();
		var scrtop = txtarea.scrollTop;
		var cursorPos=this.getCursor(txtarea); 
		if (cursorPos.start==cursorPos.end)
		{
			var nuCursorPos=cursorPos.start+starttag.length;
			txtarea.value = txtarea.value.substring(0,cursorPos.start)+starttag+endtag+txtarea.value.substr(cursorPos.start );
			this.setCursor(txtarea,nuCursorPos,nuCursorPos);
		}else{
			var txt_pre=txtarea.value.substring (0,cursorPos.start);
			var txt_sel=txtarea.value.substring(cursorPos.start,cursorPos.end);
			var txt_aft=txtarea.value.substring(cursorPos.end);
			txtarea.value = txt_pre+starttag+txt_sel+endtag+txt_aft;
			var nuCursorPos=String(txt_pre+starttag+txt_sel+endtag).length;
			this.setCursor(txtarea,nuCursorPos,nuCursorPos);
		}
		if (scrtop) txtarea.scrollTop=scrtop;
	}
	
	this.get_text=function() {
		var r;
		if (sys.is_ie) {
			r=document.selection.createRange().text;
		} else {
			r=window.getSelection();r=r.toString();
		}
		return r;
	}
}
sel=new SEL;


// ========================================= USABITITY
function in_array(val,arr) {
	for(var i=0;i<arr.length;i++) {
		if (arr[i]==val) {return 1;}
	}
	return 0;
}
Number.prototype.NaN0=function() { return isNaN(this) ? 0 : this; }
String.prototype.trim=function () {
	var str=this;
	var start=0; 
	var end=str.length-1;
	for(var i=0;i<str.length;i++) {if (str.charCodeAt(i)<33) {start++;} else {break;}}
	for(var i=end;i>=0;i--) {if (str.charCodeAt(i)<33) {end--;} else {break;}}
	return str.substring(start,end+1);

}

function $(element) {
	if (typeof element == 'string')	var element = document.getElementById(element);
	return element;
}

String.prototype.repeat=function(a) {
	var str=this.toString();
	var ret="";
	for(var i=0;i<a;i++) {
		ret+=str;
	}
	return ret;
}
String.prototype.rep=function(cnt,a) {
	var str=this.toString();
	r=new RegExp("%".repeat(cnt));
	return str.replace(r,a);
}

/**
* add,list,rem%,row% - objects
* add - func
*/
function p_list() {
	// vars
	var ths=this;
	this.debug=1;
	this.count;
	this.all=0;
	
	// callback
	this.ex_add=function() {}
	
	// code
	this.init=function(count) {
		this.count=count||1;
		this.def(this.obj,["add","list","row"+"%".repeat(this.count),"rem"+"%".repeat(this.count)]);
		for(var i=0;this.obj["Nrow"+i];i++) {this["Nrow"+i]=this.obj["Nrow"+i];}
		
		sys.ah(this.Nadd,"onclick",function() {ths.add();});
		for(this.all=0;this["Nrow"+this.all];this.all++) {this.init_row(this.all);}
	}
	this.add=function() {
		this.obj.new_assign_c(this["Nrow"+"%".repeat(this.count)],this.Nlist,this.count,this.all);
		this.init_row(this.all);
		this.all++;
	}
	this.init_row=function(i) {
		this.ex_add(this.all);
		this.def(this.obj,["row"+i,"rem"+i]);
		sys.ah(this["Nrem"+i],"onclick",function(e,o,p){ths.remove(p);},i);
	}
	this.remove=function(i) {
		sys.node_remove(this["Nrow"+i]);
	}
}
p_list.prototype=new NS;

function p_tab() {
	// vars
	var ths=this;
	this.debug=1;
	this.choosed=false;
	
	// callback
	this.ex_tab=function(){}
	
	// code
	this.init=function() {
		this.def(this.obj,["sel"]);
		var opt=this.Nsel.options; this.parent=this.ex_tab(opt[0].value).parentNode;
		for(var ii=0;opt[ii];ii++) {sys.dd(this.ex_tab(opt[ii].value));}
		this.choose(i);
		sys.ah(this.Nsel,"onchange",function() {ths.choose();});
	}
	this.choose=function() {
		var j=this.Nsel.value||"bool";
		sys.dd(this.ex_tab(j),this.parent);
		if (this.choosed) sys.dd(this.ex_tab(this.choosed));
		this.choosed=j;
	}
}
p_tab.prototype=new NS;
/* ----------------------------------------------------------------------------------------------------- */
/* 												UI                                                 
/* ----------------------------------------------------------------------------------------------------- */

//if (sys.browser!='FF') {
	var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
	"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
	
	if (typeof(window.console)!='object') {
		window.console = {};
		for (var i = 0; i < names.length; ++i) {
			window.console[names[i]] = function() {}
		}
	}
//}
pause=0;