/*pushoptions*/
/*clearoptions*/
/*jslint browser: true*/
/*jslint white: false*/
/*jslint strict: false*/
/*jslint devel: true*/
/*jslint debug: true*/
/*jslint rhino: true*/
/*jslint onevar: true*/
/*jslint undef: false*/
/*jslint nomen: true*/
/*jslint eqeqeq: false*/
/*jslint plusplus: false*/
/*jslint forin: true*/
/*jslint regexp: false*/
/*jslint maxerr: 200*/

/* --- utf-8 check --- ěščřžýáíé --- */

if (console) {
}
else {
	var console = {
		log: function(t){
		}
	};
}

(function(){

var special = ['À','à','Á','á','Â','â','Ã','ã','Ä','ä','Å','å','Ă','ă','Ą','ą','Ć','ć','Č','č','Ç','ç', 'Ď','ď','Đ','đ', 'È','è','É','é','Ê','ê','Ë','ë','Ě','ě','Ę','ę', 'Ğ','ğ','Ì','ì','Í','í','Î','î','Ï','ï', 'Ĺ','ĺ','Ľ','ľ','Ł','ł', 'Ñ','ñ','Ň','ň','Ń','ń','Ò','ò','Ó','ó','Ô','ô','Õ','õ','Ö','ö','Ø','ø','ő','Ř','ř','Ŕ','ŕ','Š','š','Ş','ş','Ś','ś', 'Ť','ť','Ť','ť','Ţ','ţ','Ù','ù','Ú','ú','Û','û','Ü','ü','Ů','ů', 'Ÿ','ÿ','ý','Ý','Ž','ž','Ź','ź','Ż','ż', 'Þ','þ','Ð','ð','ß','Œ','œ','Æ','æ','µ'];
var standard = ['A','a','A','a','A','a','A','a','Ae','ae','A','a','A','a','A','a','C','c','C','c','C','c','D','d','D','d', 'E','e','E','e','E','e','E','e','E','e','E','e','G','g','I','i','I','i','I','i','I','i','L','l','L','l','L','l', 'N','n','N','n','N','n', 'O','o','O','o','O','o','O','o','Oe','oe','O','o','o', 'R','r','R','r', 'S','s','S','s','S','s','T','t','T','t','T','t', 'U','u','U','u','U','u','Ue','ue','U','u','Y','y','Y','y','Z','z','Z','z','Z','z','TH','th','DH','dh','ss','OE','oe','AE','ae','u'];

String.implement({

	standardize: function(){
		var text = this;
		special.each(function(ch, i){
			text = text.replace(new RegExp(ch, 'g'), standard[i]);
		});
		return text;
	}

});

})();

function closeBanner() {
	var el;
	el = $('flashBannerWrapper');
	if (el) {
		el.dispose();
	}
	Cookie.write('noBannerPlease', 1, {duration: 1});
}

function screenPreview() {
	var a;
	a = $$('link[media="disable"]');
	if (a && a.length > 0) {
		a.setProperty('media', 'screen');
	}
	a = $$('link[href="/common/css/print.css"]');
	if (a && a.length > 0) {
		a.setProperty('media', 'print');
	}
	a = $('screenPreview');
	if (a) {
		a.addClass('hide');
	}
	window.focus();
	return false;
}

var run = {
	hp: 0,
	searcher: 0,
	category: 0,
	textual: 0,
	map: 0,
	filtering: 0
};

var markerClickFn = function (el, latlng) {
	return function (a) {
		var n = a, b, infoHtml, props;
		b = a.replace(/[^\d]/g, '');
		if (!this.bubbleCache[b]) {
			infoHtml = '<div class="mapBubble" id="bubble_' + n + '">' + $lang.loadingInfo + '</div>';
			this.map.closeInfoWindow();
			this.map.openInfoWindowHtml(latlng, infoHtml);
			props = {url: '/map.php?do=bubble' + '&' + this.options.urlAddon + '&id=' + b, update: 'bubble_' + n, onSuccess: function (tree, elements, txt) {
				if (b) {
					this.bubbleCache[b] = txt;
				}
				this.resizeBubble(b);
			}.bind(this)};
			setTimeout(function () {
				var a = new Request.HTML(props).get();
			}, 300);
		}
		else {
			this.map.closeInfoWindow();
			this.map.openInfoWindowHtml(latlng, '<div class="mapBubble" id="bubble_' + n + '">' + this.bubbleCache[b] + '</div>');
			setTimeout(function () {
				this.resizeBubble(b);
			}.bind(this), 100);
		}
	};
};

/*
---
description: A Class that provides a cross-browser history-management functionaility, using the browser hash to store the application's state

license: MIT-style

authors:
- Arieh Glazer
- Dave De Vos
- Digitarald

requires:
- core/1.2.4: Class
- core/1.2.4: Class.Extras
- core/1.2.4: Element

provides: [HashListner]

...
*/

var HashListener = new Class({
	Implements : [Options,Events],
	options : {
		blank_page : '/blank.html',
		start : false
	},
	iframe : null,
	currentHash : '',
	firstLoad : true,
	handle : false,
	useIframe : (Browser.Engine.trident && (typeof(document.documentMode) == 'undefined' || document.documentMode < 8)),
	ignoreLocationChange : false,

	initialize : function(options){
		var s_f, 
			self=this,
			cached_storage;
			
		this.setOptions(options);
		
		// Disable Opera's fast back/forward navigation mode
		if (Browser.Engine.presto && window.history.navigationMode) {
			window.history.navigationMode = 'compatible';
		}


		 // IE8 in IE7 mode defines window.onhashchange, but never fires it...
		if (window.onhashchange && (typeof(document.documentMode) == 'undefined' || document.documentMode > 7)){
			// The HTML5 way of handling DHTML history
			window.onhashchange = function () {
				var hash = self.getHash();
				if (hash == self.currentHash) {
					return;
				}
				self.fireEvent('hash-changed',hash);
			};
		} else {
			if (this.useIframe){
				this.initializeHistoryIframe();
			}
		}

		window.addEvent('unload', function(event) {
			self.firstLoad = null;
		});
		
		if (this.options.start) {
			this.start();
		}
	},

	initializeHistoryIframe : function(){
		var hash = this.getHash(), self = this, doc;
		this.iframe = new IFrame({
			src		: this.options.blank_page,
			styles	: { 
				'position'	: 'absolute',
				'top'		: 0,
				'left'		: 0,
				'width'		: '1px', 
				'height'	: '1px',
				'visibility': 'hidden'
			}
		}).inject(document.body);

		doc	= (this.iframe.contentDocument) ? this.iframe.contentDocumnet : this.iframe.contentWindow.document;
		doc.open();
		doc.write('<html><body id="state">' + hash + '</body></html>');
		doc.close();
		return;
	},
	checkHash : function(){
		var hash = this.getHash(), ie_state, doc;
		if (this.ignoreLocationChange) {
			this.ignoreLocationChange = false;
			return;
		}

		if (this.useIframe){
			doc	= (this.iframe.contentDocument) ? this.iframe.contentDocumnet : this.iframe.contentWindow.document;
			ie_state = doc.body.innerHTML;
			
			if (ie_state!=hash){
				this.setHash(ie_state);
				hash = ie_state;
			} 
		}		
		
		if (this.currentLocation == hash) {
			return;
		}
		
		this.currentLocation = hash;
		
		this.fireEvent('hash-changed',hash);
	},
	setHash : function(newHash){
		window.location.hash = this.currentLocation = newHash;
		
		this.fireEvent('hash-changed',newHash);
	},
	getHash : function(){
		var m;
		if (Browser.Engine.geko){
			m = /#(.*)$/.exec(window.location.href);
			return m && m[1] ? m[1] : '';
		}else{
			return window.location.hash.substr(1);
		}
	},
	setIframeHash: function(newHash) {
		var doc	= (this.iframe.contentDocument) ? this.iframe.contentDocumnet : this.iframe.contentWindow.document;
		doc.open();
		doc.write('<html><body id="state">' + newHash + '</body></html>');
		doc.close();
		
	},
	updateHash : function (newHash){
		if ($type(document.id(newHash))) {
			this.debug_msg("Exception: History locations can not have the same value as _any_ IDs that might be in the document,"
						+ " due to a bug in IE; please ask the developer to choose a history location that does not match any HTML"
						+ " IDs in this document. The following ID is already taken and cannot be a location: " + newLocation);
		}
		
		this.ignoreLocationChange = true;
		
		if (this.useIframe) {
			this.setIframeHash(newHash);
		}
		else {
			this.setHash(newHash);
		}
	},
	start : function(){
		this.handle = this.checkHash.periodical(100, this);
	},
	stop : function(){
		$clear(this.handle);
	}
});


