Array.prototype.walk = function(f){if(f){var a=[],i=this.length;while(i--){a.push(f(this[i]));}return a.reverse();};};
function px(val) { return val + 'px'; };
function an(o){o=o.split(':');return '<a name="'+o[0]+'" href="javascript:void(0);"'+(o[2]?' class="'+o[2]+'"':'')+'>'+o[1]+'</a>';}
var n_cache = new Array();
function n(o, c) { if(!n_cache[o] || c) n_cache[o] = document.getElementsByName(o); return n_cache[o]; }

var selector = new function() {
	this.recall = {};
	this.param = '';
	this.take = function() {};
	this.written = false;
	this.create = function(holder, param) {
		var i, j, k;
		this.holder = holder;
		this.padding=4;
		this.width=px(holder.offsetWidth-2*this.padding-2);//'180px';
		this.height='200px';
		this.mb = e('menu_box');
		this.ms = e('menu_scroll');
		this.md = e('menu_div');

		with(this.md.style) {
			width=this.width;
			zIndex='1';
			display='block';
			if(IE) margin='23px 0 0 0';
			else margin='21px 0 0 0';
			border='1px solid #a7a6aa';
			borderTop='none';
		}

		this.mcd = document.createElement('div');
		with(this.mcd.style) {
			margin='21px 0 0 0';
			height=px(this.md.offsetHeight+1);//this.height;
			width=px(holder.offsetWidth);
			position='absolute';
			overflow='hidden';
			background='#a7a6aa';
		}
		holder.parentNode.insertBefore(this.mcd, holder);

		this.mcd.parentNode.insertBefore(this.md, this.mcd);

		if(IE6)	{
			var o = e('search').getElementsByTagName('select');
			for(i = 0;i<o.length;i++) o[i].style.visibility='hidden';
		}

		if(this.param != param && typeof(this.recall[param]) == 'undefined') selector.ms.scrollLeft = 0;
		this.param = param;
		if(selector.recall && selector.recall[param] && typeof(this.take) == 'function') {
			var tmp = selector.recall[param].slice(); this.show();
			for(k in tmp) if(typeof(tmp[k])=='string') this.take({srcElement:{tagName:'A',name:tmp[k]},target:{tagName:'A',name:tmp[k]}});
			selector.ms.scrollLeft=0;selector.scroll.create(tmp.length-1);
		} else if(typeof(this.take) == 'function') this.take({srcElement:{tagName:'A',name:'default|'},target:{tagName:'A',name:'default|'}});
	};
	this.scroll = new function() {
		this.steps = [];
		this.create = function(value) {
			var j, k;
			selector.redraw('hidden');
			if(value != 0) with(selector.scroll) { steps = []; k = 7; for(j = 0; j <= k; j++) steps[j] = selector.ms.scrollLeft + (selector.mb.childNodes[0].clientWidth * value) / k * j; setTimeout('selector.scroll.run();',50); } else selector.ms.scrollLeft = 0;
		};
		this.run = function() { var v = selector.scroll.steps.shift();if(typeof(v)!='undefined'){selector.ms.scrollLeft=v;setTimeout('selector.scroll.run();',30);} else selector.redraw('auto'); };
	};
	this.redraw = function(flow) {
		var width = 0, i;
		this.md.style.overflow = 'hidden';
		this.md.style.zIndex = '99';
		this.ms.style.width = selector.width;
		if(this.mb.childNodes.length > 0) for(i=0; i < this.mb.childNodes.length; i++) {
			var mbc = this.mb.childNodes[i];
			mbc.onclick = function(event) { selector.take(event); };
			mbc.style.width = px(this.ms.clientWidth);
			width += mbc.offsetWidth;
			if(typeof(mbc.childNodes) == 'object' && mbc.childNodes[1] && mbc.childNodes[0])
				with(mbc.childNodes[1].style) {
					height = px(mbc.clientHeight - mbc.childNodes[0].offsetHeight);
					overflow = (flow ? flow : 'hidden');
				};
		};
		this.mb.style.width = px(width+6);
	};
	this.hide = function() {
		if(this.mcd && this.mcd.parentNode) this.mcd.parentNode.removeChild(this.mcd);
		if(this.md) this.md.style.display = 'none';
		if(IE6)	{
			var o = e('search').getElementsByTagName('select');
			for(i = 0;i<o.length;i++) o[i].style.visibility='visible';
		}
	};
	this.show = function() {
		if(this.mcd && this.mcd.parentNode) this.mcd.parentNode.removeChild(this.mcd);
		if(acp) acp.h();
		if(pop) pop.hide();
		if(this.param) this.redraw('auto');
	};
	this.preparedata = function(tab){var i; for(i in tab)if(!this[tab[i]])this[tab[i]]=[];};
};
selector.preparedata(['panstwa','miasta','grupy']);
selector.take = function(event) {
	var obj = (event ? event : window.event)[IE ? 'srcElement' : 'target'];
	if(obj.tagName == 'A' && obj.name && obj.name.match(/|/)) {
		var args = obj.name.split('|'), clear = function(a){var i, j; for(i in a){var t=[],r=e(a[i]);if(r && r.childNodes.length){t=r.getElementsByTagName('A');for(j=0;j < t.length;j++)t[j].XXXclassName='';}}};
		if(args[1] != 'h' && args[1] != 's') switch(args[0]) {
			case 'k':
				clear(['box_grupy','box_miasta','box_panstwa','box_kontynenty']);
				if(selector.panstwa && selector.panstwa[args[1]]) {
					e('box_panstwa').innerHTML = selector.panstwa[args[1]];
					selector.scroll.create(1);
					var link = n(obj.name)[0];
					link.className = 'selected';
					with(link.parentNode.parentNode) { if(clientHeight + scrollTop < link.offsetTop + link.clientHeight - (clientHeight/2)) setTimeout('n("'+ obj.name +'")[0].parentNode.parentNode.scrollTop='+(link.offsetTop + link.clientHeight - (clientHeight/2))+';', 10); };
				} else setTimeout("l('http://www.easygo.pl/js/samoloty/menu.dat.js.php?panstwa,"+args[1]+"');", 100);
				break;

			case 'p':
				clear(['box_grupy','box_miasta','box_panstwa']);
				if(selector.miasta && selector.miasta[args[1]] && selector.miasta[args[1]][args[2]]) {
					e('box_miasta').innerHTML = selector.miasta[args[1]][args[2]];
					selector.scroll.create(1);
					var link = n(obj.name)[0];
					link.className = 'selected';
					with(link.parentNode.parentNode) { if(clientHeight + scrollTop < link.offsetTop + link.clientHeight - (clientHeight/2)) setTimeout('n("'+ obj.name +'")[0].parentNode.parentNode.scrollTop='+(link.offsetTop + link.clientHeight - (clientHeight/2))+';', 10); };
				} else setTimeout("l('http://www.easygo.pl/js/samoloty/menu.dat.js.php?miasta,"+args[1]+","+args[2]+"');", 100);
				break;

			case 'g':
				clear(['box_grupy','box_miasta']);
				if(selector.grupy && selector.grupy[args[1]] && selector.grupy[args[1]][args[2]] && selector.grupy[args[1]][args[2]][args[3]]){
					e('box_grupy').innerHTML = selector.grupy[args[1]][args[2]][args[3]];
					selector.scroll.create(1);
					var link = n(obj.name)[0];
					link.className = 'selected';
					with(link.parentNode.parentNode) { if(clientHeight + scrollTop < link.offsetTop + link.clientHeight - (clientHeight/2)) setTimeout('n("'+ obj.name +'")[0].parentNode.parentNode.scrollTop='+(link.offsetTop + link.clientHeight - (clientHeight/2))+';', 10); };
				} else setTimeout("l('http://www.easygo.pl/js/samoloty/menu.dat.js.php?grupy,"+args[1]+","+args[2]+","+args[3]+"');", 100);
				break;

			case 'm':
				clear(['box_grupy','box_miasta']);
				var link = n(obj.name)[0];
				link.className = 'selected';
				with(link.parentNode.parentNode) { if(clientHeight + scrollTop < link.offsetTop + link.clientHeight - (clientHeight/2)) setTimeout('n("'+ obj.name +'")[0].parentNode.parentNode.scrollTop='+(link.offsetTop + link.clientHeight - (clientHeight/2))+';', 10); };
				if(selector.param && obj.innerHTML) switch(selector.param) {
					case 'miasto_z': e('miasto_z').value = obj.innerHTML; e('w_kod_z').value = args[1]; selector.hide(); break;
					case 'miasto_d': e('miasto_d').value = obj.innerHTML; e('w_kod_d').value = args[1]; selector.hide(); break;
				};
				break;

			case 'default':
				clear(['box_kontynenty','box_panstwa','box_miasta','box_grupy']);
				selector.show();
				if(typeof(selector.recall[selector.param]) == 'undefined') selector.ms.scrollLeft = 0;
				break;

		} else switch(args[1]) {
			case 's': selector.scroll.create(parseInt(args[2])); break;
			case 'h': selector.hide(); break;
		};
		return false;
	};
};


