function __StdModuleCore(ModuleObject, id, DefaultIcon, DefaultHeaderText, DefaultHelpText)
{
	var self = this;
	if(Desktop.templates[Skin].module)
		this.moduleColors = Desktop.templates[Skin].module;
	else
		this.moduleColors = Desktop.templates['default'].module;

	var m_color = Modules[id].State.color;
	if(!this.moduleColors[m_color])
	{	//цвета нет (сменили скин), присваиваем первый из нового скина
		for(var i in this.moduleColors)
		{
			m_color = i;
			Profile.update('module', 'update', {id: id}, {color: m_color});
			break;
		}
	}
	if(Desktop.templates[Skin].moduleSizes)
		var m_sizes = Desktop.templates[Skin].moduleSizes;
	else
		var m_sizes = Desktop.templates['default'].moduleSizes;
	if(Desktop.templates[Skin].moduleToolbar)
		var m_toolbar = Desktop.templates[Skin].moduleToolbar;
	else
		var m_toolbar = Desktop.templates['default'].moduleToolbar;

	var position = Modules[id].State.position;
	this.lang = Locale['_Modules'];
	this.ModuleObject = ModuleObject;
	this.ModuleObject.id = id;
	this.ModuleObject.DefaultHelpText = DefaultHelpText;
	this.ModuleObject.cName = Modules[id].State.cName;
	this.ModuleObject.TabID = Modules[id].State.TabID;
	this.ModuleObject.Container = ce('div', null, {id: 'Module.'+id, className: 'SimpleModule', 
		onmousemove: function() {
			if (Desktop && Desktop.CurrentModule != self.ModuleObject.id)
			{
				if (Modules[Desktop.CurrentModule]) {
					if (Modules[Desktop.CurrentModule].Object.Core.SubIconsLayer) Modules[Desktop.CurrentModule].Object.Core.SubIconsLayer.hide();
					Modules[Desktop.CurrentModule].Object.Core.HideIcons();
					Modules[Desktop.CurrentModule].Object.Core.HideHelp();
				}
				if (Modules[self.ModuleObject.id]) Modules[self.ModuleObject.id].Object.Core.ShowIcons();
				Desktop.CurrentModule = self.ModuleObject.id;
			}
		}}, {borderColor: this.moduleColors[m_color].border});

	switch (position)
	{
		case 'first':
			var first = Desktop.State[this.ModuleObject.cName].content[this.ModuleObject.TabID].content.firstChild;
			if(!first)
			{
				Desktop.State[this.ModuleObject.cName].content[this.ModuleObject.TabID].content.appendChild(this.ModuleObject.Container);
			}
			else
			{
				Desktop.State[this.ModuleObject.cName].content[this.ModuleObject.TabID].content.insertBefore(this.ModuleObject.Container, first);
			}
			break;
		case 'relative':
			Desktop.State[this.ModuleObject.cName].content[this.ModuleObject.TabID].content.insertBefore(this.ModuleObject.Container, $(Modules[id].State.itemID));
			break;
		default:
			Desktop.State[this.ModuleObject.cName].content[this.ModuleObject.TabID].content.appendChild(this.ModuleObject.Container);
	}

	this.ModuleObject.Header = ce('div', this.ModuleObject.Container, {id: 'Module.Header.'+id, className: 'Header'}, {borderColor: this.moduleColors[m_color].border, backgroundImage: 'url(\''+ this.moduleColors[m_color].bgX +'\')'});
	this.ModuleObject.Options = ce('div', this.ModuleObject.Container, {id: 'Module.Options.'+id, className: 'Options'}, {borderColor: this.moduleColors[m_color].border, backgroundColor: this.moduleColors[m_color].color, display: 'none'});
	this.ModuleObject.OptionsForm = ce('table', this.ModuleObject.Options, {className: 'Form'});
	this.ModuleObject.OptionsFormTBody = ce('tbody', this.ModuleObject.OptionsForm);
	this.ModuleObject.Content = ce('div', this.ModuleObject.Container, {id: 'Module.Content.'+id, className: 'Content'}, {borderColor: this.moduleColors[m_color].border, backgroundColor: this.moduleColors[m_color].color});

	var table = ce('table', this.ModuleObject.Header, null);
	var tbody = ce('tbody', table);
	var tr = ce('tr', tbody);
	var td1 = ce('td', tr, {className: 'mHeaderDiv1'});
	if(this.moduleColors[m_color].bgL)
		td1.style.background = 'url(\''+ this.moduleColors[m_color].bgL +'\') no-repeat';
	if (!DefaultIcon) DefaultIcon = 'trash';
	this.ModuleObject.Icons = {}
	this.ModuleObject.Icons.Main = ce('img', td1, {src: '/img/icons/'+DefaultIcon+'.gif', className: 'Icon'});

	var td2 = ce('td', tr, {className: 'mHeaderDiv2'});
	if(this.moduleColors[m_color].hcolor)
		td2.style.color = this.moduleColors[m_color].hcolor;
	var td3 = ce('td', tr, {className: 'mHeaderDiv3'});
	if(this.moduleColors[m_color].bgR)
		td3.style.background = 'url(\''+ this.moduleColors[m_color].bgR +'\') no-repeat right';
	this.ModuleObject.ModuleName = td2;
	this.SetHeader(DefaultHeaderText);

	this.ModuleObject.Icons.Manage = ce('img', td3, {src: m_toolbar.colors, title: this.lang['Styles'], className: 'Icon', onclick: function() {self.subIcons()}}, { marginRight: '5px', cursor: 'pointer', display: 'none'});
	this.ModuleObject.Icons.Help = ce('img', td3, {src: m_toolbar.question, title: Locale['Help'], className: 'Icon', onclick: function() {self.ToggleHelp()} }, { marginRight: '5px', cursor: 'pointer',  display: 'none'});
	this.ModuleObject.Icons.Resize = ce('img', td3, {src: m_toolbar.roll, title: this.lang['ToRollOnOff'], className: 'Icon', onclick: function() {self.ToggleAll()}}, { marginRight: '5px', cursor: 'pointer', display: 'none'});
	this.ModuleObject.Icons.Options = ce('img', td3, {src: m_toolbar.settings, title: this.lang['Options'], className: 'Icon', onclick: function(event) {self.ToggleOptions()}}, { marginRight: '5px', cursor: 'pointer', display: 'none'});
	this.ModuleObject.Icons.Close = ce('img', td3, {src: m_toolbar.close, title: Locale['ToClose'], className: 'Icon', onclick: function() {if (confirm(self.lang['ConfirmModuleDelete'])) ModManager.Delete(id);}}, {width: '16px', height: '16px', marginRight: '5px', cursor: 'pointer', display: 'none'});
	this.ModuleObject.Icons.Loading = ce('img', td1, {id: 'Module.'+this.ModuleObject.id+'.LoadIcon', src: '/img/actions/loading.gif'}, {display: 'none'});

	Desktop.ModulesContainer.AddItem('Module.'+id, 'Module.Header.'+id, this.onStopDrag.bind(this), this.onStartDrag.bind(this));
	this.ModuleObject.Timers = {};
	if(Profile.ApplyProfileInProgress)
		this.onCreateFromProfile();
	else
		this.onManualCreate();
	this.ControlState = {}
}