/*
---
description: A Class that provides a cross-browser history-management functionaility, using the browser hash to store the application's state

license: MIT-style

authors:
- Arieh Glazer

requires:
- HistoryManager/0.4.1: HashListner

provides: [HistoryManager]

...
*/
var HistoryManager = new Class({
	Extends : HashListener,
	state : new Hash({}),
	fromHash : false,
	fromHandle :false,
	initialize : function(options){
		this.parent(options);		
		this.addEvent('hash-changed',this.updateState.bind(this));
	},
	updateState : function (hash){
		var self = this;
		hash = new Hash(JSON.decode(decodeURIComponent(hash)));
		
		this.state.each(function(value,key){
			var nvalue;

			if (hash.has(key)){
				nvalue = hash.get(key);
				self.state.set(key,nvalue);
				self.fireEvent(key+'-changed',nvalue);
			}else{
				nvalue = self.state.get(key);
				self.fireEvent(key+'-removed',nvalue);
				self.state.erase(key);
			}
			
			hash.erase(key);
		});
		
		hash.each(function(value,key){
			self.state.set(key,value);
			self.fireEvent(key+'-added',value);
		});
	},
	set : function(key,value){
		var newState = new Hash(this.state);
		
		newState.set(key,value);

		this.updateHash(newState.toJSON());
		
		return this;
	},
	remove : function(key){
		var newState = new Hash(this.state);
		
		newState.erase(key);
		
		this.updateHash(newState.toJSON());
		
		return this;
	}
});


/*
===========================================
	map class for gg-maps handling
	with loading, moving etc. saved in Hash
===========================================
*/


