	//General JavaScript & Ajax file [jQuery compatible]
	//Copyright Eurograf.pl 2011 - All rights reserved

	//Setup variables
   	var openedCommentId = '';
	var openedCommentFormId = '';
	var openedPostId = '';
	var postDisplayEffect = 'fast';

	//Helpers Functions
	function randomString() {
		var list = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
		var string = '';
		for (i = 0; i < 40; i++) {
			string += list.charAt(Math.floor(Math.random()*list.length));
		}
		return string;
	}

	function randValue() {
		return Math.round(Math.random() * 10000000000000000);
	}

	function countElements(elem) {
		var i = 0;
		$.each(elem, function() {
			i++;
		});
		return i;
	}

	function isValidEmail(email) {
		var RegexEmail = /^[0-9a-zA-Z._-]+\@[0-9a-zA-Z._-]+\.[0-9a-zA-Z.]+$/;
		return RegexEmail.test(email);
	}

	function iskValidUrl(url) {
		var RegexUrl = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
		return RegexUrl.test(url);
	}
	
	function removeCharacters(string) {
		var search_array = new Array('<', '>', '~', '`', '!', '?', '/', '\\', '\'', '"', '@', '#', '€', '$', '%', '^', '&', '*', '(', ')', '=', '+', '-', '[', ']', '{', '}', ':', ';', '|', ',', '.', ' ', 'ą', 'ę', 'ż', 'ź', 'ć', 'ń', 'ó', 'ł', 'ś', 'Ą', 'Ę', 'Ż', 'Ź', 'Ć', 'Ń', 'Ó', 'Ł', 'Ś', '¶', '±', 'Ľ', 'ˇ', '¬', '¦');
		var replace_array = new Array('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '_', '', '', '', '', '_', '_', '', '', '', '', '', '', '', '', '', '_', 'a', 'e', 'z', 'z', 'c', 'n', 'o', 'l', 's', 'A', 'E', 'Z', 'Z', 'C', 'N', 'O', 'L', 'S', 's', 'a', 'z', 'Z', 'A', 'S');
		var search = [].concat(search_array);
		var replace = [].concat(replace_array)
		var i = (string = [].concat(string)).length;
		while(j = 0, i--) {
			while(string[i] = string[i].split(search[j]).join(replace[j] || ''), ++j in search);
		}
		return string;
	}

	//When page ready
	$(document).ready(function() {

		imagesPreloader();
		timer();

		//Form input values swap
		$('#search_string, #newsletter_email').focus(function() {
			$(this).val(($(this).val() == $(this).attr('title'))? '' : $(this).val());
		});
		$('#search_string, #newsletter_email').blur(function() {
			$(this).val(($(this).val() != '')? $(this).val() : $(this).attr('title'));
		});

		//Mini Gallery
		/*
		$('#mini_gallery').innerfade({
			speed: 700,
			timeout: 5000,
			type: 'sequence',
		});
		*/

		//Cycle plugin
		/*
		$('#element').cycle({
			speed: 1000,
			timeout: 3500,
			random: 1
		});
		*/

		//Slides plugin
		/*
		$('#element').slides({
			play: 4500,
			preload: true,
			preloadImage: '/application/images/layout/loading.gif'
		});
		*/
		
		//FB slide
		/*
		$('.facebook').hover(function() {
			$(this).stop(true, false).animate({left:'0'},'medium');
		},function() {
			$(this).stop(true, false).animate({left:'-225'},'medium');
		},500);
		*/

	});

	//Main functions
	function imagesPreloader() {
		if (document.images) {
			var imagesEmots = new Array('icon_biggrin.gif', 'icon_confused.gif', 'icon_cool.gif', 'icon_eek.gif', 'icon_evil.gif', 'icon_lol.gif', 'icon_mad.gif', 'icon_mrgreen.gif', 'icon_neutral.gif', 'icon_razz.gif', 'icon_redface.gif', 'icon_rolleyes.gif', 'icon_sad.gif', 'icon_smile.gif', 'icon_twisted.gif', 'icon_wink.gif');
			var imagesSite = new Array('loading.gif', 'loading2.gif', 'loading_small.gif');
			var imagesEmotsObject = new Array();
			var imagesSiteObject = new Array();
			$.each(imagesEmots, function(key, item) {
				imagesEmotsObject[key] = new Image();
				imagesEmotsObject[key].src = '/application/images/emots/' + item;
			});
			$.each(imagesSite, function(key, item) {
				imagesSiteObject[key] = new Image();
				imagesSiteObject[key].src = '/application/images/layout/' + item;
			});
		}
	}

	function displayImage(url, width, height) {
		var newWindow = window.open(url, randValue(), 'width=' + width + ', height='+ height + ', resizable=no, scrollbars=no, menubar=no, status=no, toolbar=no');
		newWindow.focus();
	}

	function displayWindow(url, width, height) {
		var newWindow = window.open(url, randValue(), 'width=' + width + ', height=' + height + ', resizable=no, scrollbars=yes, menubar=no, status=no, toolbar=no');
		newWindow.focus();
	}

	function displayPopup(url) {
		var newWindow = window.open(url, randValue(), 'width=1, height=1, resizable=no, scrollbars=yes, menubar=no, status=no, toolbar=no');
		newWindow.focus();
	}

	function windowResize(width, height) {
		window.resizeTo(width + 30, height + 60 - ((navigator.appName == 'Netscape')? 10 : 0));
		self.focus();
	}

	function commentsDisplay(comment_id, order_marker) {
		if ((openedCommentId != '') && (openedCommentId == comment_id)) {
			$('#comment_for_id_' + openedCommentId).hide(postDisplayEffect);
			$('#comment_for_id_' + openedCommentId).empty();
			openedCommentId = '';
		}
		else if ((openedCommentId != '') && (openedCommentId != comment_id)) {
			$('#comment_for_id_' + openedCommentId).hide(postDisplayEffect);
			$('#comment_for_id_' + openedCommentId).empty();
			commentsGet(comment_id, order_marker);
			$('#comment_for_id_' + comment_id).show(postDisplayEffect);
			openedCommentId = comment_id;
		} else {
			commentsGet(comment_id, order_marker);
			$('#comment_for_id_' + comment_id).show(postDisplayEffect);
			openedCommentId = comment_id;
		}
	}

	function commentsParse(xml) {
		var output_tags = '';
		var comments = xml.getElementsByTagName('comment_item');
		for(i = 0; i < comments.length; ++i) {
			output_tags += '<div class="comment_content"> <b class="comment_who">Napisany przez: ' + comments[i].getElementsByTagName('author')[0].childNodes[0].nodeValue + ' | Dodano: ' + comments[i].getElementsByTagName('add_time')[0].childNodes[0].nodeValue + '</b>';
			output_tags += '<div class="comment_tresc">' + commentsInsertEmoticons(comments[i].getElementsByTagName('comment')[0].childNodes[0].nodeValue.replace(/\n/g, '<br>')) + '</div></div>';
			output_tags += '<div style="height: 1px; padding: 5px 0px 5px 0px; float:none; margin-bottom:10px;"></div>';
		}
		return output_tags;
	}

	function commentsGet(id, order_marker) {
		$.ajax({
			url: '/ajax/comments/index/' + id + '/' + order_marker,
			type: 'GET',
			cache: false,
			dataType: 'xml',
			beforeSend: function(){$('#comment_for_id_' + id).html('<div align="center">Ładowanie komentarzy<br>Proszę czekać...<br><img border="0" src="/application/images/layout/loading2.gif" width="160" height="5" /></div>');},
			error: function(){$('#comment_for_id_' + id).html('<div align="center">Brak połączenia z serwerem.</div>');},
			success: function(xml){$('#comment_for_id_' + id).html(commentsParse(xml)); commentsAnchorJump(id);}
		});
	}

	function commentsAnchorJump(anchor_id) {
		window.location.hash = 'post_jump_' + anchor_id;
		return false;
	}

	function commentsInsertEmoticons(string) {
		var textEmoticons = new Array(':D',':d',':?','8)',':shock:',':evil:',':lol:',':x',':mrgreen:',':|',':P',':p',':oops:',':roll:',':(',':)',':twisted:',':wink:');
		var imgEmoticons = new Array('icon_biggrin.gif','icon_biggrin.gif','icon_confused.gif','icon_cool.gif','icon_eek.gif','icon_evil.gif','icon_lol.gif','icon_mad.gif','icon_mrgreen.gif','icon_neutral.gif','icon_razz.gif','icon_razz.gif','icon_redface.gif','icon_rolleyes.gif','icon_sad.gif','icon_smile.gif','icon_twisted.gif','icon_wink.gif');
		var newImgEmoticons = new Array();
		$.each(imgEmoticons, function(key, item) {
			newImgEmoticons[key] = '<img border="0" src="/application/images/emots/' + item + '" width="19" height="19" align="absmiddle" />';
		});
		var search = [].concat(textEmoticons);
		var replace = [].concat(newImgEmoticons);
		var i = (string = [].concat(string)).length;
		while(j = 0, i--) {
			while(string[i] = string[i].split(search[j]).join(replace[j] || ''), ++j in search);
		}
		return string;
	}

	function commentAdd(comment_form_id, comment_form_order) {
		if ((openedCommentFormId != '') && (openedCommentFormId == comment_form_id)) {
			$('#comment_form_id_' + openedCommentFormId).hide(postDisplayEffect);
			$('#comment_form_id_' + openedCommentFormId).empty();
			openedCommentFormId = '';
		}
		else if ((openedCommentFormId != '') && (openedCommentFormId != comment_form_id)) {
			$('#comment_form_id_' + openedCommentFormId).hide(postDisplayEffect);
			$('#comment_form_id_' + openedCommentFormId).empty();
			commentInsertForm(comment_form_id, comment_form_order);
			$('#comment_form_id_' + comment_form_id).show(postDisplayEffect);
			openedCommentFormId = comment_form_id;
		} else {
			commentInsertForm(comment_form_id, comment_form_order);
			$('#comment_form_id_' + comment_form_id).show(postDisplayEffect);
			openedCommentFormId = comment_form_id;
		}
	}

	function commentInsertForm(comment_form_id, comment_form_order) {
		var output_form = '';
		output_form += '<form id="send_form_ajax" name="send_comment" action="/ajax/add_comment/index" method="post">\n';
		output_form += '<input type="hidden" name="item_id\" value="' + comment_form_id + '">\n';
		output_form += '<input type="hidden" name="item_order\" value="' + comment_form_order + '">\n';
		output_form += '<div class="emots">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_biggrin.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':)\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_confused.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':?\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_cool.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\'8)\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_eek.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':shock:\');" style="cursor: pointer">\n';
		output_form += '<br>\n';
		output_form += '<img border="0" src="/application/images/emots/icon_evil.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':evil:\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_lol.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':lol:\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_mad.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':x\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_mrgreen.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':mrgreen:\');" style="cursor: pointer">\n';
		output_form += '<br>\n';
		output_form += '<img border="0" src="/application/images/emots/icon_neutral.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':|\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_razz.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':P\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_redface.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':oops:\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_rolleyes.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':roll:\');" style="cursor: pointer">\n';
		output_form += '<br>\n';
		output_form += '<img border="0" src="/application/images/emots/icon_sad.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':(\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_smile.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':)\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_twisted.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':twisted:\');" style="cursor: pointer">\n';
		output_form += '<img border="0" src="/application/images/emots/icon_wink.gif" width="19" height="19" onclick="javascript:commentFormEmoticon(\':wink:\');" style="cursor: pointer">\n';
		output_form += '</div>\n';
		output_form += '<div class="text_comments">\n';
		output_form += '<b>Nick:</b><br /><input class="form_comments" type="text" name="author" value="" maxlength="32"><br />\n';
		output_form += '<b>Treść komentarza:</b><br /><textarea class="form_comments_text" name="comment" wrap="virtual"></textarea><br />';
		output_form += '</div>';
		output_form += '<table class="comments_code">';
		output_form += '<tr>';
		output_form += '<td><b>Przepisz kod: </b></td>';
		output_form += '<td><div id="captcha"></div></td>';
		output_form += '<td>\n';
		output_form += '<input class="form_code_text" type="text" id="code" name="code" maxlength="6"></td>';
		output_form += '<td><input class="submit" style="cursor: pointer;" type="button" name="submit" value="Wyślij" onclick="commentFormSend();"></td>';
		output_form += '</tr>\n';
		output_form += '</table>\n';
		output_form += '<div id="comment_info" class="txt_alert" style="clear: both; text-align: center; padding-top: 10px"></div>\n';
		output_form += '</form>\n';
		output_form += '<div class="line" />\n';
		$('#comment_form_id_' + comment_form_id).html(output_form);
		setTimeout("insertCaptcha();", 200);
	}

	function commentFormResponse(responseXML) {
		var comment_attributes = responseXML.getElementsByTagName('comment')[0];
		var item_id = comment_attributes.getAttribute('item_id');
		var item_order = comment_attributes.getAttribute('item_order');
		var errors = comment_attributes.getAttribute('errors');
		if(errors == 1) {
			var errors_string = responseXML.getElementsByTagName('error')[0].childNodes[0].nodeValue.replace(/@/g, '<br />');
			$('#comment_info').html('<span class="red">' + errors_string + '</span>');
			insertCaptcha();
		} else {
			$('#comment_info').empty();
			$('#comment_form_id_' + item_id).empty();
			openedCommentFormId = '';
			var item_counter = parseInt($('#comment_counter_id_' + item_id).text()) + 1;
			$('#comment_link_id_' + item_id).html('<a href="javascript:;" onclick="commentsDisplay(' + item_id + ', \'' + item_order + '\')">Komentarze (<span id="comment_counter_id_' + item_id + '">' + item_counter + '</span>)</a>');
			openedCommentId = '';
			commentsDisplay(item_id, item_order);
		}
	}

	function insertCaptcha() {
		$('#code').empty();
		$('#captcha').css('background', 'url(/ajax/image_code/index/' + randomString() + ') no-repeat');
	}

	function commentFormSend() {		
		$.ajax({
			url: '/ajax/add_comment/index/',
			type: 'POST',
			dataType: 'xml',
			data: $('#send_form_ajax').serialize(),
			beforeSend: function(){$('#comment_info').html('<div align="center">Proszę czekać...<br><img border="0" src="/application/images/layout/loading2.gif" width="160" height="5" /></div>');},
			error: function(){$('#comment_info').html('<div align="center">Brak połączenia z serwerem.</div>');},
			success: function(xml){commentFormResponse(xml);}
		});
	}

	function commentFormEmoticon(text) {
		var txtarea = document.send_comment.comment;
		text = ' ' + text + ' ';
		if (txtarea.createTextRange && txtarea.caretPos) {
			var caretPos = txtarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
			txtarea.focus();
		} else {
			txtarea.value  += text;
			txtarea.focus();
		}
	}

	function postDisplay(post_id) {
		if ((openedPostId != '') && (openedPostId == post_id)) {
			$('#post_id_' + openedPostId).hide(postDisplayEffect);
			$('#post_display_label_' + openedPostId).html('Czytaj całość');
			openedPostId = '';
		} else if ((openedPostId != '') && (openedPostId != post_id)) {
			$('#post_id_' + openedPostId).hide(postDisplayEffect);
			$('#post_display_label_' + openedPostId).html('Czytaj całość');
			$('#post_id_' + post_id).show(postDisplayEffect);
			$('#post_display_label_' + post_id).html('Ukryj treść');
			postAnchorJump(post_id);
			openedPostId = post_id;
		} else {
			$('#post_id_' + post_id).show(postDisplayEffect);
			$('#post_display_label_' + post_id).html('Ukryj treść');
			postAnchorJump(post_id);
			openedPostId = post_id;
		}
	}

	function postAnchorJump(anchor_id) {
		window.location.hash = 'post_jump_' + anchor_id;
	}

	function timer() {
		if($('#date') != null) {
			var date = new Date();
			var minutes = (date.getMinutes() < 10)? '0' + date.getMinutes() : date.getMinutes();
			var secounds = (date.getSeconds() < 10)? '0' + date.getSeconds() : date.getSeconds();
			$('#date').html('dziś jest: '+ date.getDate() + '.' + (date.getMonth() + 1) + '.' + date.getFullYear() + ', godz. ' + date.getHours() + ':' + minutes + ':' + secounds);
			setTimeout('timer()', 1000);
		}
	}

	function newsletterFormResponse(responseObj) {
		$('#newsletter_message').show().text((responseObj.status != undefined)? responseObj.status : 'Błąd zapisu adresu do bazy, prosimy spróbować ponownie').delay(2000).fadeOut(1000);
	}

	function newsletterFormSend() {
		$.ajax({
			url: '/ajax/newsletter/index/',
			type: 'POST',
			dataType: 'json',
			data: $('#newsletter_email_form').serialize(),
			error: function(){$('#newsletter_message').html('Brak połączenia z serwerem.');},
			success: function(response){newsletterFormResponse(response);}
		});
	}

	function calendarBuild(calendarXML) {
		var calendarAttributes = calendarXML.getElementsByTagName('calendar')[0];
		var monthDays = calendarAttributes.getAttribute('month_days');
		var startMonthDay = calendarAttributes.getAttribute('start_month_day');
		var sessionMonth = calendarAttributes.getAttribute('session_month');
		var sessionYear = calendarAttributes.getAttribute('session_year');
		var events = calendarXML.getElementsByTagName('event_item');
		var eventsArray = new Array();
		for(i = 0; i < events.length; ++i) {
			eventsArray[events[i].getElementsByTagName('day')[0].childNodes[0].nodeValue] = (eventsArray[events[i].getElementsByTagName('day')[0].childNodes[0].nodeValue] == undefined)? events[i].getElementsByTagName('title')[0].childNodes[0].nodeValue + '::' + events[i].getElementsByTagName('item_id')[0].childNodes[0].nodeValue + '::' + events[i].getElementsByTagName('site_id')[0].childNodes[0].nodeValue + '::' + events[i].getElementsByTagName('textual_id')[0].childNodes[0].nodeValue : eventsArray[events[i].getElementsByTagName('day')[0].childNodes[0].nodeValue] + '@@' + events[i].getElementsByTagName('title')[0].childNodes[0].nodeValue + '::' + events[i].getElementsByTagName('item_id')[0].childNodes[0].nodeValue  + '::' + events[i].getElementsByTagName('site_id')[0].childNodes[0].nodeValue + '::' + events[i].getElementsByTagName('textual_id')[0].childNodes[0].nodeValue;
		}
		var dayShortNames = new Array('Pn', 'Wt', 'Sr', 'Cz', 'Pt', 'So', 'Nd');
		var monthNames = new Array('stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca', 'lipca', 'sierpnia', 'września', 'października', 'listopada', 'grudnia');
		var startPrintDay = 1;
		var startCountDay = 1;
		var rows = Math.ceil((parseInt(monthDays) + parseInt(startMonthDay) - 1) / 7);
		var table = document.createElement('table');
		table.setAttribute('border', '0');
		table.setAttribute('cellpadding', '1');
		table.setAttribute('cellspacing', '2');
		var tableBody = document.createElement('tbody');
		var tableRowTh = document.createElement('tr');
		for(var i = 0; i < 7; i++) {
			var tableCell = document.createElement('td');
			tableCell.setAttribute('align', 'center');
			tableCell.className = 'th';
			var tableCellText = document.createTextNode(dayShortNames[i]);
			tableCell.appendChild(tableCellText);
			tableRowTh.appendChild(tableCell);
		}
		tableBody.appendChild(tableRowTh);
		for(var j = 0; j < rows; j++) {
			var tableRow = document.createElement('tr');
			for(var i = 0; i < 7; i++) {
				var tableCell = document.createElement('td');
				tableCell.setAttribute('align', 'center');
				tableCell.className = (i == 6)? 'sunday' : 'normal';
				tableCell.className = (i == 5)? 'saturday' : tableCell.className;
				if((startCountDay < parseInt(startMonthDay)) || (printDay > parseInt(monthDays) -1)) {
					var tableCellText = document.createTextNode('');
					tableCell.appendChild(tableCellText);
				} else {
					var printDay = startPrintDay;
					if(eventsArray[printDay] == undefined) {
						var tableCellText = document.createTextNode(printDay);
						var tableCellDiv = document.createElement('div');
						if((startPrintDay == currentDay) && (currentMonth == sessionMonth) && (currentYear == sessionYear)) {
							tableCellDiv.className = 'today_marker_div';
						}
						tableCellDiv.appendChild(tableCellText);
						tableCell.appendChild(tableCellDiv);
					} else {
						var insertEvent = '';
						var insertEventSeparator = '';
						var separatorI = 1;
						var eventsDaily = eventsArray[printDay].split('@@');
						$.each(eventsDaily, function(event_key, item) {
							var eventTitleId = item.split('::');
							insertEventSeparator = (eventsDaily.length > separatorI)? '<br />' : '';
							insertEvent += separatorI + '. ' + eventTitleId[0] + ' - <a href=\'/site/' + eventTitleId[3] + '/n/1/' + eventTitleId[1] + '/n\' target=\'_top\'>więcej szczegółów</a>' + insertEventSeparator;
							separatorI++;
						});
						var tableCellText = document.createTextNode(printDay);
						var tableCellAnchor = document.createElement('a');
						var tableCellDiv = document.createElement('div');
						tableCellAnchor.setAttribute('href', 'javascript:;');
						tableCellAnchor.setAttribute('title', '<strong>Wydarzenia w dniu ' + printDay + ' ' + monthNames[sessionMonth - 1] + ' ' + sessionYear + '</strong><br /><br />' + insertEvent);
						tableCellAnchor.className = (i == 6)? 'sunday' : 'normal';
						tableCellAnchor.className = (i == 5)? 'saturday' : tableCell.className;
						tableCellDiv.className = ((startPrintDay == currentDay) && (currentMonth == sessionMonth) && (currentYear == sessionYear))? 'today_marker_event_div' : 'marker_event_div';
						tableCellAnchor.appendChild(tableCellText);
						tableCellDiv.appendChild(tableCellAnchor);
						tableCell.appendChild(tableCellDiv);
					}
					startPrintDay++;
				}
				startCountDay++;
				tableRow.appendChild(tableCell);
			}
			tableBody.appendChild(tableRow);
		}
		table.appendChild(tableBody);
		$('#calendar').empty();
		$('#calendar').html(table);
		$.bt.options = {
			trigger: 'click',
			closeWhenOthersOpen: true,
			width: '350px',
			shrinkToFit: true,
			fill: "rgb(238, 238, 238)",
			strokeWidth: 1,
			strokeStyle: "#666",
			centerPointX: .9,
			centerPointY: .5,
			positions: ['top']
		};
		$('#calendar').find('a').bt();
		calendarNav(sessionMonth, sessionYear);
	}

	function calendar(month, year) {
		$.ajax({
			url: '/ajax/calendar_events/index/' + month + '/' + year,
			type: 'GET',
			cache: false,
			dataType: 'xml',
			beforeSend: function(){calendarWait(0);},
			error: function(){$('#calendar').html('Brak połączenia z serwerem.'); $('#calendar_loading').empty();},
			success: function(xml){calendarBuild(xml); setTimeout("calendarWait(1);", 1000);}
		});
	}

	function calendarNav(sessionMonth, sessionYear) {
		var yearFirst = parseInt(currentYear) - 5;
		var yearLast = parseInt(currentYear) + 5;
		var monthNames1 = new Array('Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień');	
		var monthNames2 = new Array('Stycznia', 'Lutego', 'Marca', 'Kwietnia', 'Maja', 'Czerwca', 'Lipca', 'Sierpnia', 'Września', 'Października', 'Listopada', 'Grudnia');
		var monthNext = (sessionMonth == 12)? 1 : parseInt(sessionMonth) + 1;
		var monthPrev = (sessionMonth == 1)? 12 : parseInt(sessionMonth) - 1;
		var yearNext = (sessionYear == yearLast)? yearFirst : parseInt(sessionYear) + 1; 
		var yearPrev = (sessionYear == yearFirst)? yearLast : parseInt(sessionYear) - 1;
		var monthLinks = '';
		var yearLinks = '';
		var todayLinks = '';
		monthLinks += (sessionMonth == 1)? '<a href="javascript:;" onclick="calendar(' + monthPrev + ', ' + yearPrev + ')"><<</a>' : '<a href="javascript:;" onclick="calendar(' + monthPrev + ', ' + sessionYear + ')"><<</a>';
		monthLinks +=  '&nbsp;' + monthNames1[sessionMonth -1] + "&nbsp;";
		monthLinks +=  (sessionMonth == 12)? '<a href="javascript:;" onclick="calendar(' + monthNext + ', ' + yearNext + ')">>></a>' : '<a href="javascript:;" onclick="calendar(' + monthNext + ', ' + sessionYear + ')">>></a>';
		yearLinks += '<a  href="javascript:;" onclick="calendar(' + sessionMonth + ', ' + yearPrev + ')"><<</a>';
		yearLinks += '&nbsp;' + sessionYear + '&nbsp;';
		yearLinks += '<a href="javascript:;" onclick="calendar(' + sessionMonth + ', ' + yearNext + ')">>></a>';
		todayLinks += '<a href="javascript:;" onclick="calendar(' + currentMonth + ', ' + currentYear + ')">Aktualna data: ' + currentDay + ' ' + monthNames2[currentMonth -1] + ' ' + currentYear + '</a>';
		$('#calendar_nav').html(monthLinks + '&nbsp;&nbsp;' + yearLinks);
		$('#calendar_today').html(todayLinks);
	}

	function calendarWait(action) {
		$('#calendar_loading').html((action == 1)? '' : '<img border="0" src="/application/images/layout/loading2.gif" width="160" height="5">');
	}