__StdModuleCore.prototype.RemoveControl = function(ControlID)
{
	switch(ControlID)
	{
		case 'options':
			this.ModuleObject.Options.parentNode.removeChild(this.ModuleObject.Options);
			this.ControlState['Options'] = false;
			break;
	}
}

__StdModuleCore.prototype.AddUpdater = function(name, callback, timeout)
{
	this.ModuleObject.Timers[name] = new PeriodicalExecuter(callback, timeout);
}

__StdModuleCore.prototype.DeleteUpdater = function(name)
{
	this.ModuleObject.Timers[name].stop();
}


__StdModuleCore.prototype.onManualCreate = function()
{
	this.ModuleObject.FromProfile = false;
	if (typeof this.ModuleObject.onManualCreate == 'function') this.ModuleObject.onManualCreate();
}

__StdModuleCore.prototype.onCreateFromProfile = function()
{
	this.ModuleObject.FromProfile = true;
	if(typeof this.ModuleObject.onCreateFromProfile == 'function')
		this.ModuleObject.onCreateFromProfile();
}

__StdModuleCore.prototype.onDelete = function()
{
	for (var i in this.ModuleObject.Timers) this.ModuleObject.Timers[i].stop();
	if (typeof this.ModuleObject.onDelete == 'function') this.ModuleObject.onDelete();
}