var HameMap = new Class({

	Implements: [Options],

	options: {
		loadDetail: false,
		detailId: 0,
		urlAddon: "lang=cs",
		loadFiltering: false,
		loadAllMarkers: true,
		showListImmediately: false,
		gridSize: [20, 25, 35],
		maxZoom: [10, 12, 13],
		gps: false,
		storeListLoader: '/map.php?do=table'
	},

	addonFilters: '',
	lastStoreClass: '',

	bubbleCache: [],
	markerCache: {},

	storeElements: false,
	loaderElement: false,
	formularElement: false,

	firstRun: true,
	everLoadedList: false,

	map: null,
	oXml: null,
	manager: null,
	icon: null,

	styles: [],

	stateOfTheMap: {
	},

	storeListLoader: false,
	stateForFirst: false,

	lastStateOfMap: false,

	initialize: function (el, options) {
		var req, a;
		this.setOptions(options);

		this.stateOfTheMap = $H(this.stateOfTheMap);
		this.HM = new HistoryManager({start: false});

		this.HM.addEvent('state-added', this.loadTheState.bind(this));
		this.HM.addEvent('state-changed', this.changeTheState.bind(this));
		this.HM.addEvent('state-removed', this.loadAllMarkersRunner.bind(this));

		if (el && $type(el) === 'object') {
			req = el.id;
		}
		else {
			req = el;
		}
		this.map = new GMap2(document.getElementById(req));
//		this.map.setMapType(G_PHYSICAL_MAP);
		this.map.setUIToDefault();
		this.markerCache = $H();

		this.resetZoom();
		this.initStyles();

		if (this.options.loadDetail) {

			this.map.disableContinuousZoom();
			this.map.disableScrollWheelZoom();
			this.map.disableDragging();
			this.map.disableInfoWindow();
			this.map.disableDoubleClickZoom();

			this.loadDetailMarker();
		}
		else {
//			this.map.addControl(new GLargeMapControl());
//			this.map.addControl(new GMapTypeControl());

			this.map.disableContinuousZoom();
			this.map.disableScrollWheelZoom();

			a = document.getElementById('mapFilterForm');

			this.formularElement = a;

			this.storeElements = $('prodejnyList');

			this.loaderElement = $('filterLoaderAnim');

			if (this.storeElements) {
				this.storeElements = this.storeElements.getChildren('div').addClass('abshide');
				if (!this.storeList) {
					this.storeList = $('prodejnyVypis');
				}
				this.makeAjaxable();
			}
			if (this.loaderElement) {
				this.loaderElement.set('tween', {
					onComplete: function () {
						if (this.element.get('opacity').toInt() === 0) {
							this.element.addClass('hide');
						}
					}
				});
				
				this.loaderElement.fade("out");
				
			}

			if (this.formularElement) {

				this.formularElement.onsubmit = function (event) {
//					console.log('formular.onsubmit = loadFilter');
					this.loadFilter(0, 0, 0, 0);
					return false;
				}.bindWithEvent(this);

				el = $(this.formularElement.parentNode).getElement('p.buttoned');
				if (el) {
					el.adopt(new Element('a', {
						text: $lang.cancelFilter,
						href: '#',
						events: {
							'click': this.resetFilter.bindWithEvent(this)
						}
					}));

					el = el.getElement('input');
					if (el) {
						el.addEvent('click', function (event) {
							event.stop();
//							console.log('formularElement.input.click loadFilter');
							this.loadFilter(0, 0, 0, 0);
							return false;
						}.bindWithEvent(this));
					}
				}
			}

			if (this.options.loadAllMarkers) {
				this.loadAllMarkersRunner();
			}
			else if (this.options.loadFiltering) {
//				console.log('options.loadFiltering');
				this.loadFilter(true, 1, 0, 0);
			}
			if (this.options.showListImmediately) {
				this.options.showListImmediately = this.options.showListImmediately.replace(' ', '-').standardize().toLowerCase();
				el = this.storeElements.filter('div.' + this.options.showListImmediately).shift();
				if (el) {
//					console.log('showListImmediately');
					this.storeClick(false, this.options.showListImmediately, el.getElement('h3').get('text'), 0, 0);
				}
			}
		}

		this.HM.start();

		return this;
	},

	loadAllMarkersRunner: function () {
		req = new Request({
			url: '/map-markers.php' + '?' + this.options.urlAddon,
			'method': 'get',
			onSuccess: this.processMarkersXML.bind(this)
		}).send();
//		this.saveTheState('loadAll', 0);
	},

	runTheState: function (cleanup) {
		if (this.map) {
			this.resetZoom(cleanup);
			if (this.manager && cleanup) {
				this.manager.clearMarkers();
				this.manager.resetViewport();
			}
//			this.map.setCenter(new GLatLng(this.stateOfTheMap.get('y'), this.stateOfTheMap.get('x')), this.stateOfTheMap.get('zoom'));
		}
	},

	changeTheState: function (state) {
		if (this.lastStateOfTheMap != state) {
			this.lastStateOfTheMap = state;
			this.loadTheState(state);
		}
	},

	loadTheState: function (state) {

		if (this.stateForFirst) {
			this.stateForFirst = false;
			return;
		}

		this.stateOfTheMap.set('x', state.x.round(4));
		this.stateOfTheMap.set('y', state.y.round(4));
		this.stateOfTheMap.set('zoom', state.zoom);

		if ($chk(state.sik)) {
			document.getElementById('fInpKraj').selectedIndex = state.sik;
		}
		if ($chk(state.sip)) {
			document.getElementById('fInpProduct').selectedIndex = state.sip;
		}
		if ($chk(state.sis)) {
			document.getElementById('fInpStore').selectedIndex = state.sis;
		}

		if (state.f !== 'storeClick') {
			this.runTheState(true);
		}
		else {
			this.runTheState(false);
		}

		switch (state.f) {
			case "loadAll":
				this.loadAllMarkersRunner(true);
			break;
			case "resetFilter":
				this.resetFilter(false, true);
			break;
			case "storeClick":
			case "loadFilter":
				if (state.f == 'loadFilter') {
					state.p[2].split('&').each(function (el, i) {
						el = el.split('=');
						if (el[0] !== 'store' && el[0] !== 'product') {
							i = this.formularElement.getElement('input[name=' + el[0] + ']');
							if (i) {
								i.set('value', el[1]);
							}
						}
					}, this);
					state.p[3] = true;
					state.p[0] = 0;
					state.p[1] = 0;

					this.addonFilters = state.q;
					this.loadFilter.delay(50, this, state.p);

				}
				else {
					this.addonFilters = state.q;
					state.p[3] = true;
					this.storeClick.delay(50, this, state.p);
				}

//				console.log('running loadFilter in delay');
			break;
		}

	},

	saveTheState: function (fn, param) {
		var ltlg;
		if (this.map) {
			ltlg = this.map.getCenter();

			this.stateOfTheMap.set('x', ltlg.lng().round(4));
			this.stateOfTheMap.set('y', ltlg.lat().round(4));
			this.stateOfTheMap.set('zoom', this.map.getZoom());

			this.stateOfTheMap.set('f', fn);

			switch (fn) {
				case "loadAll":
				case "resetFilter":
					this.stateOfTheMap.set('q', 0);
				break;
				case "loadFilter":
				case "storeClick":
					this.stateOfTheMap.set('p', param);
					this.stateOfTheMap.set('sik', document.getElementById('fInpKraj').selectedIndex);
					this.stateOfTheMap.set('sip', document.getElementById('fInpProduct').selectedIndex);
					this.stateOfTheMap.set('sis', document.getElementById('fInpStore').selectedIndex);
					this.stateOfTheMap.set('q', this.addonFilters);
				break;
			}

			this.HM.set('state', this.stateOfTheMap.getClean());
		}
	},

	makeAjaxable: function () {
		this.storeElements.each(function (oneStore) {
			oneStore.addEvent('click', this.storeClick.bindWithEvent(this, [oneStore.get('class').replace('prodejna', '').replace('abshide', '').clean(), oneStore.getElement('h3').get('text'), 1]));
		}, this);
	},

	cleanUpStoreList: function () {
		if (this.everLoadedList && !this.firstRun) {
			this.storeList.empty();
		}
	},

	filterXML: function (prop, val) {
		var els, el, i, l, markersToPush = [], qq = false, x, xA = [300,-300], yA = [300,-300], latlngbounds;
		els = this.oXml.getElementsByTagName('store');
		if (els) {
			this.storeElements.each(function (storeElementProdejna) {
				if (!storeElementProdejna.hasClass(val)) {
					storeElementProdejna.set('opacity', 0.5);
				}
				else {
					storeElementProdejna.set('opacity', 1);
				}
			});

			for (i = 0, l = els.length; i < l; i++) {
				el = els.item(i);
				if (el.getAttribute(prop) == val) {
					qq = parseInt(el.getAttribute('q'), 10);
					break;
				}
			}

			if (qq !== false) {

				els = this.oXml.getElementsByTagName('p');
				if (els) {
					if (this.manager) {
						this.manager.clearMarkers();
						this.manager.resetViewport();
						this.map.closeInfoWindow();
					}

					for (i = 0, l = els.length; i < l; i++) {
						el = els.item(i);
						if (parseInt((el.getAttribute('q')), 10) == qq) {
							x = el.getAttribute('x').toFloat();
							if (xA[0] > x) {
								xA[0] = x;
							}
							if (xA[1] < x) {
								xA[1] = x;
							}
							x = el.getAttribute('y').toFloat();
							if (yA[0] > x) {
								yA[0] = x;
							}
							if (yA[1] < x) {
								yA[1] = x;
							}
							markersToPush.push(this.returnMarker(el));
						}
					}

					xA.sort();
					yA.sort();

					if (els && els.length > 0) {
						if (markersToPush.length > 0) {
							if (markersToPush.length > 100) {
								chooseProps = 2;
							}
							else if (markersToPush.length > 50) {
								chooseProps = 1;
							}
							else {
								chooseProps = 0;
							}
					
							maxZoom = this.options.maxZoom[chooseProps];
							gridSize = this.options.gridSize[chooseProps];

							this.manager = new MarkerClusterer(this.map, markersToPush, {
								maxZoom: maxZoom,
								gridSize: gridSize,
								styles: this.styles
							});

							if (markersToPush.length > 0) {
								latlngbounds = new GLatLngBounds();
								latlngbounds.extend(new GLatLng(xA[0], yA[0]));
								latlngbounds.extend(new GLatLng(xA[xA.length - 1], yA[yA.length - 1]));
								this.map.setCenter(latlngbounds.getCenter(), (this.map.getBoundsZoomLevel(latlngbounds) - 1).limit(5, 13));
							}
							else {
								this.resetZoom();
							}
						}
					}
				}
			}
		}
	},

	storeClick: function (event, storeClass, storeName, thru, doNotSave) {

		if (event && event.stop) {
			event.stop();
		}
		window.focus();

		if (!doNotSave) {
			this.cleanUpStoreList();
		}

//		console.log('storeClick + storeClass[' + storeClass + '], storeName[' + storeName + '], thru[' + thru + '], doNotSave[' + doNotSave + ']');

		if (storeClass && this.lastStoreClass === storeClass) {
			return false;
		}
		this.lastStoreClass = storeClass;

		if (storeName) {
			if (this.oXml && storeClass) {

				if (this.storeListLoader) {
					this.storeListLoader.cancel();
				}
				this.storeList.setStyle('height', 40);
				this.storeList.set('html', '<h4>' + $lang.loadingStoresList + '</h4>');

				this.filterXML('n', storeClass.replace('abshide', '').replace('hide', '').replace('cb', '').clean());

				if (!doNotSave) {
					this.saveTheState('storeClick', [false, storeClass, storeName, thru, true]);
				}

				this.storeListLoader = new Request.HTML({
					onSuccess: this.storeListLoaderLoaded.bind(this),
					update: this.storeList,
					method: 'post',
					url: this.options.storeListLoader + '&' + this.options.urlAddon + (this.addonFilters ? ('&' + this.addonFilters) : '')
				}).get({
					store: storeName
				});

				thru = false;
			}
			else {
				$("fInpStore").value = storeName;
				this.setFilter();
				if (this.storeListLoader) {
					this.storeListLoader.cancel();
				}

				this.storeList.setStyle('height', 40);
				this.storeList.set('html', '<h4>' + $lang.loadingStoresList + '</h4>');

//				console.log('post: store: ' + storeName);

				this.storeListLoader = new Request.HTML({
					onSuccess: this.storeListLoaderLoaded.bind(this),
					update: this.storeList,
					method: 'post',
					url: this.options.storeListLoader + '&' + this.options.urlAddon + (this.addonFilters ? ('&' + this.addonFilters) : '')
				}).get({store:storeName});
			}
		}

		if (thru) {
//			console.log('thru = 1 :: loadFilter');
			this.loadFilter(0, 1, 0, 0);
		}

		return false;
	},

	storeListLoaderLoaded: function () {
		this.everLoadedList = true;

		this.storeList.getElements('h3').each(function (h3, i) {
			var el, p;
			p = '&minus;';
			el = h3.getNext();
			el.store('h', el.getHeight().toInt());
			if (i > 0 && el.retrieve('h') > 10) {
				el.setStyle('height', 0);
				p = '+';
			}
			h3.addEvent('click', this.h3Click.bind(this, [el, h3]));
			h3.adopt(new Element('span', {
				'html': p
			}));
		}, this);
		
		this.storeList.setStyle('height', 'auto');
	},

	h3Click: function (el, h3) {
		var hh, b;
		b = -1;
		hh = el[0].getStyle('height').toInt();
		if (hh === 0) {
			b = el[0].retrieve('h').toInt();
			el[0].setStyle('height', 1);
		}
		else if (hh == el[0].retrieve('h')) {
			b = 0;
			el[0].setStyle('height', hh - 1);
		}
		if (b !== -1) {
			if (b === 0) {
				el[1].getLast().set('html', '+');
			}
			else {
				el[1].getLast().set('html', '&minus;');
			}
			el[0].tween('height', b);
		}
	},

	initStyles: function () {
		this.styles = [
			{url: '/common/images/map/markers/m1.png', width: 41, height: 40, opt_anchor: [13, 0], opt_textColor: '#FFFFFF'},
			{url: '/common/images/map/markers/m2.png', width: 56, height: 55, opt_anchor: [21, 0], opt_textColor: '#5E2E03'},
			{url: '/common/images/map/markers/m3.png', width: 66, height: 65, opt_anchor: [25, 0], opt_textColor: '#FFFFFF'}
		];

		var icon = new GIcon();
		icon.image = '/common/images/map/markers/image.png';
		icon.iconSize = new GSize(30, 29);
		icon.shadow = '/common/images/map/markers/shadow.png';
		icon.shadowSize = new GSize(45, 29);
		icon.transparent = '/common/images/map/markers/transparent.png';
		icon.iconAnchor = new GPoint(15, 29);
		icon.infoWindowAnchor = new GPoint(13, 15);
		icon.imageMap = [11, 0, 14, 1, 16, 2, 18, 3, 21, 4, 24, 5, 26, 6, 27, 7, 28, 8, 28, 9, 29, 10, 29, 11, 29, 12, 29, 13, 29, 14, 29, 15, 29, 16, 29, 17, 29, 18, 28, 19, 28, 20, 27, 21, 26, 22, 25, 23, 24, 24, 23, 25, 22, 26, 21, 27, 18, 28, 9, 28, 6, 27, 5, 26, 4, 25, 3, 24, 2, 23, 1, 22, 1, 21, 1, 20, 0, 19, 0, 18, 0, 17, 0, 16, 0, 15, 0, 14, 0, 13, 0, 12, 0, 11, 0, 10, 0, 9, 0, 8, 0, 7, 0, 6, 1, 5, 1, 4, 2, 3, 3, 2, 5, 1, 8, 0];
		this.icon = icon;
	},

	loadDetailMarker: function () {
		var m, markers = [];
		this.map.addOverlay(new GMarker(new GLatLng(this.options.gps.x, this.options.gps.y), {
			icon: this.icon
		}));
	},

	processStores: function (stores, maponly) {
		var l, i, store, q;
		this.everLoadedList = true;
//		this.cleanUpStoreList();
		stores = stores.getElementsByTagName('store');
		this.storeElements.addClass('abshide').set('opacity', 1);

		if (stores && stores.length > 0) {
			if (stores.length === 1) {
				this.storeClick(false, false, stores[0].getAttribute('n').substring(0, 1).toUpperCase() + stores[0].getAttribute('n').substring(1), 0, 0);
			}
			else {
				for (i = 0, l = stores.length; i < l; i++) {
					store = stores[i];
					q = this.storeElements.filter('div.' + store.getAttribute('n'));
					if (q) {
						q.removeClass('abshide').getElement('span.n').set('text', store.getAttribute('v'));
					}
				}
			}

		}
		if (this.loaderElement) {
			this.loaderElement.fade("out");
		}
	},

	processMarkersXML: function (txt, xml) {
		var root, markers, latlng, icon, styles, l, i, m;
		this.firstRun = false;
		this.everLoadedList = true;
		this.map.closeInfoWindow();

		if (xml && txt) {
			root = xml.documentElement;
			this.oXml = root;

			if (this.storeElements && this.storeElements.length > 0) {
				this.processStores(root);
			}

			root = root.getElementsByTagName('p');
	
			markers = [];
			
			for (i = 0, l = root.length; i < l; i++) {
				m = this.returnMarker(root[i]);
				markers.push(m);
			}
			if (this.manager) {
				this.manager.clearMarkers();
				this.manager.resetViewport();
				this.map.closeInfoWindow();
			}
			this.manager = new MarkerClusterer(this.map, markers, {
				maxZoom: this.options.maxZoom[2],
				gridSize: this.options.gridSize[2],
				styles: this.styles
			});
//			GEvent.addListener(this.map,"zoomend", this.zoomChange.bind(this));
		}
	},

	returnMarker: function (el, i) {
		var el2 = el, latlng, fn, m;
		if (!i) {
			i = el.getAttribute('id').replace(/[^\d]/g, '');
		}
		latlng = new GLatLng(el2.getAttribute('x'), el2.getAttribute('y'));
		fn = markerClickFn(el2, latlng);
		m = new GMarker(latlng, {
			icon: this.icon
		});
		this.markerCache.set(i, el2);
		GEvent.addListener(m, 'click', fn.bind(this, el.getAttribute('id')));
		return m;
	},

	resetZoom: function (onlyZoom) {
		if (this.options.gps !== false) {
			this.map.setCenter(new GLatLng(this.options.gps.x, this.options.gps.y), 15);
		}
		else {
			this.map.setCenter(new GLatLng(49.9019, 15.3419), 6);
		}
	},

	resetFilter: function (event, doNotSave) {

		if (!doNotSave) {
			this.saveTheState('resetFilter');
		}

		this.addonFilters = '';
		if (this.manager) {
			this.manager.clearMarkers();
			this.manager.resetViewport();
		}
		if (this.formularElement) {
			$(this.formularElement.parentNode).getElements('input[type=text]').setProperty('value', '');
			$(this.formularElement.parentNode).getElements('select').each(function (sel) {
				sel.selectedIndex = 0;
			});
			$(this.formularElement.parentNode).getElements('input[type=checkbox],input[type=radio]').setProperty('checked', false);
		}

		this.cleanUpStoreList();

		if (event) {
			event.stop();
			window.focus();
			return false;
		}
		window.focus();
	},

	setFilter: function (forFirst) {
		var els;

		if (!this.firstRun && this.storeElements) {
			this.storeElements.addClass('abshide');
		}
		if (this.loaderElement) {
			this.loaderElement.removeClass('hide').set('html', '<h3>' + $lang.loadingMapData + '</h3>').fade('in');
		}
		els = $(this.formularElement.parentNode).getElements('#fInpMesto,#fInpKraj');
		if (els && els.length) {
			this.addonFilters = '';
			els = els.filter(function (el) {
				return (el.get('value') !== '');
			});
			if (els && els.length > 0) {
				els = els.map(function (el) {
					return el.get('name') + '=' + encodeURIComponent(el.get('value'));
				});
				this.addonFilters = els.join('&');
			}
		}
	},

	loadFilter: function (forFirst, maponly, queryString, doNotSave) {
		var a;
		this.setFilter(forFirst);

		if (!maponly) {
			this.cleanUpStoreList();
		}

		if (!queryString) {
			queryString = $(this.formularElement.parentNode).toQueryString();
		}

		if (!doNotSave) {
			this.saveTheState('loadFilter', [forFirst, maponly, queryString]);
		}

//		console.log('IN loadFilter');

		if (this.loadFilterRequest) {
			this.loadFilterRequest.cancel();
		}

		a = new Request({
			url : '/map.php?do=filter' + '&' + this.options.urlAddon,
			method : 'post',
			onSuccess : function (txt, xml) {
				this.filterMarkers(xml, txt, maponly);
			}.bind(this)
		}).send(queryString);
		this.loadFilterRequest = a;
	},

	filterMarkers: function (xml, txt, maponly) {
		var datas, chooseProps, i, l, stores, store, q, f, x = [], y = [], markersToAdd, maxZoom, gridSize, latlngbounds;
		this.firstRun = false;

		if (!maponly) {
			this.cleanUpStoreList();
		}

		maxZoom = this.options.maxZoom[2];
		if (!xml && txt) {
			alert($lang.filterFault + txt);
			return;
		}
		else {
			datas = xml.documentElement;

			this.oXml = datas;

			if (!maponly) {
				if (this.storeElements) {
					this.processStores(datas, maponly);
				}
			}

			if (this.loaderElement) {
				this.loaderElement.removeClass('hide').fade('out');
			}

			datas = datas.getElementsByTagName('p');
		}

		if (datas.length < 1) {
			alert($lang.filterNoResults);
			if (this.manager) {
				this.manager.clearMarkers();
				this.manager.resetViewport();
			}
			return;
		}

		markersToAdd = [];
		this.filters = datas;

		if (this.manager && this.markerCache.getLength() > 0) {
			this.manager.resetViewport();
			this.manager.clearMarkers();
		}
		for (i = 0, l = datas.length; i < l; i++) {
			f = datas[i];
			x[i] = f.getAttribute('x');
			y[i] = f.getAttribute('y');
			q = f.getAttribute('id').replace(/[^\d]/g, '').toInt();
			markersToAdd.push(this.returnMarker(this.markerCache.has(q) ? this.markerCache.get(q) : f));
		}

		x.sort();
		y.sort();

		if (markersToAdd.length > 100) {
			chooseProps = 2;
		}
		else if (markersToAdd.length > 50) {
			chooseProps = 1;
		}
		else {
			chooseProps = 0;
		}

		maxZoom = this.options.maxZoom[chooseProps];
		gridSize = this.options.gridSize[chooseProps];

		this.manager = new MarkerClusterer(this.map, markersToAdd, {maxZoom: maxZoom, gridSize: gridSize, styles: this.styles});
		this.manager.resetViewport();

		if (markersToAdd.length > 0) {
			latlngbounds = new GLatLngBounds();
			latlngbounds.extend(new GLatLng(x[0], y[0]));
			latlngbounds.extend(new GLatLng(x[x.length - 1], y[y.length - 1]));
			this.map.setCenter(latlngbounds.getCenter(), (this.map.getBoundsZoomLevel(latlngbounds) - 1).limit(5, 13));
		}
		else {
			this.resetZoom();
		}

	},
	
	resizeBubble: function (b) {
		var infoWindow, point, contentBlock, size;
		// Get the point this infowindow belongs to
		infoWindow = this.map.getInfoWindow();
		point = infoWindow.getPoint();
		contentBlock = $('bubble_p' + b);
		size = contentBlock.getSize();
		infoWindow.reset(point, null, new GSize(size.x, size.y));
	}

});


