function __Desktop()
{
	this.templates = {
		'clouds': {
			headPic: {src:'/img/tpl/clouds/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/clouds/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/clouds/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/clouds/actions/blt_down.gif'},
			module: {
				cyan: {border: '#004777', color: '#EDFAFF', bgX: '/img/tpl/clouds/module/bg/blue_x.gif'},
				green: {border: '#004777', color: '#D8F3E2', bgX: '/img/tpl/clouds/module/bg/blue_x.gif'},
				yellow: {border: '#004777', color: '#FFF7CB', bgX: '/img/tpl/clouds/module/bg/blue_x.gif'},
				red: {border: '#004777', color: '#F7DFDF', bgX: '/img/tpl/clouds/module/bg/blue_x.gif'}
			},
			moduleSizes: {
				hTd1padding: '3px 0px 0px 5px',
				hTd1Width: '40px',
				hTd2padding: '0px',
				hTd3padding: '4px 5px 0px 0px'
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '132,35,40'
		},
		'fishing': {
			headPic: {src:'/img/tpl/fishing/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/fishing/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/fishing/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/fishing/actions/blt_down.gif'},
			module: {
				cyan: {border: '#004777', color: '#CEF6FA', bgX: '/img/tpl/fishing/module/bg/blue_x.gif'},
				green: {border: '#004777', color: '#B6F1BF', bgX: '/img/tpl/fishing/module/bg/blue_x.gif'},
				yellow: {border: '#004777', color: '#FFF7CB', bgX: '/img/tpl/fishing/module/bg/blue_x.gif'},
				red: {border: '#004777', color: '#FFD4DC', bgX: '/img/tpl/fishing/module/bg/blue_x.gif'}
			},
			moduleSizes: {
				hTd1padding: '3px 0px 0px 5px',
				hTd1Width: '40px',
				hTd2padding: '0px',
				hTd3padding: '4px 5px 0px 0px'
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '158,35,40'
		},
		'football': {
			headPic: {src:'/img/tpl/football/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/football/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/football/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/football/actions/blt_down.gif'},
			module: {
				cyan: {border: '#163D03', color: '#DFF5F7', bgX: '/img/tpl/football/module/bg/blue_x.gif'},
				green: {border: '#163D03', color: '#E1ECE2', bgX: '/img/tpl/football/module/bg/green_x.gif'},
				yellow: {border: '#163D03', color: '#F8F3DB', bgX: '/img/tpl/football/module/bg/yellow_x.gif'},
				red: {border: '#163D03', color: '#FFEEEA', bgX: '/img/tpl/football/module/bg/red_x.gif'},
				gray: {border: '#163D03', color: '#E7E7E7', bgX: '/img/tpl/football/module/bg/gray_x.gif'}
			},
			moduleSizes: {
				hTd1padding: '3px 0px 0px 5px',
				hTd1Width: '40px',
				hTd2padding: '0px',
				hTd3padding: '4px 5px 0px 0px'
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '158,35,40'
		},
		'astrolog': {
			headPic: {src:'/img/tpl/astrolog/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/astrolog/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/astrolog/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/astrolog/actions/blt_down.gif'},
			module: {
				green: {border: '#001020', color: '#C7E6CA', bgX: '/img/tpl/astrolog/module/bg/green_x.jpg'},
				yellow: {border: '#001020', color: '#F4EFBF', bgX: '/img/tpl/astrolog/module/bg/yellow_x.jpg'},
				red: {border: '#001020', color: '#EFD8CC', bgX: '/img/tpl/astrolog/module/bg/red_x.jpg'},
				blue: {border: '#001020', color: '#C9E1F1', bgX: '/img/tpl/astrolog/module/bg/blue_x.jpg'},
				gray: {border: '#001020', color: '#DAE3E7', bgX: '/img/tpl/astrolog/module/bg/gray_x.jpg'},
				marsh: {border: '#001020', color: '#D0D9D1', bgX: '/img/tpl/astrolog/module/bg/marsh_x.jpg'},
				brown: {border: '#001020', color: '#EFD8CC', bgX: '/img/tpl/astrolog/module/bg/brown_x.jpg'}
			},
			moduleSizes: {
				hTd1padding: '3px 0px 0px 5px',
				hTd1Width: '40px',
				hTd2padding: '0px',
				hTd3padding: '4px 5px 0px 0px'
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '158,35,40'
		},
		'china': {
			headPic: {src:'/img/tpl/china/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/china/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/china/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/china/actions/blt_down.gif'},
			module: {
				brown: {border: '#2D1100', color: '#EED393', bgX: '/img/tpl/china/module/bg/brown_x.gif'},
				green: {border: '#2D1100', color: '#D2E4CF', bgX: '/img/tpl/china/module/bg/green_x.gif'},
				red: {border: '#2D1100', color: '#F2D2BC', bgX: '/img/tpl/china/module/bg/red_x.gif'},
				cyan: {border: '#2D1100', color: '#C7DADC', bgX: '/img/tpl/china/module/bg/cyan_x.gif'},
				gray: {border: '#2D1100', color: '#E5E5E5', bgX: '/img/tpl/china/module/bg/gray_x.gif'}
			},
			moduleSizes: {
				hTd1padding: '3px 0px 0px 5px',
				hTd1Width: '40px',
				hTd2padding: '0px',
				hTd3padding: '4px 5px 0px 0px'
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '158,35,40'
		},
		'bushroot': {
			headPic: {src:'/img/tpl/bushroot/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/bushroot/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/bushroot/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/bushroot/actions/blt_down.gif'},
			module: {
				green: {border: '#004777', color: '#E1ECE2', bgX: '/img/tpl/bushroot/module/bg/green_x.gif'},
				blue: {border: '#004777', color: '#DBF1FA', bgX: '/img/tpl/bushroot/module/bg/blue_x.gif'},
				pink: {border: '#004777', color: '#FFEEEA', bgX: '/img/tpl/bushroot/module/bg/pink_x.gif'},
				gray: {border: '#004777', color: '#E9E9E9', bgX: '/img/tpl/bushroot/module/bg/gray_x.gif'},
				brown: {border: '#004777', color: '#F9F3DB', bgX: '/img/tpl/bushroot/module/bg/brown_x.gif'}
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '155,34,32'
		},
		'auto': {
			headPic: {src:'/img/tpl/auto/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/auto/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/auto/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/auto/actions/blt_down.gif'},
			module: {
				green: {border: '#797E8B', color: '#D0D9D1', bgX: '/img/tpl/auto/module/bg/green_x.gif'},
				gray: {border: '#797E8B', color: '#ECECF0', bgX: '/img/tpl/auto/module/bg/gray_x.gif'},
				orange: {border: '#797E8B', color: '#EFD8CC', bgX: '/img/tpl/auto/module/bg/orange_x.gif'},
				blue: {border: '#797E8B', color: '#B6DFF5', bgX: '/img/tpl/auto/module/bg/blue_x.gif'},
				toxic: {border: '#797E8B', color: '#C7E6CA', bgX: '/img/tpl/auto/module/bg/toxic_x.gif'},
				yellow: {border: '#797E8B', color: '#FBF7C1', bgX: '/img/tpl/auto/module/bg/yellow_x.gif'},
				red: {border: '#797E8B', color: '#FDD7D7', bgX: '/img/tpl/auto/module/bg/red_x.gif'}
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '155,34,32'
		},
		'gurman': {
			headPic: {src:'/img/tpl/gurman/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/gurman/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/gurman/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/gurman/actions/blt_down.gif'},
			module: {
				red: {border: '#000000', color: '#F9DADA', bgX: '/img/tpl/gurman/module/bg/red_x.gif'},
				yellow: {border: '#000000', color: '#FFFCC8', bgX: '/img/tpl/gurman/module/bg/yellow_x.gif'},
				green: {border: '#000000', color: '#D4F2C4', bgX: '/img/tpl/gurman/module/bg/green_x.gif'},
				gray: {border: '#000000', color: '#EDEDED', bgX: '/img/tpl/gurman/module/bg/gray_x.gif'},
				cyan: {border: '#000000', color: '#E6F3FF', bgX: '/img/tpl/gurman/module/bg/cyan_x.gif'}
			},
			moduleSizes: {
				hTd1padding: '3px 0px 0px 5px',
				hTd1Width: '40px',
				hTd2padding: '0px',
				hTd3padding: '4px 5px 0px 0px'
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '132,35,40'
		},
		'vine': {
			headPic: {src:'/img/tpl/vine/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/vine/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/vine/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/vine/actions/blt_down.gif'},
			module: {
				red: {border: '#520000', color: '#D7B698', bgX: '/img/tpl/vine/module/bg/red_x.gif'},
				yellow: {border: '#520000', color: '#FFFCC8', bgX: '/img/tpl/vine/module/bg/yellow_x.gif'},
				green: {border: '#520000', color: '#DAE3D6', bgX: '/img/tpl/vine/module/bg/green_x.gif'},
				gray: {border: '#520000', color: '#D8D8D8', bgX: '/img/tpl/vine/module/bg/gray_x.gif'},
				blue: {border: '#520000', color: '#BEC6D3', bgX: '/img/tpl/vine/module/bg/blue_x.gif'}
			},
			moduleSizes: {
				hTd1padding: '3px 0px 0px 5px',
				hTd1Width: '40px',
				hTd2padding: '0px',
				hTd3padding: '4px 5px 0px 0px'
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '132,35,40'
		},
		'megapink': {
			headPic: {src:'/img/tpl/megapink/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/megapink/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/megapink/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/megapink/actions/blt_down.gif'},
			module: {
				pink: {border: '#C54251', color: '#FBDCE2', bgX: '/img/tpl/megapink/module/bg/pink_x.gif', bgL: '/img/tpl/megapink/module/bg/pink_l.gif', bgR: '/img/tpl/megapink/module/bg/pink_r.gif'},
				blue: {border: '#486498', color: '#C0E2FD', bgX: '/img/tpl/megapink/module/bg/blue_x.gif', bgL: '/img/tpl/megapink/module/bg/blue_l.gif', bgR: '/img/tpl/megapink/module/bg/blue_r.gif'},
				brown: {border: '#947C48', color: '#FFF7CB', bgX: '/img/tpl/megapink/module/bg/brown_x.gif', bgL: '/img/tpl/megapink/module/bg/brown_l.gif', bgR: '/img/tpl/megapink/module/bg/brown_r.gif'},
				cyan: {border: '#3F8994', color: '#CDF3FE', bgX: '/img/tpl/megapink/module/bg/cyan_x.gif', bgL: '/img/tpl/megapink/module/bg/cyan_l.gif', bgR: '/img/tpl/megapink/module/bg/cyan_r.gif'},
				green: {border: '#60806F', color: '#D8F3E2', bgX: '/img/tpl/megapink/module/bg/green_x.gif', bgL: '/img/tpl/megapink/module/bg/green_l.gif', bgR: '/img/tpl/megapink/module/bg/green_r.gif'},
				gray: {border: '#838383', color: '#E9E9E9', bgX: '/img/tpl/megapink/module/bg/gray_x.gif', bgL: '/img/tpl/megapink/module/bg/gray_l.gif', bgR: '/img/tpl/megapink/module/bg/gray_r.gif'}
			},
			logoMap: '244,34,32'
		},
		'megablack': {
			headPic: {src:'/img/tpl/megablack/k2-up.png'},
			rollTabIcon: {src: '/img/tpl/megablack/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/megablack/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/megablack/actions/blt_down.gif'},
			module: {
				pink: {border: '#000000', color: '#FBDCE2', hcolor: '#FFFFFF', bgX: '/img/tpl/megablack/module/bg/black_x.gif', bgL: '/img/tpl/megablack/module/bg/black_l.gif'},
				blue: {border: '#000000', color: '#C0E2FD', hcolor: '#FFFFFF', bgX: '/img/tpl/megablack/module/bg/black_x.gif', bgL: '/img/tpl/megablack/module/bg/black_l.gif'},
				brown: {border: '#000000', color: '#FFF7CB', hcolor: '#FFFFFF', bgX: '/img/tpl/megablack/module/bg/black_x.gif', bgL: '/img/tpl/megablack/module/bg/black_l.gif'},
				cyan: {border: '#000000', color: '#CDF3FE', hcolor: '#FFFFFF', bgX: '/img/tpl/megablack/module/bg/black_x.gif', bgL: '/img/tpl/megablack/module/bg/black_l.gif'},
				green: {border: '#000000', color: '#D8F3E2', hcolor: '#FFFFFF', bgX: '/img/tpl/megablack/module/bg/black_x.gif', bgL: '/img/tpl/megablack/module/bg/black_l.gif'},
				gray: {border: '#000000', color: '#E9E9E9', hcolor: '#FFFFFF', bgX: '/img/tpl/megablack/module/bg/black_x.gif', bgL: '/img/tpl/megablack/module/bg/black_l.gif'}
			},
			moduleToolbar: {
				colors: '/img/tpl/megablack/module/toolbar/colors.gif',
				settings: '/img/tpl/megablack/module/toolbar/settings.gif',
				roll: '/img/tpl/megablack/module/toolbar/roll.gif',
				question: '/img/tpl/megablack/module/toolbar/question.gif',
				close: '/img/tpl/megablack/module/toolbar/close.gif'
			},
			logoMap: '32,34,32'
		},
		'megadark': {
			headPic: {src:'/img/tpl/megadark/k2-up.jpg'},
			rollTabIcon: {src: '/img/tpl/megadark/actions/rolltab.gif'},
			addTabIcon: {src: '/img/tpl/megadark/actions/addtab.gif'},
			bltDownIcon: {src: '/img/tpl/megablack/actions/blt_down.gif'},
			module: {
				blue: {border: '#000000', color: '#B6C9DC', bgX: '/img/tpl/megadark/module/bg/black_x.gif'},
				cyan: {border: '#000000', color: '#DFF5F7', bgX: '/img/tpl/megadark/module/bg/black_x.gif'},
				brown: {border: '#000000', color: '#F8F3DB', bgX: '/img/tpl/megadark/module/bg/black_x.gif'}
			},
			moduleToolbar: {
				colors: '/img/tpl/megadark/module/toolbar/colors.gif',
				settings: '/img/tpl/megadark/module/toolbar/settings.gif',
				roll: '/img/tpl/megadark/module/toolbar/roll.gif',
				question: '/img/tpl/megadark/module/toolbar/question.gif',
				close: '/img/tpl/megadark/module/toolbar/close.gif'
			},
			logoMap: '34,34,36'
		},
		'default': {
			headPic: {src:'/img/tpl/default/k2-up.jpg'},
			rollTabIcon: {src: '/img/actions/minus.gif'},
			addTabIcon: {src: '/img/actions/plus.gif'},
			bltDownIcon: {src: '/img/tpl/megapink/actions/blt_down.gif'},
			module: {
				gray: {border: '#ACACAC', color: '#F0F0F0', bgX: '/img/tpl/default/module/bg/gray_x.gif'},
				blue: {border: '#717D93', color: '#F4F4F4', bgX: '/img/tpl/default/module/bg/blue_x.gif'},
				pink: {border: '#AF718A', color: '#EDDBE7', bgX: '/img/tpl/default/module/bg/pink_x.gif'},
				cyan: {border: '#6997B4', color: '#D9F0FF', bgX: '/img/tpl/default/module/bg/cyan_x.gif'},
				green: {border: '#6F8E80', color: '#D8F3E2', bgX: '/img/tpl/default/module/bg/green_x.gif'},
				brown: {border: '#B6A172', color: '#F5EED1', bgX: '/img/tpl/default/module/bg/brown_x.gif'}
			},
			moduleToolbar: {
				colors: '/img/tpl/default/module/toolbar/colors.gif',
				settings: '/img/tpl/default/module/toolbar/settings.gif',
				roll: '/img/tpl/default/module/toolbar/roll.gif',
				question: '/img/tpl/default/module/toolbar/question.gif',
				close: '/img/tpl/default/module/toolbar/close.gif'
			},
			logoMap: '229,34,32'
		},
		'beige': {
			headPic: {src:'/img/tpl/beige/k2-up.jpg'},
			rollTabIcon: {src: '/img/actions/minus.gif'},
			addTabIcon: {src: '/img/actions/plus.gif'},
			bltDownIcon: {src: '/img/tpl/megapink/actions/blt_down.gif'}
		},
		'pink': {
			headPic: {src:'/img/tpl/pink/k2-up.jpg'},
			rollTabIcon: {src: '/img/actions/minus.gif'},
			addTabIcon: {src: '/img/actions/plus.gif'},
			bltDownIcon: {src: '/img/tpl/megapink/actions/blt_down.gif'}
		},
		'green': {
			headPic: {src:'/img/tpl/green/k2-up.jpg'},
			rollTabIcon: {src: '/img/actions/minus.gif'},
			addTabIcon: {src: '/img/actions/plus.gif'},
			bltDownIcon: {src: '/img/tpl/megapink/actions/blt_down.gif'}
		},
		'brown': {
			headPic: {src:'/img/tpl/brown/k2-up.jpg'},
			rollTabIcon: {src: '/img/actions/minus.gif'},
			addTabIcon: {src: '/img/actions/plus.gif'},
			bltDownIcon: {src: '/img/tpl/megapink/actions/blt_down.gif'}
		},
		'white': {
			headPic: {src:'/img/tpl/white/k2-up.jpg'},
			rollTabIcon: {src: '/img/actions/minus.gif'},
			addTabIcon: {src: '/img/actions/plus.gif'},
			bltDownIcon: {src: '/img/tpl/megapink/actions/blt_down.gif'}
		}
	}

	this.DefaultHeight = 70;
	this.DefaultWidth = 310;
	this.TabsLimit = 10;
	this.DefaultIcon = 'kz';
	this.State = {cLeft: {toggle: 0, current: 0}, cRight: {toggle: 0, current: 0}, cMain: {toggle: 0, current: 0}, cUp: {toggle: 0, current: 0}};

	this.lang = Locale['_Desktop'];
	this.BodyWidth = $(document.body).getWidth();
	this.BodyHeight = $(document.body).getHeight();

	this.cUp = ce('div', document.body, {id: 'cUp'});
	ce('DIV', document.body, {id: 'version', innerHTML: 'VERSION 2.0'});
	this.cLeft = ce('div', document.body, { id: 'cLeft', innerHTML:
		'<table id="cLeftPanel"><tr><td id="cLeftContainer"><div id="cLeftContent"></div></td><td id="cLeftTabsContainer">'+
		'<ul id="cLeftTabs"><li class="Header"><img id="Toggle.cLeft" class="Controls" src="'+ this.templates[Skin].rollTabIcon.src +'" title="'+ this.lang['ToRollOnOff'] +'"></li></ul></td></tr></table>'
	});
	$('cLeftContent').onscroll = function(event) { var target = Event.element(event); this.State.cLeft.scrollTop = target.scrollTop; }.bindAsEventListener(this);
	this.cRight = ce('div', document.body, { id: 'cRight', innerHTML:
		'<table id="cRightPanel"><tr><td id="cRightTabsContainer">'+
		'<ul id="cRightTabs"><li class="Header"><img id="Toggle.cRight" class="Controls" src="'+ this.templates[Skin].rollTabIcon.src +'" title="'+ this.lang['ToRollOnOff'] +'"></li></ul></td><td id="cRightContainer"><div id="cRightContent"></div></td></tr></table>'
	});
	$('cRightContent').onscroll = function(event) { var target = Event.element(event); this.State.cRight.scrollTop = target.scrollTop; }.bindAsEventListener(this);

	this.cMain = ce('div', document.body, { id: 'cMain', innerHTML:
		'<table id="cMainTabsContainer"><tr><td><ul id="cMainTabs"></ul></td></tr></table><div id="cMainContent"></div>'
	});
	this.cUpResize = ce('div', document.body, { id: 'cUpResize' });
	this.cLeftResize = ce('div', document.body, { id: 'cLeftResize' });
	this.cRightResize = ce('div', document.body, { id: 'cRightResize' });

	$('Toggle.cLeft').observe('click', this.TogglePanel.bindAsEventListener(this));
	$('Toggle.cRight').observe('click', this.TogglePanel.bindAsEventListener(this));
	this.cLeftResize.observe('mousedown', this.DoStartResize.bindAsEventListener(this));
	this.cRightResize.observe('mousedown', this.DoStartResize.bindAsEventListener(this));
	Event.observe(window, 'resize', this.OnResizeWindow.bindAsEventListener(this));

	this.AddCreateTabControl('cLeft');
	this.AddCreateTabControl('cRight');
	this.AddCreateTabControl('cMain');

	this.DrawcMainContent();

	this.ModulesContainer = new __DDrop(true, 'vertical');
}

__Desktop.prototype.NewModuleBox = function(event)
{
	var target = Event.element(event).id.split('.');
	if(target[0] != 'Content')
		return;
	this.MousePos = {x: Event.pointerX(event), y: Event.pointerY(event) };
	this.CurrentPanel = Event.element(event);
	// Запускаем таймер на создание
	if(this.NewModuleBoxTimer)
		clearTimeout(this.NewModuleBoxTimer);
	this.NewModuleBoxTimer = setTimeout(this.DrawNewModuleBox.bind(this), 500);
}

__Desktop.prototype.DrawNewModuleBox = function()
{
	// Бежим по гаджетам текущей панели и получаем у них ID
	var modules = this.CurrentPanel.childNodes;
	var min = 100000;
	for(var i=0;i!=modules.length;i++)
	{
		var page = Position.page(modules[i]);
		var size = { width: $(modules[i]).getWidth(), height: $(modules[i]).getHeight() }
		var value = this.MousePos.y - page[1];
		if (value>0)
		{
			if (value<min)
			{
				min = value;
				var item = modules[i];
			}
		}
	}
	// Подготовливаем
	if (!this.SBox)
	{
		this.SBox = ce('ul', null, { id: 'SBox', innerHTML: '', className: 'SBox'} );
		this.SBox.update(Locale['ToAdd'] +': <select></select>');
		var select = this.SBox.getElementsByTagName('select');
		select[0].onchange = this.AddModuleFromSBox.bindAsEventListener(this);
		for (var i in Cache.Modules)
		{
			ce('option', select[0], { value: i, innerHTML: Cache.Modules[i].title});
		}
	}
	if (this.SBox.parentNode && this.SBox)
	{
		this.SBox.parentNode.removeChild(this.SBox);
	}
	if (!item)
	{
		this.CurrentPanel.appendChild(this.SBox);
	}
	else
	{
		this.it = item;
		this.CurrentPanel.insertBefore(this.SBox, item.nextSibling);
	}
}

__Desktop.prototype.AddModuleFromSBox = function(event)
{
	var target = Event.element(event);
	var type = $F(target);
	var panel = this.CurrentPanel.id.split('.');
	ModManager.Create(type, panel[1], panel[2], null, null, this.it || null);
	this.NewModuleBoxHideBox();
}

__Desktop.prototype.NewModuleBoxHideBox = function()
{
	if (this.SBox.parentNode)
		this.SBox.parentNode.removeChild(this.SBox);
}

__Desktop.prototype.OnResizeWindow = function()
{
	this.BodyWidth = $(document.body).getWidth();
	this.BodyHeight = $(document.body).getHeight();
	var MainTop = this.cUpResize.getHeight() + this.cUp.getHeight();
	var MainHeight = this.BodyHeight - this.cUpResize.getHeight() - this.cUp.getHeight() - this.cUp.getOuterHeight();
	this.cLeft.applyStyle({ top: MainTop, height: MainHeight });
	this.cRight.applyStyle({ top: MainTop, height: MainHeight });
	this.cLeftResize.applyStyle({ top: MainTop, height: MainHeight });
	this.cRightResize.applyStyle({ top: MainTop, height: MainHeight });
	this.cMain.applyStyle({ top: MainTop, height: MainHeight });

	$('cLeftPanel').applyStyle({ height: MainHeight });
	$('cLeftTabs').applyStyle({ height: MainHeight });
	$('cLeftContent').applyStyle({ height: MainHeight - $('cLeftContent').getOuterHeight()});

	$('cRightPanel').applyStyle({ height: MainHeight });
	$('cRightTabs').applyStyle({ height: MainHeight });
	$('cRightContent').applyStyle({ height: MainHeight - $('cRightContent').getOuterHeight()});

	this.ResizeMain();
	this.cRight.applyStyle({ left: this.BodyWidth - this.cRight.getWidth(), width: this.cRight.getWidth() });
	this.cRightResize.applyStyle({ left: this.BodyWidth - this.cRight.getWidth() - this.cRightResize.getWidth() });
	this.cMain.applyStyle({ left: this.cLeft.getWidth() +  this.cLeftResize.getWidth(), width: this.BodyWidth - 2*this.cLeftResize.getWidth() - this.cLeft.getWidth() - this.cRight.getWidth() });

	var id = this.State.cMain.current.id.split('.')[2];
	var size = $('Content.cMain.'+id).parentNode.getHeight() - $('Content.cMain.'+id).parentNode.getOuterHeight();
	$('Content.cMain.'+id).applyStyle({ height: size });

	if (this.State.cMain.content[id].url)
	{
		$('Browser.'+id).parentNode.parentNode.parentNode.applyStyle({ overflow: 'hidden'});
		$('Browser.'+id).applyStyle({ height: size });
		if (this.Scroll && this.Scroll['Browser.'+id])
		{
			window.frames['Browser.'+id].scrollTo(this.Scroll['Browser.'+id][0],this.Scroll['Browser.'+id][1]);
		}
	}
}

__Desktop.prototype.drawLangMenu = function()
{
	//языковая панель
	var oForm = ce('FORM', document.body, {id: 'langTopForm', action: '/lang.php', method: 'post'});
	ce('INPUT', oForm, {type: 'hidden', name: 'lang'});
	ce('IMG', oForm, {src: '/img/lang_'+ Lang +'.gif', align: 'absMiddle'}, {marginRight: '5px', border: '1px solid #FFFFFF'});
	ce('SPAN', oForm, {innerHTML: AvailableLangs[Lang]});
	ce('IMG', oForm, {src: this.templates[Skin].bltDownIcon.src, align: 'absMiddle'}, {marginLeft: '10px'});
	var oUl = ce('UL', oForm, {id: 'langFlagMenu', className: 'menu'}, {display: 'none'});
	oForm.onmouseover = function()
	{
		oUl.style.display = ''
	};
	oForm.onmouseout = function()
	{
		oUl.style.display = 'none'
	};
	for(var i in AvailableLangs)
	{
		if(i == 'IT') continue;	//временно
		oLi = ce('LI', oUl, {lang: i, innerHTML: '<img src="/img/lang_'+ i +'.gif" align="absmiddle" title="'+ i +'" style="margin-right: 5px; border: 1px solid #FFFFFF;"/>'+AvailableLangs[i]});
		if(i != Lang)
		{
			oLi.onclick = f1;
			oLi.onmouseover = enLight;
			oLi.onmouseout = offLight;
		}
		else
		{
			oLi.style.cursor = 'default';
			oLi.style.backgroundColor = '#EEDDDD'
			oLi.style.color = '#555555';
		}
	}

	function f1()
	{
		oForm.firstChild.value = this.lang;
		oForm.submit();
	}
	function enLight()
	{
		this.style.backgroundColor = '#EEDDDD';
	}
	function offLight()
	{
		this.style.backgroundColor = '';
	}
}

__Desktop.prototype.DrawcMainContent = function()
{	//шапка
	ce('IMG', this.cUp, {src: this.templates[Skin].headPic.src, id: 'mainHeadImg', useMap: '#logoMap'}, {border: 'none'});
	this.cUp.innerHTML += '<map name="logoMap"><area shape="circle" title="'+this.lang['ResetToDefaults']+'" coords="'+ ((this.templates[Skin].logoMap)?this.templates[Skin].logoMap:this.templates['default'].logoMap) +'" onclick="Startup.resetToDefault()" href="#" class="href"/></map>';
	var oDiv = ce('DIV', this.cUp, {id: 'mainToolBar'});
	var icons = '/img/tpl/'+Skin+'/toolbar/';
	ce('IMG', oDiv, {src: icons+'favourites.gif', title: this.lang['Bookmarks'], onclick: bookmark, className: 'href'});
	ce('IMG', oDiv, {src: icons+'start.gif', title: this.lang['ToMakeHome'], onclick: function() {SetHomepage(this)}, className: 'href'});
	ce('IMG', oDiv, {src: icons+'feedback.gif', title: Locale['Feedback'], onclick: function() {Settings.Hide(); Startup.DrawFeedbackForm();}, className: 'href'});
	ce('IMG', oDiv, {src: icons+'settings.gif', title: Locale['Options'], onclick: function() {Settings.Show()}, className: 'href'});
	ce('IMG', oDiv, {src: icons+'help.gif', title: Locale['_Settings']['Info'], onclick: function() {Info.Show()}, className: 'href'});
	ce('IMG', oDiv, {src: icons+'profiles.gif', title: this.lang['ProfilesGallery'], onclick: function() {GProfiles.show()}, className: 'href'});
	ce('IMG', oDiv, {src: icons+'p2friend.gif', title: Locale['_Settings']['ProfileToFriend'], onclick: function() {Startup.initProfileToFriend()}, className: 'href'}, {marginRight: '255px'});
	ce('FORM', oDiv, {id: 'navBarForm', innerHTML: '<img src="/img/icons/inet.gif" style="position: absolute; margin: 3px 0px 0px 4px;"/><input type="text" class="navBarInput" align="absmiddle" value=""/><input type="submit" class="std_button" align="absmiddle" value="OK"/>'})
	oDiv = ce('DIV', oDiv, {id: 'enterToolbar'});
	if (!SProfile.user.name)
	{
		ce('IMG', oDiv, {src: icons+'register.gif', title: Locale['Registration'], onclick: function() {Startup.DrawRegisterForm()}, className: 'href'});
		ce('IMG', oDiv, {src: icons+'login.gif', title: Locale['Enter'], onclick: function() {Startup.DrawLoginForm()}, className: 'href'});
	}
	else
	{
		ce('IMG', oDiv, {src: icons+'logined.gif', title: SProfile.user.name, onclick: function() {Settings.Show(); Settings.RunMenuItem(Settings.Password, 'ChangePassword')}, className: 'href'});
		ce('IMG', oDiv, {src: icons+'logoff.gif', title: Locale['Exit'], onclick: function() {Startup.Logout()}, className: 'href'});
	}
	this.drawLangMenu();
	NavBar = new __NavBar('navBarForm');
}

__Desktop.prototype.ResizeMain = function()
{
	var size = this.cLeft.getHeight() - $('cMainTabsContainer').getHeight() - $('cMainContent').getOuterHeight();
	$('cMainContent').applyStyle({ height: size });
}

__Desktop.prototype.SetPanelSize = function(cName, size)
{
	size = parseInt(size);
	switch (cName)
	{
		case 'cLeft':
			this.cLeft.applyStyle({ width: size });
			this.cLeftResize.applyStyle({ left: size });
			this.cMain.applyStyle( { left: size + this.cLeftResize.getWidth(), width: this.BodyWidth - 2*this.cLeftResize.getWidth() - this.cLeft.getWidth() - this.cRight.getWidth() } );
			break;
		case 'cRight':
			this.cRight.applyStyle({ left: this.BodyWidth - size, width: size });
			this.cRightResize.applyStyle({ left: this.BodyWidth - size - this.cRightResize.getWidth() });
			this.cMain.applyStyle({ left: this.cLeft.getWidth() +  this.cLeftResize.getWidth(), width: this.BodyWidth - 2*this.cLeftResize.getWidth() - this.cLeft.getWidth() - this.cRight.getWidth() });
			break;
		case 'cUp':
//			this.cUp.applyStyle({ height: size - this.cUp.getOuterHeight()});
//			this.cUpResize.applyStyle({ top: size });
			var MainHeight = this.BodyHeight - this.cUpResize.getHeight() - size - this.cUp.getOuterHeight();
			var MainTop = this.cUpResize.getHeight() + size;
			this.cLeft.applyStyle({ height: MainHeight });
			this.cRight.applyStyle({ height: MainHeight });
			this.cLeftResize.applyStyle({ height: MainHeight });
			this.cRightResize.applyStyle({ height: MainHeight });
			this.cMain.applyStyle({ height: MainHeight });
/*
			this.cLeft.applyStyle({ top: MainTop, height: MainHeight });
			this.cRight.applyStyle({ top: MainTop, height: MainHeight });
			this.cLeftResize.applyStyle({ top: MainTop, height: MainHeight });
			this.cRightResize.applyStyle({ top: MainTop, height: MainHeight });
			this.cMain.applyStyle({ top: MainTop, height: MainHeight });
*/		
			$('cLeftPanel').applyStyle({ height: MainHeight });
			$('cLeftTabs').applyStyle({ height: MainHeight });
			$('cLeftContent').applyStyle({ height: MainHeight - $('cLeftContent').getOuterHeight()});
			$('cRightPanel').applyStyle({ height: MainHeight });
			$('cRightTabs').applyStyle({ height: MainHeight });
			$('cRightContent').applyStyle({ height: MainHeight - $('cRightContent').getOuterHeight()});
			break;
	}
	this.ResizeMain();
}

__Desktop.prototype.AddCreateTabControl = function(cName)
{
	var content = cName == 'cLeft' || cName == 'cRight' ? '<img src="'+ this.templates[Skin].addTabIcon.src +'" class="Controls" title="'+ this.lang['AddBookmark'] +'"/>' : '<img src="'+ this.templates[Skin].addTabIcon.src +'" class="Controls" title="'+ this.lang['AddBookmark'] +'"/>';
	this.State[cName].add = ce('li', cName+'Tabs', { id: cName+'.'+'AddTab', className: 'NewTabControl', innerHTML: content });
	this.State[cName].add.observe('click', this.AddTabByClick.bindAsEventListener(this));
}

__Desktop.prototype.TogglePanel = function(event)
{
	var cName = typeof event == 'string' ? event : Event.element(event).id.split('.')[1];
	if(this.State[cName].toggle)
	{
		$(cName+'Content').show();
		this.SetPanelSize(cName, this.State[cName].BackupSize);
		$('Toggle.'+cName).src = this.templates[Skin].rollTabIcon.src;
	}
	else
	{
		var size = $(cName+'TabsContainer').getWidth();
		this.State[cName].BackupSize = this[cName].getWidth();
		$(cName+'Content').hide();
		this.SetPanelSize(cName, size);
		$('Toggle.'+cName).src = this.templates[Skin].rollTabIcon.src;
	}
	this.State[cName].toggle = !this.State[cName].toggle;
	Profile.update('container', 'update', { cName: cName }, { toggle:  this.State[cName].toggle } );
	if(!Profile.ApplyProfileInProgress)
		this.OnResizeWindow();
}

__Desktop.prototype.SetActiveByID = function(cName, TabID)
{
	if (!TabID || !$(cName+'.Tab.'+TabID))
	{
		var Nodes = $(cName+'Tabs').childNodes;
		if (Nodes.length == 1)
		{
			this.NewTab(cName);
			var Nodes = $(cName+'Tabs').childNodes;
		}
		var Item = (cName != 'cMain') ? Nodes[1] : Nodes[0];
		var Item = $(Item);
	}
	else
		var Item = $(cName+'.Tab.'+TabID);
	this.SetActiveByItem(Item);
}

__Desktop.prototype.SetActive = function(event)
{
	this.SetActiveByItem(Event.findElement(event, 'li'));
	var cName = Event.findElement(event, 'li').id.split('.')[0];
	if((cName == 'cLeft' || cName == 'cRight') && this.State[cName].toggle)
	{
		this.TogglePanel(cName);
	}
}

__Desktop.prototype.SetActiveByItem = function(element)
{
	if(!element)
		return;
	if(this.CurrentTab) this.TabOptions();
	var item = element.id.split('.')
	var cName = item[0];
	var id = item[2];
	if(element == this.State[cName].current)
		return;
	if(this.State[cName].current)
	{
		this.State[cName].current.className = '';
		var item = this.State[cName].current.id.split('.')
		$('Content.'+item[0]+'.'+item[2]).hide();
	}
	element.className = 'Active';
	$('Content.'+cName+'.'+id).show();
	this.State[cName].current = element;
	var size = $('Content.'+cName+'.'+id).parentNode.getHeight() - $('Content.'+cName+'.'+id).parentNode.getOuterHeight();
	$('Content.'+cName+'.'+id).applyStyle({ height: size });
	if(this.State[cName].content[id].url)
	{
		NavBar.setUrl(this.State[cName].content[id].url);
		$('Browser.'+id).parentNode.parentNode.parentNode.applyStyle({ overflow: 'hidden'});
		$('Browser.'+id).applyStyle({ height: size });
		if(this.Scroll && this.Scroll['Browser.'+id])
		{
			window.frames['Browser.'+id].scrollTo(this.Scroll['Browser.'+id][0],this.Scroll['Browser.'+id][1]);
		}
	}
	Profile.update('container', 'update', { cName: cName }, { current: id } );
}

__Desktop.prototype.AddTabByClick = function(event)
{
	var cName = Event.findElement(event, 'li').id.split('.')[0];
	this.NewTab(cName);
	if((cName == 'cLeft' || cName == 'cRight') && this.State[cName].toggle)
	{
		this.TogglePanel(cName);
	}
}

__Desktop.prototype.scrollTo = function(item)
{
	if (item.variables.scroll)
	{
		if (!this.Scroll) this.Scroll = {}
		this.Scroll[item.event.item.id] = [item.variables.scroll[0], item.variables.scroll[1]];
		//window.frames[item.event.item.id].scrollTo(parseInt(item.variables.scroll[0]),parseInt(item.variables.scroll[1]));
		frames[item.event.item.id].scrollTo(item.variables.scroll[0],item.variables.scroll[1]);
	}
}

__Desktop.prototype.setMainTabTitle = function(tabId, title)
{
//console.info('tabTitle_'+tabId);
	var span = document.getElementById('tabTitle_'+tabId);
	if(title.length < 18)
		span.innerHTML = title;
	else
		span.innerHTML = title.substr(0, 18) +'...';
}

__Desktop.prototype.NewTab = function(cName, title, icon, TabID, url, update, TempTab, waitLoadUrl)
{
	if(!update)
		update = 0;
	if (!this.State[cName].content)
		this.State[cName].content = {};
	if(cName != 'cMain')
	{
		var cnt = 0;
		for(var i in this.State[cName].content)
		{
			cnt++;
		}
		if (cnt+1>10)
		{
			$(cName+'.AddTab').hide();
			return;
		}
		else
		{
			$(cName+'.AddTab').show();
		}
	}
	if(!this.State[cName].max)
		this.State[cName].max = 1;
	if(TabID)
	{
		if (TabID>this.State[cName].max) this.State[cName].max = TabID;
	}
	else
	{
		this.State[cName].max++;
		TabID = this.State[cName].max;
	}
	this.State[cName].content[TabID] = { content: ce('div', $(cName+'Content'), { className: 'ULContent', id: 'Content.'+cName+'.'+TabID } ).hide() };
	if (cName != 'cMain') this.ModulesContainer.AddContainer('Content.'+cName+'.'+TabID);
	var ul = this.State[cName].content[TabID].content;

	if (icon === '') var t = true; else t = false;
	icon = icon ? icon : this.DefaultIcon;
	title = title ? title : this.lang['Bookmark'] +' '+ TabID;
	var content = cName == 'cMain' ? '<NOBR><img src="/img/ticons/'+icon+'.gif" align="absmiddle"><span id="tabTitle_'+TabID+'"></span><img class="CloseRed close" src="/img/close-red.gif" id="CloseTab.'+TabID+'" title="'+ Locale['ToClose'] +'"/></NOBR>' : '<img src="/img/ticons/'+icon+'.gif" title="'+ title +'">';
	var Tab = ce('li', null, { id: cName+'.Tab.'+TabID, innerHTML: content});

	if (cName != 'cMain')
	{
		Tab.onmouseout = function() {
			Desktop.SelectedTabID = this.id;
		}
	}

	var img = Tab.getElementsByTagName('img');
	if(img[1])
	{
		var cl = img[1];
		cl.onclick = function(e)
		{
//			Event.stop(e);
			var id = this.id.split('.');
			Desktop.DeleteTabByID('cMain', id[1]);
		}
	}
	if(t)
	{
		$(Tab.getElementsByTagName('img')[0]).hide();
	}

	$(cName+'Tabs').insertBefore(Tab, this.State[cName].add);
	if(cName == 'cMain')
		this.setMainTabTitle(TabID, title);
	Tab.observe('click', this.SetActive.bindAsEventListener(this));
	Tab.oncontextmenu = this.TabOptions.bindAsEventListener(this);
	Profile.update('tab', 'create', {cName: cName, TabID: TabID }, { name: title, icon: icon, url : url });
	if (cName == 'cMain') this.ResizeMain();
	if (url && this.URLPresent)
	{
		this.State[cName].content[TabID].url = url;
		var ul = this.State[cName].content[TabID].content;
		url = escape(url);
		if(!waitLoadUrl)
		{
		   ul.update('<li><iframe frameborder="0" src="/proxy.php?prxy_url='+url+'" id="Browser.'+TabID+'" name="Browser.'+TabID+'" style="width: 100%;"></iframe></li>');
		   Update.request('Startup', 'scroll', 'GetScroll', { id: this.id }, { url: url });
			/*ul.update('<li><div id="BrowserError.'+TabID+'" style="display: none; font-weight: bold; text-align: center;"></div><iframe frameborder="0"  id="Browser.'+TabID+'" name="Browser.'+TabID+'"></iframe></li>');
			var options = {url: url	, TabID: TabID}
			Update.request('Startup', 'startup', 'testUrl', {id: this.id}, options, true);
			*/
		}
		else
		{
			ul.update('<li><div id="tabClickToLoad.'+TabID+'" align="center" style="padding-top: 100px;"><div class="Dialog" style="width: 200px; display: block; position: relative;"><h4 style="margin: 7px 0px 5px;">'+ Locale['ToLoadSites'] +'</h4><div class="content" align="center" style="margin: 0px 5px;"><input type="button" value="'+ Locale['OK'] +'" class="std_button" style="margin: 12px 0px;"/></div></div></div><div id="BrowserError.'+TabID+'" style="display: none; text-align: center; font-weight: bold;"></div><iframe frameborder="0" src="" id="Browser.'+TabID+'" name="Browser.'+TabID+'" style="display: none; width: 100%;"></iframe></li>');
			var t = document.getElementById('tabClickToLoad.'+TabID);
			t.onclick = loadUrlByClick;
			t.tid = TabID;
			t.url = url;
		}
		if(Prototype.Browser.IE)
		{
			setTimeout(function() {
				var url = $('Browser.'+TabID).src;
				Update.request('Startup', 'scroll', 'GetScroll', { id: 'Browser.'+TabID }, { url: url });
			}.bind(this),2000)
		}
		else
		{
			$('Browser.'+TabID).onload = function() {
				var url = this.src;
				Update.request('Startup', 'scroll', 'GetScroll', { id: this.id }, { url: url });
			};
		}

		if (update != 0 && update != 'undefined')
		{
			this.State[cName].content[TabID].update = update;
			this.State[cName].content[TabID].timer = new PeriodicalExecuter(function() {
				var item = this.State[cName].content[TabID].content.getElementsByTagName('iframe');
				$('Browser.'+TabID).src = $('Browser.'+TabID).src;
			}.bind(this), update);
		}
	}
	if (!Profile.ApplyProfileInProgress) this.OnResizeWindow();
	var self = this;
	return(TabID);

	function loadUrlByClick()
	{
		if(!isEmpty(self.State['cMain'].content))
		{
			for(var i in self.State['cMain'].content)
			{
				if(self.State['cMain'].content[i].url)
				{
					de(document.getElementById('tabClickToLoad.'+i));
					document.getElementById('Browser.'+ i).style.display = '';
					document.getElementById('Browser.'+ i).src = '/proxy.php?prxy_url='+ self.State['cMain'].content[i].url;
					//var options = {url: self.State['cMain'].content[i].url, TabID: i};
					//Update.request('Startup', 'startup', 'testUrl', {id: this.id}, options, true);
				}
			}
		}
	}
}


__Desktop.prototype.GetCurrentTab = function(cName)
{
	var item = this.State[cName].current.id.split('.');
	return(item[2]);
}

__Desktop.prototype.DoStartResize = function(event)
{
	this.CurrentTarget = Event.element(event).id.replace(/Resize/,'');
	if(this.State[this.CurrentTarget].toggle || !Event.isLeftClick(event))
		return false;
	this.OnStopResize = this.DoStopResize.bindAsEventListener(this);
	this.OnDoResize = this.DoResize.bindAsEventListener(this);
	Event.observe(document, 'mouseup', this.OnStopResize);
	Event.observe(document, 'mousemove', this.OnDoResize);
	if(this.CurrentTarget == 'cLeft' || this.CurrentTarget == 'cRight')
		document.body.setStyle( {cursor : 'w-resize'} );
	else
		document.body.setStyle( { cursor: 'n-resize' });

	if(this.State.cMain.current)
	{
		$('Content.cMain.'+this.GetCurrentTab('cMain')).hide();
	}
	if(Modules)
	{
		for(var i in Modules)
		{
			if(typeof(Modules[i].Object.onStartResize) == 'function')
				Modules[i].Object.onStartResize();
		}
	}
	return(false);
}

__Desktop.prototype.DoResize = function(event)
{
	switch (this.CurrentTarget)
	{
		case 'cLeft':
			var size = Event.pointerX(event);
			if (size<this.DefaultWidth || size>this.DefaultWidth*2) return(false);
			break;
		case 'cRight':
			var size = this.BodyWidth - Event.pointerX(event);
			if (size<this.DefaultWidth || size>this.DefaultWidth*2) return(false);
			break;
		case 'cUp':
			var size = Event.pointerY(event);
			if (size<this.DefaultHeight || size>this.DefaultHeight*2) return(false);
			break;
	}
	this.SetPanelSize(this.CurrentTarget, size);
	return(false);
}

__Desktop.prototype.DoStopResize = function()
{
	var size = this.CurrentTarget == 'cUp' ? this.cUp.getHeight() : this[this.CurrentTarget].getWidth();
	Event.stopObserving(document, 'mousemove', this.OnDoResize);
	Event.stopObserving(document, 'mouseup', this.OnStopResize);
	document.body.applyStyle({ cursor: 'default'});
	$('Content.cMain.'+this.GetCurrentTab('cMain')).show();
	Profile.update('container', 'update', { cName: this.CurrentTarget }, { size:  size } );
	this.CurrentTarget = null;
	if (Modules)
	{
		for (var i in Modules)
		{
			if(typeof(Modules[i].Object.onStopResize) == 'function')
				Modules[i].Object.onStopResize();
		}
	}
	return(false);
}

__Desktop.prototype.RenameTab = function(cName, TabID, title)
{
	if(!title)
		return;
	this.setMainTabTitle(TabID, title);
	$(cName+'.Tab.'+TabID).getElementsByTagName('img')[0].title = title;
	this.TabOptions();
	Profile.update('tab', 'update', { cName: cName, TabID: TabID}, { name: title});
}

__Desktop.prototype.TabOptions = function(event)
{
	if(!event || Event.element(event).id == 'TabOptionsCloseIcon')
	{
		if(this.TabOptionsLayer)
			this.TabOptionsLayer.hide();
		this.CurrentTab = null;
		return(false);
	}
	else
	{
		var Tab = Event.findElement(event, 'li');
		this.CurrentTab = Tab;
	}
	if(!this.TabOptionsLayer)
	{
		this.TabOptionsLayer = ce('div', document.body, { id: 'TabOptions', innerHTML:
			'<img id="TabOptionsCloseIcon" class="CloseIcon" src="/img/actions/close.gif" title="'+ this.lang['CloseOptions'] +'"/><h1>'+ this.lang['TabOptions'] +'</h1><p><input type="text" id="TabOptionsLayer.Name"><input type="button" value="'+ Locale['OK'] +'" id="TabOptionsLayer.Button"></p>'}, 
			{ position: 'absolute' }).hide();
		var IconGroup = HList.Create(2,null, this.lang['Icon']);
		this.TabOptionsLayer.appendChild(IconGroup.Main);
		IconGroup.Content.applyStyle({textAlign: 'center' });
		for(var i in Options.Desktop.Tab.Icons)
		{
			var img = ce('img', IconGroup.Content, { src: '/img/ticons/'+Options.Desktop.Tab.Icons[i], alt: i });
			img.observe('click', function(event) {
				var img = this.CurrentTab.getElementsByTagName('img');
				img[0].src = Event.element(event).src;
				$(img[0]).show();
				var item = this.CurrentTab.id.split('.');
				Profile.update('tab', 'update', { cName: item[0], TabID: item[2] }, { icon: Event.element(event).alt } );
				this.TabOptions();
			}.bindAsEventListener(this));
		}
		this.TabOptionsLayer.appendChild(HList.Create(3,null, this.lang['RemoveIcon'], null, function(event) {
			var img = this.CurrentTab.getElementsByTagName('img');
			$(img[0]).hide();
			var item = this.CurrentTab.id.split('.');
			Profile.update('tab', 'update', { cName: item[0], TabID: item[2] }, { icon: '' } );
			this.TabOptions();
		}.bindAsEventListener(this)).Main);

		var IconGroup = HList.Create(5,null, this.lang['RemoveTab'], null, function() {
			var item = this.CurrentTab.id.split('.');
			this.DeleteTabByID(item[0], item[2]);
		}.bind(this));
		this.TabOptionsLayer.appendChild(IconGroup.Main);

		var ScrollControl = HList.Create(15,null, this.lang['RememberScrollPos'], null, function() {
			var item = this.CurrentTab.id.split('.');
			var url = $F('TabOptionsLayer.URL');
			var iframe = $('Browser.'+item[2]);
			this.TabOptions();
			var top = (frames['Browser.'+item[2]].pageYOffset)?(frames['Browser.'+item[2]].pageYOffset):(frames['Browser.'+item[2]].document.documentElement)?frames['Browser.'+item[2]].document.documentElement.scrollTop:frames['Browser.'+item[2]].document.body.scrollTop;
			var left = (frames['Browser.'+item[2]].pageXOffset)?(frames['Browser.'+item[2]].pageXOffset):(frames['Browser.'+item[2]].document.documentElement)?frames['Browser.'+item[2]].document.documentElement.scrollLeft:frames['Browser.'+item[2]].document.body.scrollLeft;
			top = top || window.frames['Browser.'+item[2]].document.body.scrollTop;
			left = left || window.frames['Browser.'+item[2]].document.body.scrollLeft;
			if(!this.Scroll)
				this.Scroll = {}
			this.Scroll['Browser.'+item[2]] = [left, top];
			Update.request('Startup', 'scroll', 'SetScroll', { id: 'Browser.'+item[2] }, { url: escape(url), scroll: [left, top]});
		}.bind(this));
		this.TabOptionsLayer.appendChild(ScrollControl.Main);
		var BrowserControl = HList.Create(4,null, this.lang['ViewURL']);
		this.TabOptionsLayer.appendChild(BrowserControl.Main);
		BrowserControl.Content.update('<input id="TabOptionsLayer.URL" type="text"><br>'+ this.lang['RefresEvery'] +' <select id="TabOptionsLayer.Update"><option value="0">--</option><option value="5">'+ this.lang.period['5sec'] +'</option><option value="10">'+ this.lang.period['10sec'] +'</option><option value="20">'+ this.lang.period['20sec'] +'</option><option value="60">'+ this.lang.period['1min'] +'</option><option value="300">'+ this.lang.period['5min'] +'</option><option value="600">'+ this.lang.period['10min'] +'</option><option value="3600">'+ this.lang.period['1hour'] +'</option></select> <input id="TabOptionsLayer.URLSubmit" type="button" class="button" value="'+ Locale['OK'] +'">');
		$('TabOptionsLayer.URLSubmit').observe('click', function() {
			var url = $F('TabOptionsLayer.URL');
			if (!(/http:\/\//).test(url)) url = 'http://'+url;
			var title = url;
			$('TabOptionsLayer.URL').value = url;
			var item = this.CurrentTab.id.split('.');
			var ul = this.State[item[0]].content[item[2]].content;
			this.State[item[0]].content[item[2]].url = url;
			ul.update('<li><iframe frameborder="0" src="/proxy.php?prxy_url='+url+'" id="Browser.'+item[2]+'" style="width: 100%;"></iframe></li>');
			/*
			ul.update('<li><div id="BrowserError.'+item[2]+'" style="display: none; font-weight: bold; text-align: center;"></div><iframe frameborder="0"  id="Browser.'+item[2]+'"></iframe></li>');
			var options = {url: url	, TabID: item[2]}
			Update.request('Startup', 'startup', 'testUrl', {id: this.id}, options, true);
			*/
			var size = $('cMainContent').getHeight() - $('cMainContent').getOuterHeight();
			$('Browser.'+item[2]).parentNode.parentNode.parentNode.applyStyle({ overflow: 'hidden'});
			$('Browser.'+item[2]).applyStyle({ height: size -4 });
			var update = $F('TabOptionsLayer.Update')*1;
			this.State[item[0]].content[item[2]].update = update;
			if (update != 0 && update != 'undefined') {
				this.State[item[0]].content[item[2]].timer = new PeriodicalExecuter(function() {
					$('Browser.'+item[2]).src = $('Browser.'+item[2]).src;
				}.bind(this), update);
			}
			this.RenameTab('cMain', item[2], title);
			this.SetActiveByID('cMain', item[2]);
			Profile.update('tab', 'update', { cName: item[0], TabID: item[2] }, { url: url, update: update } );
			this.TabOptions();
		}.bind(this));

		$('TabOptionsCloseIcon').observe('click', this.TabOptions.bindAsEventListener(this));
		$('TabOptionsLayer.Button').onclick = function() {
			var value = $F('TabOptionsLayer.Name');
			var item = this.CurrentTab.id.split('.');
			this.RenameTab(item[0], item[2], value);
		}.bind(this);
	}

	var offset = Position.cumulativeOffset(Tab);
	var height = Tab.getHeight();
	this.TabOptionsLayer.applyStyle({ left: offset[0], top: offset[1] + height - 1});
	var item = this.CurrentTab.id.split('.');
	var url = this.State[item[0]].content[item[2]].url ? this.State[item[0]].content[item[2]].url : '';
	$('TabOptionsLayer.URL').value = url;

	var update =  this.State[item[0]].content[item[2]].update ? this.State[item[0]].content[item[2]].update : 0;
	$('TabOptionsLayer.Update').value = update;
	if(item[0] == 'cMain')
	{
		$('HList.3').show();
		$('HList.4').show();
		if($F('TabOptionsLayer.URL') || this.State.cMain.content[item[2]].url)
		{
			$('HList.15').show();
		}
		else
		{
			$('HList.15').hide();
		}
	}
	else
	{
		$('HList.3').hide();
		$('HList.4').hide();
		$('HList.15').hide();
	}

	var span = $(item[0]+'.Tab.'+item[2]).getElementsByTagName('span');
	if(span.length)
		var title = span[0].innerHTML;
	else
	{
		var img = $(item[0]+'.Tab.'+item[2]).getElementsByTagName('img');
		var title = img[0].alt;
	}
	$('TabOptionsLayer.Name').value = title;
	this.TabOptionsLayer.show();
	return(false);
}

__Desktop.prototype.DeleteTabByID = function(cName, TabID)
{
	var item = $(cName+'.Tab.'+TabID);
	var size = 0;
	for(var i in this.State[cName].content)
		size++;
	if(size == 1)
	{
		this.TabOptions();
		window.alert(this.lang['LastTabCantDel']);
		return;
	}

	if(this.State[cName].current.id == cName+'.Tab.'+TabID)
		this.SetActiveByItem((!item.nextSibling.id.match(/AddTab/)) ? item.nextSibling : item.previousSibling);
	if(this.State[cName].content[TabID].timer)
		this.State[cName].content[TabID].timer.stop();
	this.State[cName].content[TabID].content.parentNode.removeChild(this.State[cName].content[TabID].content);
	de(item);
	delete this.State[cName].content[TabID];
	var del_modules = [];

	this.TabOptions();
	if (cName == 'cMain') this.ResizeMain();
	Profile.update('tab', 'delete', { cName: cName, TabID: TabID} );
	if(cName != 'cMain')
	{
		delete this.ModulesContainer.Containers['Content.'+cName+'.'+TabID];
		for(var i in Modules)
		{
			if(Modules[i].State.TabID == TabID && Modules[i].State.cName == cName)
			{
				delete Modules[i];
				delete this.ModulesContainer.Items['Module.'+i];
			}
		}

		var cnt = 0;
		for (var i in this.State[cName].content)
		{
			cnt++;
		}
		if (cnt+1>10)
		{
			$(cName+'.AddTab').hide();
			return;
		}
		else
		{
			$(cName+'.AddTab').show();
		}
	}

	for(var i in Modules)
	{
		mActionsInspector.delActionsByTab(i, TabID);
		if(Modules[i].Object.workspaceId && Modules[i].Object.workspaceId == TabID && Modules[i].Object.onTabDelete)
			Modules[i].Object.onTabDelete();
	}
}

__Desktop.prototype.initTabFromModule = function(module_id, title)
{
	var m = Modules[module_id].Object;
	if(!title)
		var title = m.lang.title
	if(!m.workspaceId || !Desktop.State.cMain.content[m.workspaceId])
	{
		m.workspaceId = Desktop.NewTab('cMain', title, 'inet', null, null, null, true);
	}

	if(!m.workspace)
	{
		var t = Desktop.State.cMain.content[m.workspaceId].content;
		t.style.overflow = 'auto';
		t.innerHTML = '';
		m.workspace = ce('LI', t);
	}
	m.workspace.innerHTML = '';
	m.ModuleName.onclick = function()
	{
		if(m.workspace)
			Desktop.SetActiveByID('cMain', m.workspaceId);
	}

}
