function $()
{
	if (arguments[0]) {
		if (typeof(arguments[0])=='string'){
				try{this.__obj=document.getElementById(arguments[0]);}
				catch(ex){	return false;}
			}
		else{
				this.__obj = arguments[0];
				//var date = new Date();
				//var id = 'obj_'+date.getTime();
				//this.__obj.id = (this.__obj.id||id);
			}
	}
	// param - not param
	this.empty = function(){
		while(this.__obj.childNodes.length)
		this.__obj.removeChild(this.__obj.childNodes[0]);
		return this;
	}
	// param - obj.time(int), obj.callback = function or nothing
	this.hide = function(){
		this.__obj.style.display = 'none';
	    return this;
	}
	// param - time(int)
	this.opacity = function(){
		this.__obj.style.opacity = (arguments[0]/100);
		this.__obj.style.MozOpacity = (arguments[0]/100);
		this.__obj.style.KhtmlOpacity = (arguments[0]/100);
		this.__obj.style.filter = "alpha(opacity="+arguments[0]+")";
		return this;
	}
	// param - obj.time(int), obj.callback = function or nothing
	this.show = function(){
		this.__obj.style.display = 'block';
	    return this;
	}
	// paran - object
	this.ltwh = function(obj){
		if(obj)	for(var i in obj) this.__obj.style[i]=obj[i];
		return this;
	}
	// paran - object
	this.setParam = function(obj){
		if(obj)	for(var i in obj) this.__obj[i]=obj[i];
		return this;
	}
	// not param
	this.hide_cnt = function(){
		this.__obj._content_display == 'none';
		var len = this.__obj.childNodes.length;
		for (var i=0; i<len; i++)
			if (this.__obj.childNodes[i].nodeType==1) {
				this.__obj.childNodes[i]._old_display = (this.__obj.childNodes[i]['style']['display']||'block');
				this.__obj.childNodes[i]['style']['display'] = 'none';
			}
	    return this;
	}
	// not param
	this.show_cnt = function(){
		this.__obj._content_display == 'block';
		var len = this.__obj.childNodes.length;
		for (var i=0; i<len; i++)
			if (this.__obj.childNodes[i].nodeType==1)
				this.__obj.childNodes[i]['style']['display'] = (this.__obj.childNodes[i]._old_display||'block');
		return this;
	}
	//remove element not param
	this.drop=function(){
		this.__obj = this.__obj.parentNode.removeChild(this.__obj);
		return this;
	}
	this.e = function(){return this.__obj;}
	//create new element
	//param obj
	this.create = function(obj){
		if(obj.type=='canvas' && this.browser.ie())
			this.__obj=excanvas(document.createElement(obj.type));
		else
			this.__obj = document.createElement(obj.type);

		if(obj.id) this.__obj.id = obj.id;
		if(obj.style)
			for (var i in obj.style ) this.__obj.style[i]=obj.style[i];
		if(obj.param)
			for (var i in obj.param) this.__obj[i]=obj.param[i];
		if (obj.text) this.__obj.innerHTML = obj.text;

		return this;
	}
	this.getClientW = function(){return parseInt(document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth);}
	this.getClientH = function(){return parseInt(document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight);}
       this.browser = {
       	ie:function(){return window.navigator.userAgent.toLowerCase().search(/msie/gi) != -1;},
       	mozila:function(){return window.navigator.userAgent.toLowerCase().search(/firefox/gi) != -1;},
       	opera:function(){return window.navigator.userAgent.toLowerCase().search(/opera/gi) != -1;},
       	safari:function(){return window.navigator.userAgent.toLowerCase().search(/safari/gi) != -1;}
       }
       this.appendChild = function(obj){       	this.__obj.appendChild(obj);
       	return this;       }
       this.appendTo = function(){       	var o = arguments[0];
       	if (typeof(o)=='string'){       		document.getElementById(o).appendChild(this.__obj);       	}else o.appendChild(this.__obj);
       	return this;       }
	this.getPos = function () {
      var x = y = 0;
      var obj = this.__obj;
      while(obj) {
            x += obj.offsetLeft;
            y += obj.offsetTop;
            obj = obj.offsetParent;
      }
      return {x:x, y:y};
	}
	return this;
}