var ImageEditor = new Class({

	initialize: function (els) {
		if (Browser.Engine.trident) {
			this.canvas = false;
		} else {
			this.canvas = document.createElement('canvas');
			if (this.canvas) {
				this.canvasContext = this.canvas.getContext('2d');
			}
		}
		if (els) {
			this.run(els);
		}
		return this;
	},
	
	run: function (els) {
		if (els) {
			if (!this.canvas) {
				els.each(function (el) {
					this.runIE(el);
				}, this);
			}
			else {
				if (this.canvasContext) {
					els.each(function (el) {
						this.runNonIE(el);
					}, this);
				}
			}
		}
		return this;
	},

	runIE: function (imgObj) {
		imgObj.style.filter = 'progid:DXImageTransform.Microsoft.BasicImage(grayScale=1,opacity=0.70);';
		imgObj.style.zoom = 1;
	},

	runNonIE: function (imgObj) {
		if (!imgObj.complete) {
			this.runNonIE.delay(10, this, imgObj);
			return;
		}
		var i, avg, imgPixels, imgW = imgObj.naturalWidth || imgObj.offsetWidth || imgObj.width, imgH = imgObj.naturalHeight || imgObj.offsetHeight || imgObj.height, canvasContext, canvas, y, x, imgPixels_height, imgPixels_width, imgPixels_heightJeLicha = false, imgPixels_widthJeLicha = false, imgPixels_data_length = 0, imgPixels_height_half, imgPixels_width_half;

		if (this.canvasContext) {
			imgW = imgObj.width;
			imgH = imgObj.height;
			this.canvas.width = imgW;
			this.canvas.height = imgH;
			this.canvasContext.drawImage(imgObj, 0, 0);
			imgPixels = this.canvasContext.getImageData(0, 0, imgW, imgH);

			imgPixels_height = imgPixels.height;
			imgPixels_heightJeLicha = (imgPixels_height % 2);

			imgPixels_width = imgPixels.width;
			imgPixels_widthJeLicha = (imgPixels_width % 2);

			imgPixels_data_length = imgPixels.data.length;

			imgPixels_height_half = Math.ceil(imgPixels_height / 2);
			imgPixels_width_half = Math.ceil(imgPixels_width / 2);

//			for(y = 0; y < imgPixels_height; y++) {
			for (y = 0; y <= imgPixels_height_half; y++) {

//				for(x = 0; x < imgPixels_width; x++) {
				for (x = 0; x <= imgPixels_width_half; x++) {

					i = (4 * y) * imgPixels_width + (4 * x); // A1
					if (i < imgPixels_data_length) {
						avg = parseInt((0.2125 * imgPixels.data[i]) + (0.7154 * imgPixels.data[i + 1]) + (0.0721 * imgPixels.data[i + 2]), 10);// true grayscale
						imgPixels.data[i] = avg;
						imgPixels.data[i + 1] = avg;
						imgPixels.data[i + 2] = avg;
					}

					i = (4 * y) * imgPixels_width + (4 * (imgPixels_width - x)); // A2
					if (i < imgPixels_data_length) {
						avg = parseInt((0.2125 * imgPixels.data[i]) + (0.7154 * imgPixels.data[i + 1]) + (0.0721 * imgPixels.data[i + 2]), 10);// true grayscale
						imgPixels.data[i] = avg;
						imgPixels.data[i + 1] = avg;
						imgPixels.data[i + 2] = avg;
					}

					i = (4 * (imgPixels_height - (y + 1))) * imgPixels_width + (4 * x);// A3
					if (i < imgPixels_data_length) {
						avg = parseInt((0.2125 * imgPixels.data[i]) + (0.7154 * imgPixels.data[i + 1]) + (0.0721 * imgPixels.data[i + 2]), 10);// true grayscale
						imgPixels.data[i] = avg;
						imgPixels.data[i + 1] = avg;
						imgPixels.data[i + 2] = avg;
					}

					i = (4 * (imgPixels_height - (y + 1))) * imgPixels_width + (4 * (imgPixels_width - x));// A4
					if (i < imgPixels_data_length) {
						avg = parseInt((0.2125 * imgPixels.data[i]) + (0.7154 * imgPixels.data[i + 1]) + (0.0721 * imgPixels.data[i + 2]), 10);// true grayscale
						imgPixels.data[i] = avg;
						imgPixels.data[i + 1] = avg;
						imgPixels.data[i + 2] = avg;
					}
				}
			}

			this.canvasContext.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
			imgObj.src = this.canvas.toDataURL();
			imgObj.setOpacity(0.70);
		}
	}
});