__StdModuleCore.prototype.onStartDrag = function()
{
	this.HideHelp();
	if(this.SubIconsLayer)
		$(this.SubIconsLayer).hide();
	if(typeof this.ModuleObject.onStartDrag == 'function')
		this.ModuleObject.onStartDrag();
}

__StdModuleCore.prototype.onStopDrag = function(item)
{
	if(typeof this.ModuleObject.onStopDrag == 'function')
		this.ModuleObject.onStopDrag();
	if(item)
	{
		var b = {cName: this.ModuleObject.cName, TabID: this.ModuleObject.TabID, id: this.ModuleObject.id};
		var t = item.id.split('.');
		this.ModuleObject.cName = t[1];
		this.ModuleObject.TabID = t[2];
		ModManager.SaveOrder(b.cName, b.TabID, b.id);
	}
	Desktop.OnResizeWindow();
}

__StdModuleCore.prototype.SetHeader = function(text)
{
	if(text && text.length>17)
		text = text.substr(0,17)+'...';
	this.ModuleObject.ModuleName.innerHTML = text;
}

__StdModuleCore.prototype.GetHeader = function()
{
	return(this.ModuleObject.ModuleName.innerHTML);
}

__StdModuleCore.prototype.HideIcons = function()
{
	for(var i in this.ModuleObject.Icons)
	{
		if(i != 'Main' && i!='Loading')
		{
			$(this.ModuleObject.Icons[i]).hide();
		}
	}
}


__StdModuleCore.prototype.ToggleHelp = function()
{
	if(!this.HelpLayer)
	{
		this.HelpLayer = ce('div', document.body, { id: 'Module.HelpLayer.'+this.ModuleObject.id, className: 'ModuleHelpLayer', innerHTML : 'test' }, { display: 'none', position: 'absolute'})
	}
	var position = getBounds1(this.ModuleObject.Container);
	var position1 = Position.page(this.ModuleObject.Container)
	position.left = position1[0];
	position.top = position1[1];
	if(document.body.offsetWidth - (position.left + position.width + 250) < 5)
	{
		this.HelpLayer.style.right = position.width+7 + 'px';
	}
	else
	{
		this.HelpLayer.style.left = position.width+7 + 'px';
	}

	this.HelpLayer.style.top = position.top + 'px';
	if(this.HelpLayer.style.display == 'none')
	{
		this.ShowHelp(this.ModuleObject.DefaultHelpText);
	}
	else
	{
		this.HideHelp();
	}
}

__StdModuleCore.prototype.ShowLoadingIcon = function()
{
	$(this.ModuleObject.Icons.Main).hide();
	$(this.ModuleObject.Icons.Loading).show();
}

__StdModuleCore.prototype.HideLoadingIcon = function()
{
	$(this.ModuleObject.Icons.Main).show();
	$(this.ModuleObject.Icons.Loading).hide();
}

__StdModuleCore.prototype.ShowHelp = function(text)
{
	this.HelpLayer.innerHTML = text;
	$(this.HelpLayer).show();
}

__StdModuleCore.prototype.HideHelp = function()
{
	if(this.HelpLayer)
		$(this.HelpLayer).hide();
}

__StdModuleCore.prototype.ToggleAll = function()
{
	$(this.ModuleObject.Options).hide();
	$(this.ModuleObject.Content).toggle();
	Profile.update('module', 'update', {id: this.ModuleObject.id}, {ShowOptions: $(this.ModuleObject.Options).visible(), ShowContent: $(this.ModuleObject.Content).visible()});
}

__StdModuleCore.prototype.ToggleOptions = function()
{
	$(this.ModuleObject.Options).toggle();
	if($(this.ModuleObject.Options).visible())
	{
		if(typeof this.ModuleObject.onOptionsVisible == 'function')
			this.ModuleObject.onOptionsVisible();
	}
	Profile.update('module', 'update', { id: this.ModuleObject.id }, { ShowOptions: $(this.ModuleObject.Options).visible()} );
}

