function pageClass(phpBlocks, phpPath, phpUser, phpStatus){
	var nodes = new function(){eval('result='+phpBlocks);return result}
	var markedMenu = null;
	var markedBlock = null;

	var linksInit = function(){
		var link = document.getElementsByTagName("A");
		var index = link.length;
    var temp = null;
		if (index){
			while (index--){
        temp = link[index];
        if (!temp.rel){
          temp.onclick = function(e){
            if (!e) e = window.event;
            e.cancelBubble = true;
            if (unescape(this.href).indexOf('{sources}') == -1) parent.location = this.href;
          }
        }
			}
		}
	}
	var blockInit = function(){
		if (1*phpStatus){
			var index = nodes.length;
			while (index--){
				var block = document.getElementById(nodes[index]);
				if (block){
					if (block.id.indexOf('data') != -1){
						var record = block.childNodes;
						var count = record.length;
						while (count--) if (record[count].id && record[count].id.indexOf('data') != -1) blockMenu(record[count]);
					}
				}
			}
		}
		linksInit();
	}
	var blockRequest = function(){
    var result = markedBlock.id.split("_");
		return (arguments[0] || false) ? result[0]+((result[1] || false) ? result[1] : '') : 'block='+result[0]+((result[1] || false) ? result[1]+'&id='+result[2] : '');
	}
	
	this.linkEvents = function(action){
		var wname = ''+Math.random();
		wname = wname.replace(/0\./, '');
		switch (action){
			case 'edit':
				window.open('/{editor}/?'+blockRequest()+'&action=edit&window='+wname, wname, 'left=200, top=200, width=800, height=600, toolbar=0, status=0, menubar=0, scrollbar=1, resizable=1');
			break;
			case 'add':
				window.open('/{editor}/?'+blockRequest()+'&action=add&window='+wname, wname, 'left=200, top=200, width=800, height=600, toolbar=0, status=0, menubar=0, scrollbar=1, resizable=1');
			break;
			case 'drop':
				if (confirm("Вы действительно хотите удалить элемент?")) xmlRequest('drop', '', blockRequest());
			break;
			case 'folders':
				window.open('/{folders}/?page='+phpPath, '', 'left=150, top=200, width=800, height=600, toolbar=0, status=0, menubar=0, scrollbar=1, resizable=1');
			break;
			case 'exit':
				xmlRequest('exit', '', '');
			break;
			case 'panel':
				xmlRequest('panel', '', '');
			break;
		}
	}
	
	var blockUpdate = function(block_id, bcontent){
		var block = document.getElementById(block_id);
		if (block){
			if (document.all && block.nodeName == "TBODY"){
				var table = block.parentNode;
				var text = '<table class="'+table.className+'">'+table.childNodes[0].outerHTML+'<tbody id="'+block_id+'">'+bcontent+'</tbody></table>';
				table.outerHTML = text;
			}
			else block.innerHTML = bcontent;
		}
	}

	var xmlRequest = function(action, object, values, dialog){
		var getLinks = (window.parent) ? window.parent.location.search : window.location.search;
		JsHttpRequest.query('/{editor}/request.php'+getLinks,
			{'action':action, 'object':object||'', 'values':values||''},
			function(result, error){
				if (action == 'exit'){
					window.parent.location.href = 'http://'+window.location.host;
					return;
				}
				if (action == 'panel'){
					window.parent.location.href = window.parent.location.href;
					return;
				}
				if (error) alert(error);
				var b2upd = result['refresh'].split(',');
				var bcnt = b2upd.length;
				while (bcnt--) blockUpdate(b2upd[bcnt], result[b2upd[bcnt]]);
				hideMenu();
				blockInit();
				if (dialog) dialog.close();
			},
			true)
	}
	
	this.xmlRequest = function(action, object, values, dialog){
    xmlRequest(action, object, values, dialog);
	}

	this.hideMenu = function(){
		hideMenu();
    blockHide(markedBlock);
    markedBlock = null;
	}
	var hideMenu = function(){
		var panel = window.parent.window["panel"];
		if (panel){
			panel = panel.document;
			panel.getElementById('edit').style.display = panel.getElementById('add').style.display = panel.getElementById('drop').style.display = "none";
		}
		if (markedMenu) document.body.removeChild(markedMenu);
		markedMenu = null;
	}
  
  var blockHide = function(block){
    if (block){
      block.style.backgroundImage = block.oldBgImage;
      block.style.backgroundRepeat = block.oldBgRepeat;
    }
  }
  
  var blockShow = function(block){
    block.oldBgImage = block.style.backgroundImage;
    block.oldBgRepeat = block.style.backgroundRepeat;
    block.style.backgroundImage = "url({styles}/sys/img/edit.gif)";
    block.style.backgroundRepeat = "repeat";
  }

	var blockMenu = function(block){
		var markBlock = function(){
			var panel = window.parent.window["panel"];
      
      if (block != markedBlock){
        blockHide(markedBlock);
        markedBlock = block;
      }
      block.mouseOutOld = block.onmouseout;
      block.onmouseout = null;
			hideMenu();
      
      
			if (panel){
				panel = panel.document;
				panel.getElementById('edit').style.display = panel.getElementById('add').style.display = panel.getElementById('drop').style.display = "";
			}
		}
    
		block.onmouseover = function(e){
			if (!e) e = window.event;
      if (this != markedBlock) blockShow(this);
			e.cancelBubble = true;
		}
		block.onmouseout = function(){
      blockHide(this);
		}
		block.onclick = function(){
			markBlock();
		}
		block.oncontextmenu = function(e){
			markBlock();
			if (!e) e = window.event;
			var click = (e.x)?{top:e.y,left:e.x}:{top:e.pageY,left:e.pageX};
			markedMenu = document.createElement("DIV");
			markedMenu.className = "corepopup";
			markedMenu.oncontextmenu = function(){return false};
			var scroll = document.getElementsByTagName("HTML")[0];
			with (markedMenu.style){
				top = ((window.pageYOffset) ? 0 : scroll.scrollTop)+click.top+"px";
				if (parseInt(top)>(scroll.clientHeight+scroll.scrollTop-234)) top = (scroll.clientHeight-234)+scroll.scrollTop+"px";
				left = ((window.pageXOffset) ? 0 : scroll.scrollLeft)+click.left+"px";
				if (parseInt(left)>(scroll.clientWidth+scroll.scrollLeft-162)) left = (scroll.clientWidth-162)+scroll.scrollLeft+"px";
			}
			document.body.appendChild(markedMenu);
      
      var key = (
        (this.id.indexOf('data') != -1) &&
        (this.id.indexOf('data_111_') == -1)
      );
      
			markedMenu.innerHTML = '\
      <h1><a onclick="window.page.linkEvents(\'edit\');return false" href="">Редактировать</a>'+( key ? '<a class="add" onclick="window.page.linkEvents(\'add\');return false" href="">Добавить элемент</a><a class="drop" onclick="window.page.linkEvents(\'drop\');return false" href="">Удалить элемент</a>' : '<div></div><div></div>')+'<a class="border" onclick="window.page.linkEvents(\'folders\');return false" href="">Структура</a><a class="border" onclick="page.hideMenu();return false" href="">Закрыть меню</a><a onclick="window.page.linkEvents(\'panel\');return false" href="">Верхняя панель</a><a class="border" onclick="window.page.linkEvents(\'exit\');return false" href="">Выход из системы</a></h1>';
			e.cancelBubble = true;
			return false;
		}				
	}
	blockInit();
  
  this.blockInit = blockInit;
}