var pngFix = new Class({
	options: {
		shim: '/common/images/layout/spacer.gif'
	},
	run: false,

	initialize: function (els) {
		if (Browser.Engine.trident && Browser.Engine.version < 6) {
			this.run = true;
		}
		else {
			this.run = false;
		}
		this.fixIt(els);
		return this;
	},
	fixIt: function (els) {
		if (els && this.run) {
			$$(els).each(function (elem) {
				elem.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + elem.getProperty('src') + "', sizingMethod='crop')").setProperty('src', this.options.shim);
			}, this);
		}
		return this;
	},

	fixBgImg: function (elem) {
		if (elem && this.run) {
			elem.setStyle('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + elem.getStyle('backgroundImage').substring(elem.getStyle('backgroundImage').indexOf('(') + 1, elem.getStyle('backgroundImage').lastIndexOf(')')) + ", sizingMethod='crop')").setStyle('background', 'none');
		}
		return this;
	}
});

var initAll = function () {

	var els, el, tmp, form_validation, imageFiltering, overFce, outFce, overFce2, outFce2, overLi, leaveLi, srch_wht, bubble, advancedFilter, advancedFilterSwitch, boxiesCycle, mouseOverSymbol, mouseOutSymbol, fnAdvancedToggle, checkBothCheckboxes, fnInputClick, vizualCycle;

	var form_validation = new FormValidation({
		default_border : "1px solid #CCCCCC",
		error_border : "1px solid #E80000",
		error_background : "#E80000"
	});



	if (run.hp) {
		overFce = function () {
			this.fade(1);
		};
		outFce = function () {
			this.fade(0.75);
		};
		$$('#product_types a').addClass('invisText').set('opacity', 0.75).set('tween', {
			'link': 'cancel',
			'duration': 300
		}).addEvents({
			'mouseenter': overFce,
			'mouseleave': outFce
		});
		els = $('boxies');
		if (els) {
			boxiesCycle = function (els, i) {
				var oldI = i;
				i += 3;
				i %= 6;
				if (els[i]) {
					els[oldI].fade('out');
					els[i].setStyles({
						'opacity': 0,
						'top': 0
					}).fade('in');
					boxiesCycle.delay(11000, null, [els, i]);
				}
			};
			els = els.getChildren('div');
			if (els && els.length > 3) {
				els[0].getParent().addClass('js');
				(function () {
					boxiesCycle.delay(1000, null, [this, 0]);
					boxiesCycle.delay(6000, null, [this, 1]);
					boxiesCycle.delay(11000, null, [this, 2]);
				}).delay(5000, els);
			}
		}
		
		
		
		els = $('product_types');
		if (els) {

			el = els.getPrevious('div.vizual');
			if (el) {
				els = el.getChildren('img');
				if (els.length === 1) {
					return;
				}
				else {
					els = el.getChildren();
					vizualCycle = function(ex) {
						var elN;
						elN = ex.getNext();
						if (!elN) {
							elN = ex.getParent().getFirst();
						}
						ex.fade('out');
						elN.fade('in');
						vizualCycle.delay(8000, elN, elN);
					};
					el = els.shift();
					els.fade('hide');
					vizualCycle.delay(8000, el, el);
				}
			}
		}
		els = $('flashBannerWrapper');
		if (els && Browser.Plugins.Flash && Browser.Plugins.Flash.version >= 9) {
			els.setStyle("display", "block");
			els = els.getLast();
			el = els.getFirst();
			els = new Swiff(el.data, {
				width: el.width,
				height: el.height,
				callBacks: {
					'closeBanner': function() {
						closeBanner();
					}
				}, vars: {
					'dataPath':'/xml/data.xml'
				},
				params: {
					allowScriptAccess: 'always',
					play: 'true',
					wmode: 'transparent'
				},
				container: els
			});
		}
	}
	if (run.searcher) {
		srch_wht = $$('input.labeled').each(function (el) {
			el.addEvents({
				keyup: function (event) {
					this.getPrevious().addClass('hide');
				},
				keydown: function (event) {
					this.getPrevious().addClass('hide');
				},
				click: function () {
					if (this.get('value') != '') {
						this.getPrevious().addClass('hide');
					}
				},
				focus: function () {
					if (this.get('value') != '') {
						this.getPrevious().addClass('hide');
					}
				},
				blur: function () {
					if (this.get('value') == '') {
						this.getPrevious().removeClass('hide');
					}
					else {
						this.getPrevious().addClass('hide');
					}
				}
			});
			if (el.get('value') != '') {
				el.getPrevious().addClass('hide');
			}
			el.getPrevious().addEvent('click', function () {
				this.addClass('hide');
			});
		});
	}

	if (run.map) {
		els = $('detailProdejny');
		if (els) {
			els = new pngFix('#detailProdejny div.prodejnaProdukty img[src$=png]');
		}
	}

	if (run.category) {

		els = new pngFix('#products img[src$=png]');
		bubble = new Element('span', {
			'id': 'bubbleInfoSymbol',
			styles: {
				'marginTop': 35,
				'left': -500,
				'top': -500,
				'opacity': 0
			}
		}).set('html', '<span class="bg"></span><span class="fg"></span>').set('morph', {
			'duration': 500,
			'link': 'cancel'
		}).inject(document.id(document.body));

//		els.fixBgImg(bubble.getFirst());

		mouseOverSymbol = function (event) {
			var pos = {x: 0, y: 0}, mTop = 26;
			if (event.target.tagName.toLowerCase() === 'li' || event.target.tagName.toLowerCase() === 'span') {
				if (event.target.tagName.toLowerCase() === 'span') {
					event.target = event.target.parentNode;
					mTop = 52;
				}
				event.target = $(event.target);
				this.getLast().set('text', event.target.get('text'));
				pos = event.target.getPosition();
				this.setStyles({
					'left': pos.x,
					'top': pos.y
				});
				if (Browser.Engine.trident) {
					this.setStyle('marginTop', mTop).set('opacity', 1);
				}
				else {
					this.morph({
						'marginTop': mTop,
						'opacity': 1
					});
				}
			}
			event.stop();
		};
		mouseOutSymbol = function (event) {
			if (event.target.tagName.toLowerCase() === 'li' || event.target.tagName.toLowerCase() === 'span') {
				if (Browser.Engine.trident) {
					this.set('opacity', 0);
				}
				else {
					this.morph({'marginTop': ((event.target.parentNode.parentNode.id === 'productDetailIcos' || event.target.parentNode.id === 'productDetailIcos') ? 70 : 35), 'opacity': 0});
				}
			}
		};
		els = $$('#products ul,#productImage ul').addEvents({'mouseover': mouseOverSymbol.bindWithEvent(bubble), 'mouseout': mouseOutSymbol.bindWithEvent(bubble)});
		advancedFilter = $('advancedFilter');
		if (advancedFilter) {
			fnAdvancedToggle = function (event) {
				if (event && $type(event) !== 'number') {
					event.stop();
					if (event.target.href) {
						event.target.blur();
					}
				}
				if (!event || advancedFilter.getStyle('height').toInt() > 0) {
					advancedFilter.tween('height', 0);
					advancedFilterSwitch.set('text', advancedFilterSwitch.retrieve('switchText'));
				}
				else {
					advancedFilter.tween('height', advancedFilter.getFirst().getHeight());
					advancedFilterSwitch.set('text', $lang.closeAdvanced);
				}
			};
			advancedFilter.set('tween', {
				'duration': 500,
				'transition': 'sine:in:out',
				'link': 'cancel',
				'onStart': function () {
					if (this.element.hasClass('opened')) {
						this.element.getElements('input').set('disabled', 'disabled');
					}
					else {
						this.element.getElements('input').removeProperty('disabled');
					}
				},
				'onComplete': function () {
					if (this.element.getStyle('height').toInt() > 0) {
						this.element.addClass('opened').getElements('input').removeProperty('disabled');
					}
					else {
						this.element.removeClass('opened').getElements('input').set('disabled', 'disabled');
					}
				}
			});
			advancedFilterSwitch = $('advancedFilterSwitch');
			advancedFilterSwitch.addEvent('click', fnAdvancedToggle.bindWithEvent()).store('switchText', advancedFilterSwitch.get('text'));

			checkBothCheckboxes = function (t) {
				if (t.id.indexOf('2') !== -1) {
					if (t.checked) {
						t = $(t.id.substr(0, t.id.length - 1));
						if (t) {
							t.setProperty('checked', false);
						}
					}
				}
				else {
					if (t.checked) {
						t = $(t.id + '2');
						if (t) {
							t.setProperty('checked', false);
						}
					}
				}
			};
			fnInputClick = function (event) {
				checkBothCheckboxes(event.target);
			};
			if (advancedFilter.getElements('input').addEvent('click', fnInputClick.bindWithEvent()).some(function (el) {
				return !!el.checked;
			})) {
				fnAdvancedToggle(1);
			}
			else {
				fnAdvancedToggle(false);
			}
		}
	}

	if (run.filtering || run.category) {
		el = $('filtering');
		if (el) {
			if (el.get('tag') !== 'form') {
				el = el.getElement('form');
			}
			el.addEvent('submit', function (event) {
				var elX;
				elX = this.getElement('input.redirecter:checked');
				if (elX) {
					elX = elX.getAttribute('rel') || elX.getProperty('rel') || elX.rel;
					if (elX) {
						this.setProperties({'action': elX + '.html?' + this.toQueryString(), method: 'post'});
					}
				}
				else {
					this.setProperty('action', ((this.getProperty('action').indexOf('?') > -1) ? window.location.href.split('?').shift() : this.getProperty('action').split('?').shift() + '?') + '?' + this.toQueryString());
				}
			});
		}
	}

	if (run.textual) {
		els = $$('#rcol ul.boxCats li span');
		if (els && els.length > 0) {
			imageFiltering = [];
			els.each(function (el) {
				var h = el.getHeight();
				if (h < 20) {
					el.tween('paddingTop', 7);
				}
				else if (h > 32) {
					el.setStyle('fontSize', 10);
				}
				if (el.parentNode.parentNode.className.indexOf('active') === -1) {
					imageFiltering.push(el.parentNode.getElementsByTagName('img')[0]);
				}
			});

/*
=========================================
=== TODO start --- uncomment for LIVE ===
=========================================
*/
			els = new ImageEditor(imageFiltering);
/*
-------------TODO END --------------------------
*/

		}
	}

	el = $$('a.targetblank');
	if (el && el.length > 0) {
		el.set('target', '_blank');
	}
	el = $('fLayers');
	if (el) {
		el.getElement('h3').addEvent('click', function () {
			this.getParent().toggleClass('hovered');
		});
	}
	if (run.map) {
		if (makeMap) {
			makeMap();
		}
		el = $('detailProdejny');
		if (el) {
			overLi = function () {
				this.addClass('hovered');
			};
			leaveLi = function () {
				this.removeClass('hovered');
			};
			el = el.getElement('div.prodejnaProdukty');
			if (el) {
				el = el.getElement('ul').getChildren();
				el.each(function (li) {
					if (li.offsetHeight > 26) {
						li.addClass('doubleLine');
					}
					if (Browser.Engine.trident4 || Browser.Engine.trident5) {
						li.addEvents({mouseenter: overLi, mouseleave: leaveLi});
					}
				});
				if (el && el.length > 0) {
				}
			}
		}
	}
	els = $$('a.targetblank');
	if (els && els.length > 0) {
		els.setProperty('target', '_blank');
	}

	els = $$('p.printLinkIn');
	if (els && els.length > 0) {
		els.adopt(new Element('a', {
			'href': '#',
			'class': 'print',
			'id': 'printPreview',
			'text': $lang.printPreview,
			events: {
				'click': function () {
					var screenPreviewEl, tm;
					$$('link[media="print"]').setProperty('media', 'print, screen');
					$$('link[media="screen"]').setProperty('media', 'disable');
					screenPreviewEl = $('screenPreview');
					if (!screenPreviewEl) {
						tm = new Element('a', {
							events: {
								'click': function () {
									screenPreview();
									return false;
								}
							},
							'id': 'screenPreview',
							'href': '#',
							'text': $lang.printPreviewClose
						}).inject(document.id(document.body), 'top');
					}
					else {
						screenPreviewEl.removeClass('hide');
					}
					return false;
				}
			}
		}));
	}
/*
	els = $$('form.form-validation');
	if (els && els.length > 0) {
		form_validation = new FormValidation({
			default_border : '1px solid #408EC3'
		});
	}
*/


						/* discussion */

	if($$(".discussion .reply").length > 0){
		$$(".discussion .reply").addEvent("click", function(){
			var parent_id = parseInt(this.id.replace("d_", ""));
			if($("discussion_reply_id")){
				$("discussion_reply_id").value = parent_id;
			}
			return false;
		});
	}
	
	if($("add_new_discussion")){
		$("add_new_discussion").addEvent("click", function(){
			var parent_id = 0;
			if($("discussion_reply_id")){
				$("discussion_reply_id").value = parent_id;
			}
			return false;
		});
	}

          	/* xbox */
  if($$("a.xbox").length > 0 || $$("a.htmlbox").length > 0){
		var x_box = new XBox();
	} 

	          /* ring */
	if($("promobox_wheel")){
	  var ring = new Ring({
	    id : "promobox_wheel",
	    slider : "promobox_wheeler",
	    navi_id : "promobox_nav",
	    delay : 4500
	  }); 
	}

						/* consulting_list */

	if($$(".consulting_list .item .author").length > 0){
		$$(".consulting_list .item .author").each(function(item, index){
		
			item.getPrevious().setStyle("height", "auto");
			item.getPrevious().id = "h_" + item.getPrevious().getHeight();
			if(item.getParent().getParent().hasClass("first")){
				item.getPrevious().setStyle("height", "auto");
			} else {
				item.getPrevious().setStyle("height", 0);			
			}

			item.addEvent("click", function(){
				var temp_height = parseInt(this.getPrevious().id.replace("h_", ""));
				if(this.getParent().getParent().hasClass("act")){
					this.getPrevious().tween("height", temp_height, 0);
				} else {					
					this.getPrevious().tween("height", 0, temp_height);
				}
				this.getParent().getParent().toggleClass("act");
			});
		});
	}


	els = $$('input.dateInput');
	if (els && els.length > 0) {
		tmp = new DatePicker(els, {
			pickerClass: 'datepicker_vista',
			days: $lang.datePickerDays,
			months: $lang.datePickerMonths,
			monthShort: 3,
			allowEmpty: true,
			startDay: 1,
			positionOffset: {x: -35, y: 0},
			format: 'd.m.Y',
			inputOutputFormat: 'd.m.Y'
		}, $('global'));
	}

	els_2 = $$('input.calendarInput');
	if (els_2 && els_2.length > 0) {
		tmp_2 = new DatePicker(els_2, {
			pickerClass: 'datepicker_vista',
			days: $lang.datePickerDays,
			months: $lang.datePickerMonths,
			monthShort: 3,
			allowEmpty: true,
			startDay: 1,
			positionOffset: {x: -35, y: 0},
			format: 'd.m.Y',
			inputOutputFormat: 'Y-m-d'
		}, $('global'));
	}

	window.focus();

};

function AddTwitter(l) {
	l.target = '_blank';
	l.href = 'http://twitter.com/home?status=' + encodeURIComponent(document.title + ' - ' + window.location.hostname) + ' - ' + encodeURIComponent(window.location.protocol + '//' + window.location.hostname + window.location.pathname);
}

function AddFacebook(l) {
	l.target = '_blank';
	l.href = 'http://www.facebook.com/sharer.php?t=' + encodeURIComponent(document.title + ' - ' + window.location.hostname) + '&u=' + encodeURIComponent(window.location.protocol + '//' + window.location.hostname + window.location.pathname);
}

function AddLinkuj(l) {
	l.target = '_blank';
	l.href = 'http://linkuj.cz/?id=linkuj&title=' + encodeURIComponent(document.title + ' - ' + window.location.hostname) + '&url=' + encodeURIComponent(window.location.protocol + '//' + window.location.hostname + window.location.pathname);
}


/*popoptions*/
