
	if (window.location.hash) {
		if (window.location.hash.match(/^#?:/)) {
			var h = window.location.hash;
			window.location = JS_HOST + h.replace(/^#?:.*:/, '');
		}
	}

	var wlh = window.location.hash;
	setInterval(function () {
		if (wlh != window.location.hash.replace(/^#/, '')) {
			var prev = wlh;
			wlh = window.location.hash.replace(/^#/, '');

			if (window.location.hash.match(/^#?:/)) {
				var href = JS_HOST + wlh.replace(/^#?:.*:/, '');
				var name = decode_s2c(wlh.replace(/^#?:/, '').replace(/:.*$/, ''));
				reload_block(name, name, href);
			}
			else if (prev.match(/^#?:/)) {
				window.location = window.location;
			}
		}
	}, 200);

	var sAgent = navigator.userAgent.toLowerCase();

	function isIe() {
		return (!isPresto() && !isGecko() && document.all) ? true : false;
	}

	function isIe6() {
		return (isIe() && document.all && /MSIE (6)/.test(navigator.userAgent)) ? true : false;
	}

	function isGecko() {
		return sAgent.match(/gecko/i);
	}

	function isPresto() {
		return sAgent.match(/presto/i);
	}

	function createMethodReference(object, method) {
		return function () {
			return method.apply(object, arguments);
		};
	}

	function dbg(v) {
		return debug(v);
	}

	function debug(v) {
		try {
			if (is_def(console))
				console.info(v);
		} catch (e) {
		}
	}

	function replaceAll(strTarget, strSubString, strText) {
		var intIndexOfMatch = strText.indexOf(strTarget);

		while (intIndexOfMatch != -1) {
			strText = strText.replace(strTarget, strSubString);
			intIndexOfMatch = strText.indexOf(strTarget);
		}

		return strText;
	}

	var IE = (typeof document.all != 'undefined' && !(typeof window.opera == 'Opera'));
	//if (!IE) document.captureEvents(Event.MOUSEMOVE);
	var tempX, tempY;

	var attachEvent = function (o, sEventName, oCallback) {
		if (typeof o.addEventListener != 'undefined') {
		  o.addEventListener(
			sEventName,
			oCallback,
			false
		  );
		} else if (typeof o.attachEvent != 'undefined') {
		  o.attachEvent(
			'on' + sEventName,
			oCallback
		  );
		}
	};

	var _mouse = {x:0, y:0};
	function getMouseXY() {
		return _mouse;
	}

	function getBodyElement() {
		if (document.documentElement) {
			return document.documentElement;
		} else {
			return document.body;
		}
	}

	if (document) {
		attachEvent(document, 'mousemove', function (e) {
			if (isIe()) {
				_mouse = {
					x: e.clientX + getBodyElement().scrollLeft,
					y: e.clientY + getBodyElement().scrollTop
				};
			} else if (e && e.pageX) {
				_mouse = {
					x: e.pageX,
					y: e.pageY
				};
			} else {
				_mouse = {x:0, y:0};
			}
		});
	}

	function get_mouse() {
		return getMouseXY();
	}

	function getElementsByClass(searchClass,node,tag) {
		if (node == null)
			node = document;

		if (document.getElementsByClassName)
			return node.getElementsByClassName(searchClass);

		var classElements = new Array();
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		//var pattern = new RegExp("(^|[ 	]*)"+searchClass+"([ 	]*|$)");
		for (i = 0, j = 0; i < elsLen; i++) {
			//if ( pattern.test(els[i].className) ) {
			if (is_subclass_of(els[i], searchClass)) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}

	function is_subclass_of(element, className) {
		return (element.className == className || element.className.indexOf(" "+className) !== -1 || element.className.indexOf(className+" ") !== -1);
		className = new String(className);
		className = className.replace(/-/, '\\-');

		var pattern = new RegExp("(^|[ 	]+)"+className+"([ 	]+|$)");
		return pattern.test(element.className);

		return (new String(element.className)).match("/(^|[ 	]*)" + className + "([ 	]*|$)/");
	}

	function $(id) {
		return document.getElementById(id);
	}

	function n(type, id, count) {
		if (count > 0) {
			var res = [];
			for (var i = 0; i < count; i ++) {
				res.push(n(type, id?id+i:null));
			}
			return res;
		} else {
			var o = document.createElement(type);
			if (!id)
				id = 'object' + (new Date()).getTime();
			o.setAttribute('id', id);

			return o;
		}
	}

	function getAC() {
		var res;
		if (window.XMLHttpRequest) {
			try {
				res = new XMLHttpRequest();
		   } catch(e) {
				res = false;
		   }
		} else if (window.ActiveXObject) {
		   try {
			res = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				try {
					res =  new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					res = false;
				}
			}
		}

		return res;
	}

	var TConnection = function (sUrl, fOnData, settings, postdata) {
		this.onData = null;
		this.oConn = getAC();
		this.sMethod = postdata ? 'POST' : 'GET';
		this.sUrl = '';
		this.status = 'none';
		this.aPost = postdata ? postdata : {};
		this.aSettings = {
			timeout: 1000,
			queue: null,
			status_point: null
		};

		this.partialData = null;

		if (typeof settings == 'object') {
			for (k in settings) {
				if (typeof this.aSettings[k] != 'undefined') {
					this.aSettings[k] = settings[k];
				}
			}
		}

		this.oConn.onreadystatechange = createMethodReference(this, function () {
			if (this.oConn.readyState == 4) {
				if (this.onData)
					this.onData(this.oConn, this);
			}
		});

		this.onData = fOnData;

		if (sUrl) {
			this.sUrl = sUrl;
			this.open();
		}
	};
	TConnection.prototype.onData = null;
	TConnection.prototype.sMethod = 'GET';
	TConnection.prototype.sUrl = '';
	TConnection.prototype.status = '';
	TConnection.prototype.bCacheProtection = true;
	TConnection.prototype.aPost = {};

	TConnection.prototype.addPost = function (k, v) {
		this.aPost[k] = v;
	};

	TConnection.prototype.cacheProtect = function () {
		if (this.sUrl.match(/_t=[0-9]+/)) {
			this.sUrl.replace(/_t=[0-9]+/, '_t' + (new Date()).getTime());
		} else {
			this.sUrl += (this.sUrl.match(/\?/) ? '&' : '?') + '_t=' + (new Date()).getTime() ;
		}
	};

	TConnection.prototype.open = function () {
		this.cacheProtect();
		this.oConn.open(this.sMethod, this.sUrl, true);
		if (this.sMethod == 'POST') {
			var parameters = this.getParameters();
			this.oConn.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.oConn.setRequestHeader("Content-length", parameters.length);
			this.oConn.setRequestHeader("Connection", "close");
			this.oConn.send(parameters);
		} else {
			this.oConn.send('');
		}

		//document.body.style.cursor = 'wait';
	};

	TConnection.prototype.getParameters = function () {
		var sRes = '';

		for (var k in this.aPost) {
			sRes += urlencode(k) + '=' + urlencode(this.aPost[k]) + '&';
		}

		return sRes;
	};

	function urlencode( str ) {
		var ret = new String(str);

		ret = encodeURIComponent(ret);
		ret = ret.replace(/%20/g, '+');

		return ret;
	}

	function send_form(form, onload) {
		if (_is_loading)
			return;

		view_loading();
		var conn = new TConnection;

		var act = form.getAttribute('action');
		conn.sUrl = get_url(act, {partial: 1});

		if (_active_page) {
			//_active_page.url = conn.sUrl;
		}

		conn.onData = createMethodReference(onload, function (conn) {
			this(conn.responseText);
			evaluate_jcode();
			hide_loading();
		});

		if (form.getAttribute('method') == 'post')
			conn.sMethod = 'POST';

		setFormDataToConnection(form, conn);

		conn.open();
	}

	function setFormDataToConnection(form, conn) {
		var ip = get_by_tag(form, 'input', []);

		conn.sMethod = form.getAttribute('method').toUpperCase();

		for (k = 0; k < ip.length; k ++) {
			if (ip[k] && ip[k].getAttribute('name') != null && !is_subclass_of(ip[k], 'skip-partial')) {
				if (ip[k].getAttribute('type') == 'radio' || ip[k].getAttribute('type') == 'checkbox') {
					if (!ip[k].checked) {
						continue;
					}
				}

				if (ip[k].getAttribute('name') == 'partial') 
					continue;

				if (form.getAttribute('method') == 'post')
					conn.aPost[ip[k].getAttribute('name')] = ip[k].value;
				else 
					conn.sUrl += '&' + urlencode(ip[k].getAttribute('name')) + '=' + urlencode(ip[k].value);
			}
		}

		var t = form.getElementsByTagName('textarea');
		for (l = 0; l < t.length; l ++) {
			if (t[l] && t[l].getAttribute('name') != null) {
				if (form.getAttribute('method') == 'post') {
					conn.addPost(t[l].getAttribute('name'), t[l].value);
				} else {
					conn.sUrl += '&' + urlencode(t[l].getAttribute('name')) + '=' + urlencode(t[l].value);
				}
			}
		}

		t = form.getElementsByTagName('select');
		for (l = 0; l < t.length; l ++) {
			if (t[l] && t[l].getAttribute('name') != null) {
				if (form.getAttribute('method') == 'post') {
					conn.addPost(t[l].getAttribute('name'), t[l].value);
				} else {
					conn.sUrl += '&' + urlencode(t[l].getAttribute('name')) + '=' + urlencode(t[l].value);
				}
			}
		}
	}

	function get_by_tag(e, t, res) {
		if (e.childNodes) {
			for (var i = 0; i < e.childNodes.length; i ++) {
				if (e.childNodes[i].nodeName.toLowerCase() == t) {
					res.push(e.childNodes[i]);
				}
				get_by_tag(e.childNodes[i], t, res);
			}
		}
		return res;
	}

	var shadestep_to;
	function shadestep(el, value, stepsize, hideafter, reversed, onfinally) {
		value -= (reversed ? -stepsize : stepsize);
		if ((!reversed && value < 0) || (reversed && value > 100)) {
			value = reversed ? 100 : 0;
			if (hideafter || is_subclass_of(el, 'loading-hideafter')) {
				el.style.display = 'none';
			} else if (!reversed) {
				el.style.visibility = 'hidden';
			}
			el.style.opacity = 1;
			if (onfinally) {
				onfinally();
			}
			return;
		}

		el.style.visibility = '';
		el.style.opacity = value/100;

		shadestep_to = setTimeout(createMethodReference({el:el, value:value, stepsize:stepsize, hideafter:hideafter, reversed:reversed, onfinally:onfinally}, function () {
			shadestep(this.el, this.value, this.stepsize, this.hideafter, this.reversed, this.onfinally);
		}), 100);

		return shadestep_to;
	}

	function shadeoff(el, stepsize, hideafter, reversed, onfinally) {
		if (typeof el == 'string') el = $(el);
		if (!el) return;
		if (!stepsize) stepsize = 7;

		return shadestep(el, reversed ? 0 : 100, stepsize, hideafter, reversed, onfinally);
	}

	function shadeoff_timeout(timeo, el, stepsize, hideafter) {
		var func = createMethodReference({el:el, stepsize:stepsize, hideafter:hideafter}, function () {
			shadeoff(this.el, this.stepsize, this.hideafter);
		});

		setTimeout(func, timeo);
	}

	function select_all(name, strict, none) {
		if (typeof name == 'object') {
			for (var k = 0; k < name.length; k ++) {
				if (name[k].type == 'checkbox') {
					if (strict)
						name[k].checked = !none;
					else
						name[k].checked = !name[k].checked;
				}
			}
		} else {
			var radio = document.getElementsByTagName('input');
			for (var k = 0; k < radio.length; k ++) {
				if (radio[k].type == 'checkbox' && strpos(radio[k].name, name) === 0) {
					if (strict)
						radio[k].checked = !none;
					else
						radio[k].checked = !radio[k].checked;
				}
			}
		}
	}

	function get_checked(name) {
		var radio = document.getElementsByTagName('input');
		var res = [];
		for (var k = 0; k < radio.length; k ++) {
			if (radio[k].type == 'checkbox' && strpos(radio[k].name, name) === 0 && radio[k].checked)
				res.push(radio[k]);
		}
		return res;
	}

	function style_by_class(className, styles) {
		var it = getElementsByClass(className);
		for (var k = 0; k < it.length; k ++) {
			for (var s in styles) {
				it[k].style[s] = styles[s];
			}
		}
	}

	function check_by_class(className, strict) {
		var it = getElementsByClass(className);

		if (it.length > 0)
			var stv = it[0].checked;

		for (var k = 0; k < it.length; k ++)
			it[k].checked = strict ? !stv : !it[k].checked;
	}

	function style_by_id(id, styles) {
		var it = $(id);
		for (var s in styles) {
			it.style[s] = styles[s];
		}
	}

	function show_id(cls) {
		style_by_id(cls, {display: ''});
	}

	function hide_id(cls) {
		style_by_id(cls, {display: 'none'});
	}

	function show_class(cls) {
		style_by_class(cls, {display: ''});
	}

	function hide_class(cls) {
		style_by_class(cls, {display: 'none'});
	}

	var _url = new String(window.location);

	function get_url(url, arg) {
//		var query = '';

		if (!url)
			url = _url;

		url = new String(url);
//
//		if (_url.match(/\?/)) {
//			query = _url.replace(/.*\?/, '');
//		}

		if (!url.match(/\?/))
			url += '?';

		for (var k in arg) {
			url = url.replace(new RegExp(k + "(\[.*?\])*=.*?(&|$)", "g"), '');
			url += '&' + encodeURI(k) + '=' + encodeURI(arg[k]);
		}
		url = url.replace(/\?\&+/, "?");
		url = url.replace(/\&+/, "&");

		return url;
	}

	function strpos( haystack, needle, offset){
		var i = haystack.indexOf( needle, offset );
		return i >= 0 ? i : false;
	}

	function on_window_load(func) {
		if (isIe()) {
			attachEvent(document, 'readystatechange', createMethodReference({func:func}, function () {
				if (document.readyState == 'complete')
					this.func();
			}));
		} else
			attachEvent(window, 'load', func);
	}

	on_window_load(function () {
		show_class('js-show');
		hide_class('js-hide');
	});

	function in_array(needle, haystack) {
		if (haystack.length) {
			for (var k = 0; k < haystack.length; k ++) {
				if (haystack[k] == needle)
					return true;
			}
			return false;
		}

		for (var k in haystack) {
			if (haystack[k] == needle)
				return true;
		}
		return false;
	}

	function is_def(variable) {
		return typeof(variable) !== 'undefined';
	}

	function get_element_absolute(element) {
		var res = {
			top: element.offsetTop,
			left: element.offsetLeft
		}

		if (element.offsetParent) {
			var parent = get_element_absolute(element.offsetParent);
			res.top += parent.top;
			res.left += parent.left;
		}

		return res;
	}

	function register_function(name, cbx) {
		window[name] = cbx;
	}

	var noptions_group = {};

	function getForm(obj) {
		if (obj.nodeName.toLowerCase() == 'form')
			return obj;
		return getForm(obj.parentNode);
	}

	function clone(obj) {
		var cn = {};
		for (p in obj) {
			cn[p] = obj[p];
		}
		return cn;
	}

	function preventDefault(event) {
		if (event.preventDefault) {
			event.preventDefault();
		} else {
			event.returnValue = false;
		}
	}

	function substr(s, st, len) {
		s = new String(s);

		if (st < 0) {
			st += s.length;
		}

		if (len == undefined) {
			len = s.length;
		} else if (len < 0){
			len += s.length;
		} else {
			len += st;
		}

		if (len < st) {
			len = st;
		}

		return s.substring(st, len);
	}

	function trim(s) {
		return ltrim(rtrim(s));
	}

	function ltrim(s) {
		return (new String(s)).replace(new RegExp("^[ \t\r\n]+", "g"), "");
	}

	function rtrim(s) {
		return (new String(s)).replace(new RegExp("[ \t\r\n]+$", "g"), "");
	}

	function l(s) {
		for (var i = 1; i < arguments.length; i ++) {
			s = s.replace('%' + (i-1), arguments[i]);
		}

		return s;
	}

	function time() {
		return _thetime;
	}

	function array() {
		var res = [];
		for (var i = 0; i < arguments.length; i ++)
			res.push(arguments[i]);

		return res;
	}

	function get_html_translation_table(table) {
		var entities = {}, histogram = {}, decimal = 0, symbol = '';

		entities['38'] = '&amp;';
		entities['60'] = '&lt;';
		entities['62'] = '&gt;';

		for (decimal in entities) {
			symbol = String.fromCharCode(decimal)
			histogram[symbol] = entities[decimal];
		}

		return histogram;
	}

	function htmlspecialchars (s, quote_style) {
		var tmp_str = new String(s);

		var histogram = {}, symbol = '', i = 0;

		if (false === (histogram = get_html_translation_table('HTML_SPECIALCHARS', quote_style))) {
			return false;
		}

		for (symbol in histogram) {
			entity = histogram[symbol];
			tmp_str = tmp_str.split(symbol).join(entity);
		}

		return tmp_str;
	}

	function array_unshift(a, val) {
		return a.unshift(val);
	}

	function array_pop(a) {
		return a.pop();
	}
	function array_push(a, val) {
		return a.push(val);
	}


	on_window_load(function () {
		if (typeof(console) == 'undefined') {
			var console = {"log": function () {}};
		}

		var el = getElementsByClass('target-blank');
		for (var i = 0; i < el.length; i ++)
			el[i].target = '_blank';
	});

	function list_changePage(p, loc) {
		window.scroll(0, 0);
		return changePage(p, loc);
	}

	var block_reloading = {};

	function reload_block(name, objid, href, onload, gid, postdata) {
		if (isIe6())
			return true;

		var obj = $(objid);

		if (!href) {
			if (onload)
				onload();
			return false;
		}

		if (!obj) {
			if (onload)
				onload();
			return true;
		}

		href = href.replace(/#.*$/, '');

		var c = new CElement;
		c.setElement(obj);

		var d = n('div');
		d.style.backgroundColor = '#FFEDCC';
		d.style.backgroundImage = 'url("' + JS_HOST + 'view/images/loading.gif")';
		d.style.width = '130px';
		d.style.height = '25px';
		d.style.lineHeight = '25px';
		d.style.paddingLeft = '25px';
		d.style.backgroundPosition = '5px center';
		d.style.position = 'absolute';
		d.style.border = '1px solid #FFA500';
		d.style.top = (c.getAbsoluteTop() + c.getHeight()/2 - 20) + 'px';
		d.style.left = (c.getAbsoluteLeft() + c.getWidth()/2 - 60) + 'px';
		d.innerHTML = 'Ładowanie ...';

		setTimeout(createMethodReference(d, function () {
			document.body.appendChild(this);
		}), 500);

		if (block_reloading[gid]) {
			block_reloading[gid].d.style.display = 'none';
			clearTimeout(block_reloading[gid].shadeoff);
		}

		block_reloading[gid] = {
			"id": (new Date).getTime() + Math.random(),
			"d": d,
			"onload": onload
		};

		new TConnection(get_url(href, {"block": name}), createMethodReference({href: href, obj:obj, d:d, id:block_reloading[gid].id, gid:gid}, function (c) {
			var gid = this.gid;

			if (this.id == block_reloading[gid].id) {
				//window.location.hash = encode_s2c(this.href);
				wlh = window.location.hash = ':' + encode_s2c(this.obj.id) + ':' + (this.href.replace(JS_HOST, ''));
				this.obj.innerHTML = c.responseText;

				/*block_reloading[gid].shadeoff = shadeoff(this.obj, 20, false, false, createMethodReference(this, function () {
					this.obj.innerHTML = c.responseText;
					reset_autoblocks();
					shadeoff(this.obj, 90, false, true);
				}));*/

				this.d.style.display = 'none';
			}

			if (block_reloading[gid].onload) 
				block_reloading[gid].onload();
		}), null, postdata);

		return false;
	}

	function reload_block_form(name, objid, form, onload, gid) {
		var conn = new TConnection;
		conn.sUrl = form.action + (form.action.match(/\?/) ? '' : '?');
		setFormDataToConnection(form, conn);
		return reload_block(name, objid, conn.sUrl, onload, gid, conn.sMethod.toLowerCase() == 'post' ? conn.aPost : null);
	}

	on_window_load(function () {
		var i = getElementsByClass('autoselect');
		for (var k = 0; k < i.length; k ++) {
			attachEvent(i[k], 'focus', createMethodReference(i[k], function () {
				this.select();
			}));
		}
	});

	var autoblocks = [];
	function set_autoblock(ab, reset) {
		if (!reset)
			autoblocks.push(ab);
		
		for (var i = 0; i < ab.length; i ++) {
			var el = getElementsByClass('block-' + ab[i].name);

			for (var j = 0; j < el.length; j ++) {
				if (is_subclass_of(el[j], 'autoblock-set'))
					continue;
					
				el[j].className += ' autoblock-set';
				attachEvent(el[j], el[j].nodeName.toLowerCase() == 'form' ? 'submit' : 'click', createMethodReference({"block": ab[i].block, "el":el[j]}, function (e) {
					for (var i = 0; i < this.block.length; i ++) {
						var uuid = 'autoblock-' + this.block[i];

						if (this.el.nodeName.toLowerCase() == 'form')
							var rbs = reload_block_form(this.block[i], this.block[i], this.el, null, uuid);
						else
							var rbs = reload_block(this.block[i], this.block[i], this.el.href, null, uuid);


						if ((rbs === false) && (i == this.block.length - 1)) {
							preventDefault(e);
							return false;
						}

						return true;
					}
				}));
			}
		}
	}

	function reset_autoblocks() {
		for (var i = 0; i < autoblocks.length; i ++)
			set_autoblock(autoblocks[i], true);
	}

	function encode_s2c(s) {
		var res = '';
		for (var i = 0; i < s.length; i ++) {
			if (s.charCodeAt(i) < 16)
				res += '0';

			res += s.charCodeAt(i).toString(16);
		}
		return res;
	}

	function decode_s2c(s) {
		var res = '';
		for (var i = 0; i < s.length; i += 2) {
			res += String.fromCharCode(parseInt(s.substr(i, 2), 16));
		}
		return res;
	}


	var MagicText = function () {
		this.oParent = $('magic-text');
		this.oParentC = new CElement;
		this.oParentC.setElement(this.oParent);

		this.oSpan = [];

		var l = this.oParent.getElementsByTagName('span');
		for (var i = 0; i < l.length; i ++)
			this.oSpan.push(l[i]);

		this.iPos = 0;
		this.iPrevPos = null;

		this.iHideTickSpeed = 25;
		this.iShakeSpeed = 5;
		this.iShakeCount = 5;
		
		this.iTickSpeed = 20;
		this.iTickInterval = 70;
		
		this.oPrevC = null;
		this.rTickInterval = null;
		this.iMovPos = 0;
		this.iHideMovPos = 0;
		this.oParent.style.overflow = 'hidden';

		setTimeout(createMethodReference(this, this.anim), 500);
		setInterval(createMethodReference(this, this.rotate), 10000);
	};

	MagicText.prototype.rotate = function () {
		this.anim();
	};

	MagicText.prototype.anim = function () {
		clearInterval(this.rTickInterval);
		
		var el = this.oSpan[this.iPos];
		el.style.display = '';
		
		this.iMovPos = this.oParentC.getWidth();
		this.iHideMovPos = 0;

		this.rTickInterval = setInterval(createMethodReference(this, this.tick), this.iTickInterval);
	};

	MagicText.prototype.tick = function () {
		if (this.iMovPos <= 0) {
			this.iPrevPos = this.iPos;
			this.oSpan[this.iPos].style.marginLeft = "0";

			this.iPos = (this.iPos == this.oSpan.length-1) ? 0 : (this.iPos+1);

			this.iShakePos = 0;
			this.shake();

			clearInterval(this.rTickInterval);
			return;
		}

		this.iMovPos = Math.max(0, this.iMovPos - this.iTickSpeed);
		this.oSpan[this.iPos].style.marginLeft = this.iMovPos + 'px';

		if (this.iPrevPos !== null) {
			if (this.oParentC.getWidth() <= this.iHideMovPos) {
				this.oSpan[this.iPrevPos].style.display = 'none';
				this.oSpan[this.iPrevPos].style.marginLeft = "0";
				
				this.oParent.removeChild(this.oSpan[this.iPrevPos]);
				this.oParent.appendChild(this.oSpan[this.iPrevPos]);
			} else {
				this.iHideMovPos = Math.max(0, this.iHideMovPos + this.iHideTickSpeed);
				this.oSpan[this.iPrevPos].style.marginLeft = "-" + this.iHideMovPos + 'px';
			}
		}
	};

	MagicText.prototype.shake = function () {
		if (this.iShakePos < this.iShakeCount) {
			this.oSpan[this.iPrevPos].style.marginLeft = (Math.random() * this.iShakeSpeed * (this.iShakePos % 2 == 0 ? 1 : 0)) + 'px';
			this.iShakePos ++;
			setTimeout(createMethodReference(this, this.shake), 70);
		}
	};

	on_window_load(function () {
		new MagicText;
	});


	var ExtendedSelect = function (element, type) {
		if (isIe6())
			return;
			
		this.sType = type;
		this.oElement = element;
		this.oElement.setAttribute('autocomplete', "off");
		
		this.oExtImage = n('img');
		element.parentNode.insertBefore(this.oExtImage, element);

		this.oExtImage.src = JS_HOST + 'view/images/select-expander.png';
		this.oExtImage.style.position = 'absolute';
		this.oExtImage.style.marginLeft = '140px';
		this.oExtImage.style.marginTop = '2px';
		this.oExtImage.style.display = 'none';
		this.oExtImage.style.cursor = 'pointer';

		this.oContainer = n('div');
		element.parentNode.insertBefore(this.oContainer, element);
		this.oContainer.className = 'extended-select-container';
		this.oContainer.style.display = 'none';

		this.rCloseTimeout = null;

		attachEvent(element, 'focus', createMethodReference(this, this.elementFocus));
		attachEvent(element, 'blur', createMethodReference(this, this.elementBlur));
		attachEvent(element, 'keyup', createMethodReference(this, this.elementKeyPress));
		attachEvent(this.oExtImage, 'click', createMethodReference(this, this.extImageClick));
		attachEvent(this.oContainer, 'click', createMethodReference(this, this.extImageClick));
	};

	ExtendedSelect.prototype.extImageClick = function () {
		this.oElement.focus();
		this.updateList();
	};

	ExtendedSelect.prototype.elementFocus = function () {
		clearInterval(this.rCloseTimeout);
		
		this.oExtImage.style.display = '';
		if (this.oElement.value != '') {
			this.updateList();
		} 
	};

	ExtendedSelect.prototype.elementBlur = function () {
		this.rCloseTimeout = setTimeout(createMethodReference(this, function () {
			this.oExtImage.style.display = 'none';
			this.oContainer.style.display = 'none';
		}), 200);
	};

	ExtendedSelect.prototype.elementKeyPress = function () {
		if (this.oElement.value != '') {
			this.updateList();
		} else {
			this.oContainer.style.display = 'none';
		}
	};

	ExtendedSelect.prototype.updateList = function () {
		new TConnection(JS_HOST + 'extselect/?type=' + this.sType + '&match=' + htmlspecialchars(this.oElement.value), createMethodReference({"es": this, "value": this.oElement.value}, function (c) {
			try {
				eval('var data = ' + c.responseText + ';');
				this.es.oContainer.innerHTML = '';

				for (var i = 0; i < data.length; i ++) {
					var d = n('div');
					d.className = 'extended-select-element';
					d.innerHTML = data[i];
					attachEvent(d, 'click', createMethodReference({"el": this.es.oElement, "d":d}, function () {
						this.el.value = this.d.innerHTML;
					}));
					this.es.oContainer.appendChild(d);
				}

				this.es.oContainer.style.display = '';
				if (data.length < 1) {
					this.es.oContainer.style.display = 'none';
				} else if (data.length == 1 && data[0] == this.value) {
					this.es.oContainer.style.display = 'none';
				} else if (data.length > 10) {
					this.es.oContainer.style.height = '150px';
					this.es.oContainer.style.overflow = 'auto';
				} else {
					this.es.oContainer.style.height = 'auto';
				}
			} catch (e) {
				debug(e);
			}
		}));
	};






	var CalendarInput = function (element, type) {
		this.sType = type;
		this.oElement = element;
		this.oElement.setAttribute('autocomplete', "off");

		this.oExtImage = n('img');
		element.parentNode.insertBefore(this.oExtImage, element);

		this.oExtImage.src = JS_HOST + 'view/images/icon-calendar.png';
		this.oExtImage.style.position = 'absolute';
		this.oExtImage.style.marginLeft = '45px';
		this.oExtImage.style.marginTop = '3px';
		if (this.oElement.value != '')
			this.oExtImage.style.display = 'none';
		this.oExtImage.style.cursor = 'pointer';

		this.oContainer = n('div');
		element.parentNode.insertBefore(this.oContainer, element);
		this.oContainer.className = 'calendar-container';
		this.oContainer.style.display = 'none';
		this.oContainer.style.zIndex = '9999';
		this.oContainer.style.position = 'absolute';

		this.rCloseTimeout = null;
		this.date = new Date;

		attachEvent(element, 'focus', createMethodReference(this, this.elementFocus));
		attachEvent(element, 'blur', createMethodReference(this, this.elementBlur));
		attachEvent(element, 'keyup', createMethodReference(this, this.elementKeyPress));
		attachEvent(this.oExtImage, 'click', createMethodReference(this, this.extImageClick));
	};

	CalendarInput.prototype.checkInitialization = function () {
		this.drawCalendar(this.date);
		this.oContainer.style.display = '';
	};

	CalendarInput.prototype.drawCalendar = function (date) {
		this.oContainer.innerHTML = '';

		var table = n('table');
			var thead = n('thead');
				var tr = n('tr');

				var th = n('th', null, 3);
				th[0].style.backgroundImage = 'url("' + JS_HOST + 'view/images/month-left.png")';
				th[0].style.cursor = 'pointer';
				th[1].setAttribute('colspan', "5");
				th[1].colSpan = '5';
				th[1].style.whiteSpace = 'nowrap';
				th[1].innerHTML = getMonth(date.getMonth()) + ' ' + get_year(date);
				th[2].style.backgroundImage = 'url("' + JS_HOST + 'view/images/month-right.png")';
				th[2].style.backgroundPosition = 'right';
				th[2].style.cursor = 'pointer';

				attachEvent(th[0], 'click', createMethodReference(this, function () {
					this.oElement.focus();
					this.date = new Date(get_year(this.date), this.date.getMonth() - 1, 1);
					this.drawCalendar(this.date);
				}));
				attachEvent(th[2], 'click', createMethodReference(this, function () {
					this.oElement.focus();
					this.date = new Date(get_year(this.date), this.date.getMonth() + 1, 1);
					this.drawCalendar(this.date);
				}));

				tr.appendChild(th[0]);
				tr.appendChild(th[1]);
				tr.appendChild(th[2]);

				thead.appendChild(tr);

			table.appendChild(thead);

			var tbody = n('tbody');

			var dim = daysInMonth(get_year(date), date.getMonth()+1);
			var fd = (new Date(get_year(date), date.getMonth(), 1)).getDay();
			if (fd == 0)
				fd = 6;
			else
				fd --;
				
			var week_d = 0;
			var tr = n('tr');
			tbody.appendChild(tr);

			for (var i = 0; i < fd; i ++) {
				week_d ++;
				var td = n('td');
				tr.appendChild(td);
			}

			for (var i = 1; i <= dim; i ++) {
				if (week_d == 7) {
					week_d = 0;
					var tr = n('tr');
					tbody.appendChild(tr);
				}

				week_d ++;
				var td = n('td');
				td.innerHTML = i;
				attachEvent(td, 'click', createMethodReference({"t": this, "i": i, "date":date}, function () {
					this.t.oElement.value = (get_year(this.date)) + '-' + (this.date.getMonth() < 9 ? '0' : '') + (1+this.date.getMonth()) + '-' + (this.i < 10 ? '0' : '') + this.i;
					this.t.oExtImage.style.display = '';
					this.t.oContainer.style.display = '';
				}));
				if (week_d == 7)
					td.style.color = 'red';

				tr.appendChild(td);
			}

			for (var i = 0; i < (7 - week_d); i ++) {
				var td = n('td');
				tr.appendChild(td);
			}

			table.appendChild(tbody);

		this.oContainer.appendChild(table);
	};

	CalendarInput.prototype.extImageClick = function () {
		this.oElement.focus();
		this.checkInitialization();
	};

	CalendarInput.prototype.elementFocus = function () {
		clearInterval(this.rCloseTimeout);
		this.oExtImage.style.display = '';
	};

	CalendarInput.prototype.elementBlur = function () {
		this.rCloseTimeout = setTimeout(createMethodReference(this, function () {
			if (this.oElement.value != '')
				this.oExtImage.style.display = 'none';
				
			this.oContainer.style.display = 'none';
		}), 200);
	};

	CalendarInput.prototype.elementKeyPress = function () {
	};

	function get_year(date) {
		return ((date.getYear() < 1900) ? 1900 : 0) + date.getYear();
	}

	function daysInMonth(year,month) {
		var m = [31,28,31,30,31,30,31,31,30,31,30,31];
		if (month != 2) return m[month - 1];
		if (year%4 != 0) return m[1];
		if (year%100 == 0 && year%400 != 0) return m[1];
		return m[1] + 1;
	}

	function getMonth(m) {
		return ((["styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "pażdziernik", "listopad", "grudzień"])[m]);
	}


	var Pictures = function (element, medium, large) {
		this.oElement = element;
		this.oLarge = getElementsByClass('view-large-picture', this.oElement)[0].getElementsByTagName('img')[0];
		this.aMin = getElementsByClass('view-pictures-mini', this.oElement)[0].getElementsByTagName('img');
		this.aMedium = medium;
		this.aLarge = large;
		this.iActive = 0;

		for (var i = 0; i < this.aMin.length; i ++) {
			attachEvent(this.aMin[i], 'click', createMethodReference({t: this, i:i}, function () {
				this.t.oLarge.src = this.t.aMedium[this.i];
				this.t.iActive = this.i;
			}));
		}

		var d = n('div');
		d.className = 'view-pictures-pop';
		d.style.display = 'none';
		document.body.appendChild(d);

		var close = n('div');
		close.innerHTML = 'Zamknij X';
		close.style.backgroundColor = '#b20000';
		close.style.width = '600px';
		close.style.margin = '0 auto';
		close.style.padding = '4px 10px 0 10px';
		close.style.color = '#fff';
		close.style.cursor = 'pointer';
		close.style.textAlign = 'right';
		close.style.fontSize = '12px';
		d.appendChild(close);

		attachEvent(close, 'click', createMethodReference(d, function () {
			this.style.display  = 'none';
		}));

		this.oPop = n('div');
		this.oPop.title = 'Kliknij, aby zobaczyć następne zdjęcie';
		this.oPop.style.cursor = 'pointer';
		d.appendChild(this.oPop);

		attachEvent(this.oLarge, 'click', createMethodReference(this, function () {
			this.oPop.innerHTML = '<img src="' + this.aLarge[this.iActive] + '" alt="" />';
			this.oPop.parentNode.style.display = '';
		}));

		attachEvent(this.oPop, 'click', createMethodReference(this, function () {
			this.iActive ++;
			if (this.iActive >= this.aLarge.length)
				this.iActive = 0;
				
			this.oPop.innerHTML = '<img src="' + this.aLarge[this.iActive] + '" alt="" />';
		}));


		var navi = n('div');
		navi.style.width = '600px';
		navi.style.margin = '0 auto';
		navi.style.backgroundColor = '#b20000';
		navi.style.padding = '8px 10px 8px 10px';
		navi.style.marginTop = '-4px';
		d.appendChild(navi);

		var prev = n('span');
		prev.innerHTML = ' << Poprzednie';
		prev.style.cssFloat = 'left';
		prev.style.textAlign = 'left';
		prev.style.width = '280px';
		prev.style.color = '#fff';
		prev.style.fontSize = '12px';
		prev.style.display = 'inline-block';
		prev.style.cursor = 'pointer';
		navi.appendChild(prev);

		attachEvent(prev, 'click', createMethodReference(this, function () {
			this.iActive --;
			if (this.iActive < 0)
				this.iActive = this.aLarge.length - 1;

			this.oPop.innerHTML = '<img src="' + this.aLarge[this.iActive] + '" alt="" />';
		}));

		var next = n('span');
		next.innerHTML = 'Następne >> ';
		next.style.cssFloat = 'right';
		next.style.textAlign = 'right';
		next.style.width = '280px';
		next.style.color = '#fff';
		next.style.fontSize = '12px';
		next.style.display = 'inline-block';
		next.style.cursor = 'pointer';
		navi.appendChild(next);

		attachEvent(next, 'click', createMethodReference(this, function () {
			this.iActive ++;
			if (this.iActive >= this.aLarge.length)
				this.iActive = 0;

			this.oPop.innerHTML = '<img src="' + this.aLarge[this.iActive] + '" alt="" />';
		}));

		var c = n('div');
		c.className = 'clear';
		navi.appendChild(c);
	};


	var Search = function (element) {
		this.oElement = element;
		this.aControls = Form.getControls(element, true);
		this.oStatus = getElementsByClass('search-column', element)[2].getElementsByTagName('div')[0];
		
		this.aNames = {
			"voivod": l("Województwo"),
			"id_category": l("Kategoria"),
			"city": l("Miasto"),
			"price_min": l("Cena od"),
			"price_max": l("Cena do"),
			"q": l("Fraza")
		};
		this.iLen = 1;

		for (var i in this.aControls.item) {
			attachEvent(this.aControls.item[i], 'change', createMethodReference(this, this.someChange));
			attachEvent(this.aControls.item[i], 'keyup', createMethodReference(this, this.someChange));
		}
	};

	Search.prototype.someChange = function () {
		this.oStatus.innerHTML = '';
		
		for (var i in this.aNames) {
			var ct = this.aControls.item[i];
			var d = n('div');

			if (ct.value == '') {
				d.style.color = '';
				d.innerHTML = '<img src="' + JS_HOST + 'view/images/icon_error.png" alt="" class="mid" /> ' + l('Wypełnij "%0"', this.aNames[i]);
			} else {
				d.innerHTML = '<img src="' + JS_HOST + 'view/images/icon_ok.png" alt="" class="mid" /> ' + this.aNames[i] + " OK";
			}

			this.oStatus.appendChild(d);
		}
	};
