	// События
var EVENT = {
		// Добавляем
	Add: function(el, evname, fn)
	{
		if(el.attachEvent) // IE
			el.attachEvent('on' + evname, fn);
		else if(el.addEventListener) // Gecko / W3C
			el.addEventListener(evname, fn, false);
	},
		// Удаляем
	Del: function(el, evname, fn)
	{
		if(el.detachEvent) // IE
			el.detachEvent('on' + evname, fn);
		else if(el.removeEventListener) // Gecko / W3C
			el.removeEventListener(evname, fn, false);
	}
}




var PAGE = {	BrowserList: [
		{
			string: navigator.userAgent,
			subString: 'Chrome',
			identity: 'Chrome'
		},
		{
			string: navigator.vendor,
			subString: 'Apple',
			identity: 'Safari',
			versionSearch: 'Version'
		},
		{
			prop: window.opera,
			identity: 'Opera'
		},
		{
			string: navigator.vendor,
			subString: 'KDE',
			identity: 'Konqueror'
		},
		{
			string: navigator.userAgent,
			subString: 'Firefox',
			identity: 'FF'
		},
		{
			string: navigator.userAgent,
			subString: 'MSIE',
			identity: 'IE',
			versionSearch: 'MSIE'
		},
		{
			string: navigator.userAgent,
			subString: 'Gecko',
			identity: 'Mozilla',
			versionSearch: 'rv'
		},
		{
			string: navigator.userAgent,
			subString: 'Mozilla',
			identity: 'Netscape',
			versionSearch: 'Mozilla'
		}
	],
	OSList : [
		{
			string: navigator.platform,
			subString: 'Win',
			identity: 'Windows'
		},
		{
			string: navigator.platform,
			subString: 'Mac',
			identity: 'Mac'
		},
		{
			string: navigator.userAgent,
			subString: 'iPhone',
			identity: 'iPhone/iPod'
	    },
		{
			string: navigator.platform,
			subString: 'Linux',
			identity: 'Linux'
		}
	],
	BRWInfo : false,
		// Определяем Браузер, версию и ОС	BRW: function () {		if (!this.BRWInfo) {			res = {};
			res['NAME'] = this.BRWString(this.BrowserList) || 'An unknown browser';
			res['VER'] = this.BRWVersion(navigator.userAgent)
				|| this.BRWVersion(navigator.appVersion)
				|| 'an unknown version';
			res['OS'] = this.BRWString(this.OSList) || 'an unknown OS';

			this.BRWInfo = res;
		} else {			res = this.BRWInfo		}

		return res;
	},
	BRWString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	BRWVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},

	IsIE: function() {
		BR = this.BRW();
		if (BR['NAME'] == 'IE')
			return true;
		else
			return false;
	},
	IsFF: function() {
		BR = this.BRW();
		if (BR['NAME'] == 'FF')
			return true;
		else
			return false;
	},





	WinInnerSize: function(Doc) {
		var width, height;
		if (!Doc)
			Doc = document;

		if (self.innerHeight) {
			width = self.innerWidth;
			height = self.innerHeight;
		}
		else if (Doc.documentElement && Doc.documentElement.clientHeight) {
			width = Doc.documentElement.clientWidth;
			height = Doc.documentElement.clientHeight;
		}
		else if (Doc.body) {
			width = Doc.body.clientWidth;
			height = Doc.body.clientHeight;
		}
		return {innerWidth : width, innerHeight : height};
	},

	WinScrollPos: function(Doc) {
		var left, top;
		if (!Doc)
			Doc = document;

		if (self.pageYOffset) {
			left = self.pageXOffset;
			top = self.pageYOffset;
		}
		else if (Doc.documentElement && Doc.documentElement.scrollTop) {
			left = document.documentElement.scrollLeft;
			top = document.documentElement.scrollTop;
		}
		else if (Doc.body) {
			left = Doc.body.scrollLeft;
			top = Doc.body.scrollTop;
		}
		return {scrollLeft : left, scrollTop : top};
	},

	WinScrollSize: function(Doc)
	{
		var width, height;
		if (!Doc)
			Doc = document;

		if ( (Doc.compatMode && Doc.compatMode == 'CSS1Compat')) {
			width = Doc.documentElement.scrollWidth;
			height = Doc.documentElement.scrollHeight;
		} else {
			if (Doc.body.scrollHeight > Doc.body.offsetHeight)
				height = Doc.body.scrollHeight;
			else
				height = Doc.body.offsetHeight;

			if (Doc.body.scrollWidth > Doc.body.offsetWidth ||
				(Doc.compatMode && Doc.compatMode == 'BackCompat') ||
				(Doc.documentElement && !Doc.documentElement.clientWidth)
			)
				width = Doc.body.scrollWidth;
			else
				width = Doc.body.offsetWidth;
		}
		return {scrollWidth : width, scrollHeight : height};
	},



		// Возврашает параметры окна браузера
	WinSize: function()
	{
		var innerSize = this.WinInnerSize();
		var scrollPos = this.WinScrollPos();
		var scrollSize = this.WinScrollSize();

		return  {
			innerWidth : innerSize.innerWidth, innerHeight : innerSize.innerHeight,
			scrollLeft : scrollPos.scrollLeft, scrollTop : scrollPos.scrollTop,
			scrollWidth : scrollSize.scrollWidth, scrollHeight : scrollSize.scrollHeight
		};
	},







		// Отменяет все выделения
	remSelect: function() {		if (window.getSelection) {			window.getSelection().removeAllRanges();
		} else if (document.selection && document.selection.clear)
			document.selection.clear();	},


		// Координаты мышки
	mouseX: function(e, noScroll) {		if (!e)
			e = event;

		if (noScroll)
			return e.clientX;
		else
			return e.clientX + document.body.scrollLeft;
	},
	mouseY: function(e, noScroll) {		if (!e)
			e = event;

		if (noScroll)
			return e.clientY;
		else
			return e.clientY + document.body.scrollTop;
	},













		// Создает объект на весь сайта для затемнения
	BlackOut: function(opacity, zIndex, bgcolor, bgimage)
	{
		if (getElemByID('black_out'))
			this.CloseBlackOut();

		if (!opacity)
			opacity = 0.5;

		if (!zIndex)
			zIndex = 997;

		if (!bgcolor)
			bgcolor = '#000000';



		var pageSize = PAGE.WinSize();

		obBlackOut = document.createElement('DIV');
		obBlackOut.id = 'black_out';
		obBlackOut.style.zIndex = zIndex;
		obBlackOut.style.position = 'absolute';

		obBlackOut.style.width = pageSize['scrollWidth']+'px';
		obBlackOut.style.height = pageSize['scrollHeight']+'px';

		obBlackOut.style.left = 0;
		obBlackOut.style.top = 0;

		if (bgimage) {
			obBlackOut.style.background = 'url(' + bgimage + ')';
		} else {
			obBlackOut.style.background = bgcolor;
			obBlackOut.opacity(opacity);
		}
		document.body.appendChild(obBlackOut);
	},


	CloseBlackOut: function()
	{
		var obBlackOut = getElemByID('black_out');
		if (obBlackOut) {
			obBlackOut.parentNode.removeChild(obBlackOut);
		}
	}}


	// Возврашаем объект элемента по ID (для удобства)