__StdModuleCore.prototype.subIcons = function()
{
	var self = this;
	if(!this.SubIconsLayer)
	{
		this.SubIconsLayer = ce('ul', document.body, { id: 'Module.SubIconsLayer.'+this.ModuleObject.id, className: 'SubIconsLayer' }, {display: 'none'});
		var ModuleRecolor = ce('li', this.SubIconsLayer, { className: 'ModuleRecolor'});
		for(var i in this.moduleColors)
		{
			ce('div',  ModuleRecolor, { id: 'Module.Color.'+i, onclick: function(e) {self.ChangeColor(e, this)}}, {backgroundColor: this.moduleColors[i].color});
		}
	}
	var position = getBounds1(this.ModuleObject.Icons.Manage);
	var position1 = getBounds1(this.ModuleObject.Header);
	var scroll = Desktop.State[this.ModuleObject.cName].scrollTop ? Desktop.State[this.ModuleObject.cName].scrollTop : 0;
	var top = Position.page(this.ModuleObject.Header)[1];
	if(document.body.offsetWidth-(position.left+200)<5)
	{
		this.SubIconsLayer.style.right = '5px';
		this.SubIconsLayer.style.top = top + position.height + 6 + 'px';
	}
	else
	{
		this.SubIconsLayer.style.left = position.left - position.width + 'px';
		this.SubIconsLayer.style.top = top + position.height + 6 + 'px';
	}

	$(this.SubIconsLayer).toggle();
	if(this.SubIconsLayer.style.display == 'block' && ModManager.test != this.SubIconsLayer.id && ModManager.test)
	{
		Element.Hide(ge(ModManager.test));
	}
	ModManager.test = this.SubIconsLayer.id;
}

__StdModuleCore.prototype.ChangeColor = function(e, obj)
{
	var color = obj.id.split('.');
	color = color[2];
	var oTds = this.ModuleObject.Header.firstChild.firstChild.firstChild.childNodes;
	if(this.moduleColors[color].bgL)
		oTds[0].style.backgroundImage = 'url(\''+ this.moduleColors[color].bgL +'\')';
	if(this.moduleColors[color].bgR)
		oTds[2].style.backgroundImage = 'url(\''+ this.moduleColors[color].bgR +'\')';
	this.ModuleObject.Header.firstChild.style.backgroundImage = 'url(\''+ this.moduleColors[color].bgX +'\')';
	this.ModuleObject.Container.style.borderColor = this.moduleColors[color].border;
	this.ModuleObject.Header.style.borderColor = this.moduleColors[color].border;
	this.ModuleObject.Options.style.backgroundColor = this.moduleColors[color].color;
	this.ModuleObject.Options.style.borderColor = this.moduleColors[color].border;
	this.ModuleObject.Content.style.backgroundColor = this.moduleColors[color].color;
	this.ModuleObject.Content.style.borderColor = this.moduleColors[color].border;

	Profile.update('module', 'update', {id: this.ModuleObject.id}, {color: color});
	$(this.SubIconsLayer).hide();
}

__StdModuleCore.prototype.ShowIcons = function()
{
	for(var i in this.ModuleObject.Icons)
	{
		if(i!= 'Main' && i!='Loading' && this.ControlState[i] != false)
		{
			this.ModuleObject.Icons[i].style.display = 'inline';
		}
	}
}

__StdModuleCore.prototype.AddOption = function(HeaderText, element)
{
	if(!HeaderText)
		HeaderText = '';
	var Option = ce('tr', this.ModuleObject.OptionsFormTBody);
	var Header = ce('td', Option, { className: 'Header', innerHTML: HeaderText });
	var Item= ce('td', Option);
	if (element) Item.appendChild(element);
	return(Item);
}

__StdModuleCore.prototype.CheckLoadingStatus = function()
{
	if (this.ModuleObject.LoadingStatus)
	{
		window.alert(this.lang['LoadingInProgress']);
		return true;
	}
	else
		return false;
}