function infoboxObject()
{
	this.id = 'ib';
	this.el = null;
	this.idTitle = 'ibTitle';
	this.elTitle = null;
	this.idContent = 'ibContent';
	this.elContent = null;
	this.originalClassName='';

	this.presets = new Array;
	this.contentArray = new Array;

	this.addPreset = function addPreset(key, obj)
	{
		this.presets[key] = obj;
	};

	this.initId = function initId(id, idTitle, idContent)
	{
		if (id) this.id = id;
		this.el = document.getElementById(this.id);
		this.originalClassName=this.el.className;
		if (idTitle) this.idTitle = idTitle;
		this.elTitle = document.getElementById(this.idTitle);
		if (idContent) this.idContent = idContent;
		this.elContent = document.getElementById(this.idContent);
	};
	this.isOn = function isOn(x) 	{x=x+''; if (x == '1' || x == 'true' || x == 't' || x == 'on') return true;};
	this.isOff = function isOff(x) 	{x=x+''; if (x == '0' || x == 'false' || x == 'f' || x == 'off') return true;};
	this.show = function show()		{if (this.el) this.el.style.display = 'block';};
	this.hide = function hide()		{if (this.el) this.el.style.display = 'none';};
	this.display = function display(f)	{if (this.el) if (f) this.el.style.display = 'block'; else this.el.style.display = 'none';};
	this.controls = function controls(f)
	{
		if (f && !core.nowPage.hideControls)
		{
			if ($('ib_bottom')) $('ib_bottom').style.display = 'none';
			if ($('ib_bottom_ctrls')) $('ib_bottom_ctrls').style.display = 'block';
			if ($('ib_close')) $('ib_close').style.display = 'block';
		}
		else
		{
			if ($('ib_bottom')) $('ib_bottom').style.display = 'block';
			if ($('ib_bottom_ctrls')) $('ib_bottom_ctrls').style.display = 'none';
			if ($('ib_close')) $('ib_close').style.display = 'none';
		}
	};
	this.dragndrop = function dragndrop(x) {if (x) xEnableDrag(this.id); else xDisableDrag(this.id);};
	this.top = function top(x)			{if (this.el) {this.el.style.bottom = ''; this.el.style.top = x;}};
	this.left = function left(x)		{if (this.el) {this.el.style.right = ''; this.el.style.left = x;}};
	this.bottom = function bottom(x)	{if (this.el) {this.el.style.top = ''; this.el.style.bottom = x;}};
	this.right = function right(x)		{if (this.el) {this.el.style.left = ''; this.el.style.right = x;}};
	this.width = function width(x)		{if (this.el) this.el.style.width = x;};
	this.height = function height(x)	{if (this.el) this.el.style.height = x;};
	this.title = function title(x)		{if (this.elTitle) this.elTitle.innerHTML = x;};
	this.content = function content()	{if (this.elContent) this.elContent.innerHTML = this.contentArray.join('');};
	function px(x) {if (x == parseInt(x)) return x+'px'; else return x;};
	this.init = function init(obj, keepContent)
	{
		if (!keepContent) this.contentArray = [];

		if (typeof (obj.ibClass) == "undefined"){
			this.el.className=this.originalClassName;
		}else{
			this.el.className=this.originalClassName+' '+obj.ibClass;
		}

		if (typeof obj.preset != "undefined")
		{
			var t = obj.preset.split(' ');
			for (var i = 0; i < t.length; i++){
				this.init(this.presets[t[i]], true);
			}
		}

		if (typeof obj.bottom != 'undefined') this.bottom(px(obj.bottom));
		if (typeof obj.right != 'undefined') this.right(px(obj.right));
		if (typeof obj.top != 'undefined') this.top(px(obj.top));
		if (typeof obj.left != 'undefined') this.left(px(obj.left));
		if (typeof obj.width != 'undefined') this.width(px(obj.width));
		if (typeof obj.height != 'undefined') this.height(px(obj.height));
		if (typeof obj.title != 'undefined') this.title(obj.title);

		if (obj['content-5']) this.contentArray[0] = obj['content-5'];
		if (obj['content-4']) this.contentArray[1] = obj['content-4'];
		if (obj['content-3']) this.contentArray[2] = obj['content-3'];
		if (obj['content-2']) this.contentArray[3] = obj['content-2'];
		if (obj['content-1']) this.contentArray[4] = obj['content-1'];
		if (obj.content) this.contentArray[5] = obj.content;
		if (obj['content+1']) this.contentArray[6] = obj['content+1'];
		if (obj['content+2']) this.contentArray[7] = obj['content+2'];
		if (obj['content+3']) this.contentArray[8] = obj['content+3'];
		if (obj['content+4']) this.contentArray[9] = obj['content+4'];
		if (obj['content+5']) this.contentArray[10] = obj['content+5'];

		if (obj.show) this.show();
		if (obj.hide) this.hide();
		if (typeof obj.display != 'undefined')
		{
			if (this.isOn(obj.display))	this.display(true);
			if (this.isOff(obj.display)) this.display(false);
		}
		if (typeof obj.controls != 'undefined')
		{
			if (this.isOn(obj.controls))
			{
				this.controls(false);
				this.progressBar();
				this.controls(true);
			}
			if (this.isOff(obj.controls))
				this.controls(false);
		}
		if (typeof obj.dragndrop != 'undefined')
		{
			if (this.isOn(obj.dragndrop))	this.dragndrop(true);
			if (this.isOff(obj.dragndrop)) this.dragndrop(false);
		}
		this.content();

	};

	this.progressBar = function progressBar()
	{
		var ib_pb = $('ib_pb');
		var inner2 = '';
		inner2 += '<table cellspacing="0" cellpadiing="0"><tr>';
		if ((core.now.posCountable+1) == 0)
			inner2 += '<td class="pb_bg_left"></td><td class="pb_bg_center"></td><td class="pb_bg_right"></td>';
		else if ((core.now.posCountable+1) == (core.now.lengthCountable))
			inner2 += '<td class="pb_fg_left"></td><td class="pb_fg_center"></td><td class="pb_fg_right"></td>';
		else
		{
			var w2 = ib_pb.offsetWidth - 9 - 9;
			var x2 = (w2/(core.now.lengthCountable))*(core.now.posCountable+1);
			inner2 += '<td class="pb_fg_left"></td><td class="pb_fg_center" style="width: '+(x2/w2*100)+'%;"></td><td class="pb_bg_center"></td><td class="pb_bg_right"></td>';
		}
		inner2 += '</tr></table>';
		if (ib_pb) ib_pb.innerHTML = inner2;
	};

	this.FIRST_START = function FIRST_START()
	{
		css.loadSS('infoboxStyle','system/infobox.css');

		var div = document.createElement('div');
		div.id = 'ib';
		div.className = 'ib';
		var inner = '<table cellspacing="0" cellpadding="0" class="ib_top"><tr><td class="ib_left_top"></td><td class="ib_center_top" id="ibTitle"><div class="ib_close" id="ib_close"><a href="javascript:// Выйти из раздела" onclick="core.view(\'toc\');"><img style="position:absolute; top:5px" src="img/ib/ib_close.gif" title="Выйти из раздела" /></a></div></td><td class="ib_right_top"></td></tr></table>'+
'<table cellspacing="0" cellpadding="0" class="ib_center"><tr><td class="ib_left"></td><td class="ib_content" id="ibContent"></td><td class="ib_right"></td></tr></table>'+
'<table cellspacing="0" cellpadding="0" class="ib_bottom" id="ib_bottom"><tr><td class="ib_left_bottom"></td><td class="ib_center_bottom"></td><td class="ib_right_bottom"></td></tr></table>'+
'<table cellspacing="0" cellpadding="0" class="ib_bottom" id="ib_bottom_ctrls" style="display:none;">'+
	'<tr>'+
		'<td class="ib_left_bottom_ctrls"></td>'+
		'<td class="ib_center_bottom_ctrls"><img src="img/controls/first.gif" id="ib_ctrl_first" onclick="core.first();" alt="" title="На первую страницу" class="ib_ctrl ib_first" /></td>'+
		'<td class="ib_center_bottom_ctrls"><img src="img/controls/prev.gif" id="ib_ctrl_prev" onclick="core.prev();" alt="" title="На предыдущую страницу" class="ib_ctrl ib_prev" /></td>'+
		'<td class="ib_center_bottom_ctrls_full"><div id="ib_pb"></div></td>'+
		'<td class="ib_center_bottom_ctrls"><img src="img/controls/next.gif" id="ib_ctrl_next" onclick="core.next();" alt="" title="На следущую страницу" class="ib_ctrl ib_next" /></td>'+
		'<td class="ib_center_bottom_ctrls"><img src="img/controls/last.gif" id="ib_ctrl_last" onclick="core.last();" alt="" title="На последнюю страницу" class="ib_ctrl ib_last" /></td>'+
		'<td class="ib_right_bottom_ctrls"></td>'+
	'</tr>'+
'</table>';
		div.innerHTML = inner;
		document.body.appendChild(div);
		this.ctrlImages('ib_ctrl_first', 'img/controls/first.gif', 'img/controls/first_click.gif', 'img/controls/first_over.gif');
		this.ctrlImages('ib_ctrl_last', 'img/controls/last.gif', 'img/controls/last_click.gif', 'img/controls/last_over.gif');
		this.ctrlImages('ib_ctrl_prev', 'img/controls/prev.gif', 'img/controls/prev_click.gif', 'img/controls/prev_over.gif');
		this.ctrlImages('ib_ctrl_next', 'img/controls/next.gif', 'img/controls/next_click.gif', 'img/controls/next_over.gif');

        //Подсказка с номером страницы
		var divGoTo = document.createElement('div');
		divGoTo.id = 'infoboxPageShow';
		divGoTo.style.display = 'none';
		divGoTo.className = 'infoboxPageShow';
		divGoTo.innerHTML = '<div class="begin"></div><div id="infoboxPageShowContent" class="infoboxPageShowContent"></div><div class="end"></div>';
		document.body.appendChild(divGoTo);

	  	events.add('ib_pb', 'click', infobox.infoboxGoTo);
		events.add('ib_pb', 'mouseover', infobox.infoboxShoGoToPage);
		events.add('ib_pb', 'mousemove', infobox.infoboxShoGoToPage);
		events.add('ib_pb', 'mouseout', infobox.infoboxHideGoToPage);
		events.add('ib_pb', 'mouseup', infobox.infoboxHideGoToPage);
	};

	this.ctrlImages = function ctrlImages(ele, normal, click, over)
	{
		events.add(ele, 'mouseover', function(){$(ele).src=over;}, false);
		events.add(ele, 'mouseout', function(){$(ele).src=normal;}, false);
		events.add(ele, 'mousedown', function(){$(ele).src=click;}, false);
		events.add(ele, 'mouseup', function(){$(ele).src=over;}, false);
	};

	this.infoboxGoTo = function infoboxGoTo(ev)
	{
		ev = new xEvent(ev);
		var width = xWidth('ib_pb');
		var posEv = ev.pageX - xPageX('ib_pb');
		var length = core.now.lengthCountable;
		if (posEv >= 0 && posEv <= width)
		{
			var pos = Math.floor(posEv * length/width);
			if (pos < 0) pos = 0;
			if (pos >= length) pos = length-1;
			(core.now.pos != pos)? core.view(core.now.id, pos): '';
		};
	};
	this.infoboxShoGoToPage = function infoboxShoGoToPage(ev)
	{
		//Заглушка для 6 IE
		if(navigator.userAgent.indexOf('MSIE 6.0') == 25)
			return;
		ev = new xEvent(ev);
		var re = /(\d+)px/;
		var width = xWidth('ib_pb');
		var posEv = ev.pageX - xPageX('ib_pb');
		var length = core.now.lengthCountable;
		if (posEv >= 0 && posEv <= width)
		{
			var pos = Math.floor(posEv * length/width);
			if (pos < 0) pos = 0;
			if (pos >= length) pos = length-1;
			$('infoboxPageShow').style.left = (ev.pageX - 30)+'px';
			$('infoboxPageShow').style.top = (ev.pageY - (ev.pageY - xPageY('ib_pb'))-23) + 'px';
            $('infoboxPageShow').style.display = '';
            $('infoboxPageShowContent').innerHTML = 'Стр. '+(pos+1)+'';
		}
	};
	this.infoboxHideGoToPage = function infoboxHideGoToPage()
	{
		$('infoboxPageShow').style.display = 'none';
	};
}