function getElemByID(id) {	if (ob = document.getElementById(id))
		return ob;
	else
		return false;}


	// Подключаем JS файл
function include(SRC) {
	document.write('<script src="'+SRC+'"></script>');
}







function DialogWindow()
{

	var _this = this;
	this.floatDiv = null;
	this.smooth = '';
	this.x = this.y = 0;

	this.Open = function(data, smooth)
	{
		zIndex = 1000;

		var pageSize = PAGE.WinSize();




		obDialog = document.createElement("DIV");
		obDialog.id = "dialog_window";
		obDialog.style.zIndex = zIndex;
		obDialog.style.position = 'absolute';




		document.body.appendChild(obDialog);
		this.floatDiv = obDialog;


		if (smooth) {
			this.smooth = 0;
			if (PAGE.IsIE())
				{ obDialog.style.filter = "Alpha(opacity=" + 20 + ")"; }
			else
				{ obDialog.style.opacity = 0 / 100; }
			DialogWindow.smoothOpen();
		}



		obDialog.innerHTML = data;

		this.x = parseInt(pageSize["scrollTop"] + pageSize["innerHeight"]/3 - obDialog.offsetHeight/2);
		this.y = parseInt(pageSize["scrollLeft"] + pageSize["innerWidth"]/2 - obDialog.offsetWidth/2);

		if (this.x - pageSize["scrollTop"] <= 0)
			this.x = pageSize["scrollTop"];
		if (this.y - pageSize["scrollLeft"] <= 0)
			this.y = pageSize["scrollLeft"];

		obDialog.style.top = this.x+'px';
		obDialog.style.left = this.y+'px';



		EVENT.Add(document, "keypress", this.EscClose);

	},
		// Плавно отткрываем окно
	this.smoothOpen = function(f)
	{
		if (this.smooth <= 100) {
			this.smooth = this.smooth + 7;
			if (PAGE.IsIE())
				{ this.floatDiv.style.filter = "Alpha(opacity=" + this.smooth + ")"; }
			else
				{ this.floatDiv.style.opacity = this.smooth / 100; }
			setTimeout("DialogWindow.smoothOpen()", 1);
		} else {
			if (PAGE.IsIE())
				{ this.floatDiv.style.filter = ""; }
			else
				{ this.floatDiv.style.opacity = 100 / 100; }
			this.smooth = 100;
		}
	}


	this.Close = function(f)
	{			// Убираем затеменение
		PAGE.CloseBlackOut();

		if (getElemByID("dialog_window")) {
			var obDialog = getElemByID("dialog_window");
			obDialog.parentNode.removeChild(obDialog);
		}

		EVENT.Del(document, "keypress", this.EscClose);
	},

		// Закрываем при нажатии "Esc"
	this.EscClose = function()
	{		if(window.event.keyCode == 27) {
			if (DialogWindow.smooth == 100) {
				DialogWindow.smoothClose();
			} else {
				DialogWindow.Close();
			}
		}
	},
		// Плавно закрываем окно
	this.smoothClose = function(f)
	{			// Убираем затеменение
		PAGE.CloseBlackOut();


		if (this.smooth >= 0) {
			this.smooth = this.smooth - 7;
			if (PAGE.IsIE())
				{ this.floatDiv.style.filter = "Alpha(opacity=" + this.smooth + ")"; }
			else
				{ this.floatDiv.style.opacity = this.smooth / 100; }
			setTimeout("DialogWindow.smoothClose()", 1);
		} else {
			DialogWindow.Close();
		}
	}














	this.StartDrag = function(e, div)
	{
		if(!e)
			e = window.event;

		this.x = e.clientX + document.body.scrollLeft;
		this.y = e.clientY + document.body.scrollTop;




		EVENT.Add(document, "mousemove", this.GoDrag);

		document.onmouseup = this.StopDrag;
	},

	this.StopDrag = function()
	{
		if(document.body.releaseCapture)
			document.body.releaseCapture();


		document.onmouseup = null;
		EVENT.Del(document, "mousemove", _this.GoDrag);

	},

	this.GoDrag = function(e)
	{
		var x = e.clientX + document.body.scrollLeft;
		var y = e.clientY + document.body.scrollTop;

		if(_this.x == x && _this.y == y)
			return;



		_this.floatDiv.style.left = parseInt(_this.floatDiv.style.left) + (x - _this.x)+'px';
		_this.floatDiv.style.top = parseInt(_this.floatDiv.style.top) + (y - _this.y)+'px';


		if (window.getSelection)
			{ window.getSelection().removeAllRanges(); }
		else
			if (document.selection && document.selection.clear)
				document.selection.clear();


		_this.x = x;
		_this.y = y;
	}
}


