	/*
		Hybrid Library v1.2.1
        © 2010 Алексей Забродин
	*/
	
	/* Классика */
	function $(a, b)
	{
		try
		{
			if (typeof(a) == 'string')
			{
				return document.getElementById(a);
			}
			else
			{
				return a.getElementsByTagName(b);
			}
		}
		catch(e){}
	}
	
	/* Инструменты */
	var Tools = {
		hide: function()
		{
			this.each(arguments, function()
			{
				this.style.display = 'none';
			});
		},
		show: function()
		{
			this.each(arguments, function()
			{
				this.style.display = '';
			});
		},
		style: function(e, s)
		{
    		for (var i in s)
    		{
        		e.style[i] = s[i];
    		}
		},
		each: function(e, f)
		{
			for (var i = 0; i < e.length; i++)
			{
				f.call(e[i], i);
			}
		},
		event: function(o, e, f)
		{
			if (o.attachEvent)
			{
				o.attachEvent('on' + e, f);
			}
			else
			{
				o.addEventListener(e, f, false);
			}
		},
		createElement: function(p, n)
		{
			return p.appendChild(document.createElement(n));
		},
		fade: function(m, e, o)
		{
			if (m == 'in')
			{
				var o = o || 0;
				
				if (o <= 10)
				{
					setTimeout(function()
					{
						e.style.opacity = (o / 10);
						Tools.fade('in', e, o + 1);
					}, 28);
				}
			}
			if (m == 'out')
			{
				if (o == null) o = 10;
				
				if (o >= 0)
				{
					setTimeout(function()
					{
						e.style.opacity = (o / 10);
						Tools.fade('out', e, o - 1);
					}, 28);
				}
			}
		},
		zebra: function(a, b, r1, r2, l)
		{
			this.each($(a, b), function(i)
			{
				if (i % 2)
				{
					this.className = r1;
				}
				else
				{
					this.className = r2;
				}
				
				if (l)
				{
					var c = this.className;
			
					this.onmouseover = function()
					{
						this.className = l;
					}
					this.onmouseout = function()
					{
						this.className = c;
					}
				}
			});
		},
		flash: function(w, h, f, v)
		{
			return '<object width="' + w + '" height="' + h + '">' +
				'<param name="movie" value="' + f + '" />' +
				'<param name="allowScriptAccess" value="sameDomain" />' +
				'<param name="flashvars" value="' + v + '" />' +
				'<param name="wmode" value="transparent" />' +
				'<embed src="' + f + '" type="application/x-shockwave-flash ' +
				'allowScriptAccess="sameDomain" flashvars="' + v + '" ' +
				'wmode="transparent" width="' + w + '" height="' + h + '">' +
				'</embed></object>';
		},
		include: function()
		{
			this.each(arguments, function()
			{
				Ajax.send(function()
				{
					eval(this.responseText);	
				}, 'GET', this, null);
			});
		}
	};
	
	/* Транспорт */
	var Ajax = {
		frame: null,
		onload: null,
		init: function()
		{
			var div = Tools.createElement(document.body, 'div');
			div.style.display = 'none';
			div.innerHTML = '<iframe id="_frame_" name="_frame_"></iframe>';
			
			Ajax.frame = $('_frame_');
			Tools.event(Ajax.frame, 'load', function()
			{
				if (Ajax.onload)
				{
					try
					{
						Ajax.onload.call(this, frames['_frame_'].document.body.innerHTML);
						Ajax.onload = null;
					}
					catch(e){}
				}	
			});
		},
		load: function(u, f)
		{
			setTimeout(function()
			{
				Ajax.onload = f;
				Ajax.frame.src = u;
			}, 0);
		},
		submit: function(f, fu)
		{
			setTimeout(function()
			{
				Ajax.onload = fu;
				f.setAttribute('target', '_frame_');
				f.submit();
			}, 0);
		},
		getXmlHttp: function()
		{
			try
			{
				return new XMLHttpRequest();
			}
			catch(e) {}
			try
			{
				return new ActiveXObject("Msxml2.XMLHTTP.6.0");
			}
			catch(e) {}
			try
			{
				return new ActiveXObject("Msxml2.XMLHTTP.3.0");
			}
			catch(e) {}
			try
			{
				return new ActiveXObject('Msxml2.XMLHTTP');
			}
			catch(e) {}
			try
			{
				return new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch(e) {}
		},
		send: function(f, m, u, p)
		{
			var r = Ajax.getXmlHttp();
			r.onreadystatechange = function()
			{
				if (r.readyState == 4 && (r.status == 200 || r.status == 0))
				{
					f.call(r);
				}
			}
			r.open(m, u, true);
			r.setRequestHeader("If-Modified-Since", "Mon, 26 Jul 1997 00:00:00 GMT");
            r.setRequestHeader("Pragma", "no-cache");
			r.send(p);
		}
	};
	
	/* Флешбокс */
	var Box = {
		blind: null,
		container: null,
		loader: null,
		init: function()
		{
			Box.blind = Tools.createElement(document.body, 'div');
			Tools.style(Box.blind, {
				backgroundColor: '#000',
				width: '100%',
				height: '100%',
				position: 'absolute',
				top: '0',
				left: '0',
				display: 'none',
				zIndex: '1',
				opacity: '0.7',
				filter: 'alpha(opacity=70)'
			});
			Box.blind.onclick = Box.hide;
			
			Box.container = Tools.createElement(document.body, 'div');
			Tools.style(Box.container, {
				position: 'absolute',
				top: '0',
				left: '0',
				display: 'none',
				zIndex: '2'
			});
		},
		show: function(c, f)
		{
			function alignBlind()
			{
				Box.blind.style.top = (
					document.documentElement.scrollTop || document.body.scrollTop
				) + 'px';
			}
			function alignContainer()
			{
				Box.container.style.top = 
					(document.documentElement.scrollTop || document.body.scrollTop) + 
			    	((Box.blind.clientHeight / 2) - (Box.container.clientHeight / 2)) + 'px';
			    Box.container.style.left = '0';
			    Box.container.style.left = 
					((document.body.clientWidth / 2) - (Box.container.clientWidth / 2)) + 'px';
			}
			
			setTimeout(function()
			{
				Tools.show(Box.blind);
				alignBlind();
				
				Tools.event(window, 'resize', function()
				{
					alignBlind();
					alignContainer();
				});
				
				Tools.event(window, 'scroll', function()
				{
					alignBlind();
					alignContainer();
				});
				
				Box.container.innerHTML = c;
				Tools.show(Box.container);
				Tools.fade('in', Box.container);
				alignContainer();
				
				if (f) f.call(Box);
			}, 0);
		},
		hide: function()
		{
			Tools.hide(Box.blind, Box.container);
			Box.container.innerHTML = '';
		},
		load: function(u, f)
		{
			if (Box.loader) Box.show(Box.loader);
			Ajax.load(u, function(c)
			{
				if (c)
				{
					Box.show(c);
					if (f) f.call(Box, c);
				}
			});
		},
		submit: function(f, fu)
		{
			if (Box.loader) Box.show(Box.loader);
			Ajax.submit(f, function(c)
			{
				if (c)
				{
					Box.show(c);
					if (fu) fu.call(Box, c);
				}
			});
		}
	};
	
	/* Вкладки */
	var Tabs = {
		ctrl: null,
		items: [],
		css: [],
		init: function(c, h, s)
		{
			Tabs.ctrl = c;
			Tabs.css = [h, s];
			
			if (c)
			{
				Tools.each($(document, 'div'), function()
				{
					var id = this.id;
					
					if (/tab;.*/i.test(id))
					{
						Tabs.items.push({
							tab: this,
							name: id.split('; ')[1],
							hold: id.split('; ')[2]
						});
						Tools.hide(this);
					}
				});
				Tabs.draw();
			}
		},
		select: function(i)
		{
			if (Tabs.items)
			{
				if (!Tabs.items[i].hold)
				{
					Tools.each(Tabs.items, function()
					{
						Tools.hide(this.tab);
					});
					Tools.show(Tabs.items[i].tab);
					Tools.each($(Tabs.ctrl, 'a'), function(n)
					{
						if (i == n)
						{
							this.className = Tabs.css[0];
						}
						else
						{
							if (this.className != Tabs.css[1])
							{
								this.className = '';
							}
						}
					});
				}
				else
				{
					this.select(0);
				}
			}
		},
		hold: function(n)
		{
			setTimeout(function()
			{
				Tools.each(Tabs.items, function()
				{
					if (this.name == n) this.hold = true;
				});
				Tabs.draw();
			}, 0);
		},
		unhold: function(n)
		{
			setTimeout(function()
			{
				Tools.each(Tabs.items, function()
				{
					if (this.name == n) this.hold = false;
				});
				Tabs.draw();
			}, 0);
		},
		draw: function()
		{
			Tabs.ctrl.innerHTML = '';
			
			if (Tabs.items)
			{
				Tools.each(Tabs.items, function(i)
				{
					var a = Tools.createElement(Tabs.ctrl, 'a');
					a.href = 'javascript:;';
					a.innerHTML = this.name;
						
					if (this.hold)
					{
						a.className = Tabs.css[1];
					}
					else
					{
						a.onclick = function()
						{
							Tabs.select(i);
							location = '#' + i;
						};
					}
				});
				Tabs.select(location.toString().split('#')[1] || 0);
			}
		}
	};
	
	/* Рисуем html */
	Tools.event(window, 'load', function()
	{
		Ajax.init();
		Box.init();
	});