function extendClass (_class,func)
{
	if (!_class) {var __class = function(){};
	for (var i in func) __class.prototype[i]=func[i];
	return new (__class)();
	}
	else {var __class = function(){};
	for (var i in _class) __class.prototype[i]=_class[i];
	for (var i in func) __class.prototype[i]=func[i];
	return new (__class)();
	}
}
//даодрода
var main_func = {
	blockAll:function(){
		$().create({type:'div',
					style :{position:'absolute',
							left:'0px',
							top:'0px',
							width:$().getClientW()+'px',
							height:$().getClientH()+'px',
							backgroundColor:'black'},
					id:'block_all'}).opacity(40).appendTo(document.body).e();
		if (arguments[0])this.setProgressBar('block_all');
	},
	unblockAll:function(){if ($('block_all').e()) $('block_all').drop();},
	alignCenter:function(){
		var w = $().getClientW();
		var h = $().getClientH();
		var obj = $(arguments[0]);
		var left = (w-parseInt(obj.e().clientWidth))/2+'px';
		var top = (h-parseInt(obj.e().clientHeight))/2+'px';
		obj.ltwh({position:'absolute',left:left,top:top});
	},
	setProgressBar:function(to){		var table = $().create({type:'table',style:{width:'100%',height:'100%'},id:'progres_bar'}).appendTo(to).e();
		var cell = table.insertRow(0).insertCell(0);
		$(cell).setParam({align:'center',valign:'center',innerHTML:'<h1 style="color:#4294CA">LOAD...</h1><img src="/img/ajax_loader.gif" />'});
		return table;	},
	dropProgressBar:function(){if ($('progres_bar').e()) $('progres_bar').drop();}
};

var main = extendClass (null,main_func);

function init_page()
{	var w = $().getClientH();
	$('main_page_table').ltwh({height:w+'px'});}


function move(o, event,rule)
{
	if (!event) event = window.event;
	var  dy = event.clientY-(rule.move?parseInt(o.style.top):parseInt(o.style.height));
	var  dx = event.clientX-(rule.move?parseInt(o.style.left):parseInt(o.style.width));
	var actionMove = rule.actionMove;
    if (typeof(actionMove)!='function') actionMove =function(obj,point){}
    var actionUp = rule.actionUp;
    if (typeof(actionUp)!='function') actionUp =function(obj){}

	if (document.addEventListener){
	   document.addEventListener('mousemove', moveHandler, true);
	   document.addEventListener('mouseup', upHandler, true);
	 }
	 else{
	   document.attachEvent('onmousemove', moveHandler);
	   document.attachEvent('onmouseup', upHandler);
	 }
	function moveHandler ()
	{
	 	var e = (arguments[0]||window.event);
	  	var y= e.clientY - dy;
	  	var x= e.clientX - dx;
	  actionMove(e,o,x,y);
	  e.stopped = true;
	  if (e.stopPropagation) {e.stopPropagation();} else {e.cancelBubble = true;}
	  if (e.preventDefault) {e.preventDefault();} else {e.returnValue = false;}
	}
	function upHandler ()
	{
	 var e = (arguments[0]||window.event);
	 if (document.removeEventListener){
	   document.removeEventListener('mousemove', moveHandler, true);
	   document.removeEventListener('mouseup', upHandler, true);}
	 else{
	   document.detachEvent('onmousemove', moveHandler);
	   document.detachEvent('onmouseup', upHandler);}
     if (e.stopPropagation) {e.stopPropagation();} else {e.cancelBubble = true;}
     if (e.preventDefault) {e.preventDefault();} else {e.returnValue = false;}
     e.stopped = true;
     actionUp(e,o);
	}
}