var DialogWindow = new DialogWindow();










GOLR = false;
function lr (url)
{	PAGE.remSelect();	if (GOLR)
		return;


	if (!url)
		url = self.parent.location;
	self.parent.location = url;
	GOLR = true;}




function Effect()
{
	var $this = this;
	this.ob = '';			// Объект с которым мы производим эффект
	this.time = 0.2;		// Время которое доеться на выполнение эффектов
	this.css = {};			// Теги
	this.final = '';		// Запускаем функцию по окончанию эфектов
	this.startTime = false;	// Время старта

	this.start = function(ob, css, time) {
		if (!ob || !css)
			return;

		if (time)
			this.time = time;

		this.ob = ob;

			// Таймер в формате для дальнейших вичислений
		timer = this.time * 1000;

		for (var t in css) {
			var v = css[t];
			switch (t) {
				case 'width':   start = ob.offsetWidth;   break;
				case 'height':  start = ob.offsetWidth;   break;
				case 'left':    start = ob.X();			  break;
				case 'top':     start = ob.Y();			  break;
				case 'opacity':	start = ob.getOpacity();  break;

				default:
					continue;
				break;
			}

			this.css[t] = {
				START:parseFloat(start),
				STOP:v,
				STEP:(v - start) / timer
			};
		}

		if (this.css['width'] || this.css['height'])
			ob.style.overflow = 'hidden';

		this.startTime = new Date().getTime();
		setTimeout(this.process, 0);
	},

	this.process = function(ob) {
		endTime = $this.startTime + ($this.time * 1000);
		realTime = new Date().getTime();

			// Если время закончилось выстовляем значения STOP
		if (realTime > endTime) {

			for (var t in $this.css) {
				stop = $this.css[t]['STOP'];
				switch (t) {
					case 'width':   $this.ob.style.width = stop;	break;
					case 'height':  $this.ob.style.height = stop;	break;
					case 'left':    $this.ob.style.left = stop;		break;
					case 'top':     $this.ob.style.top = stop;		break;
					case 'opacity': $this.ob.opacity(stop);			break;
				}
			}

			if ($this.final)
				$this.final($this.ob)
		} else {
			passedTime = realTime - $this.startTime;	// Прошло времени

			for (var t in $this.css) {
				v = $this.css[t]['START'] + (passedTime * $this.css[t]['STEP']);
				switch (t) {
					case 'width':   $this.ob.style.width = v;	break;
					case 'height':  $this.ob.style.height = v;	break;
					case 'left':    $this.ob.style.left = v;	break;
					case 'top':     $this.ob.style.top = v;		break;
					case 'opacity': $this.ob.opacity(v);		break;
				}
			}
			setTimeout($this.process, 1);
		}
	}
}







function GetVar(ar)
{
	if (typeof(ar) != 'object')
		return ar;

	res = '{';

	first = true;

	for (var key in ar)
	{
		if(first) first = false;
		else res += ',';

		if (typeof(ar[key]) == 'object')
			res += "'" + key + "':" + GetVar(ar[key]);
		else
			res += "'" + key + "':'" + ar[key] + "'";
	}
	res += '}';
	return res;
}


function ech (mes, p) {
	if (typeof(mes) != 'object') {
		alert(mes)
		return ;
	}
	if (!p)
		p = '';

	ps = "       ";

	res = "{";

	first = true;

	for (var key in mes)
	{
		if(first) first = false;
		else res += ',';

		if (typeof(mes[key]) == 'object')
			res += "\n" + ps + p + "'" + key + "':" + ech(mes[key], p+ps);
		else
			res += "\n" + ps + p + "'" + key + "':'" + mes[key] + "'";
	}
	res += "\n" + p + "}";

	if (p)
		return res;
	else
		ech (res);

}
