$(document).ready(function() {

	swfobject.embedSWF("/flash/kolokacja.swf","flashNews",140,230,'9.0.0');

	var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
	if (viewportHeight<740) {
		$('body').css('overflow-y', 'scroll');
	}

	initialize();


	var $body = $(document.body),
			$menu = $('#menu'),
			$content = $('#main');

	$.Ajaxy.configure({
				root_url: siteUrl,
				debug: false,
				base_url: '/',
				redirect: false,
				'Controllers': {
					'_generic': {
						request: function() {
							$body.addClass('loading');
							$menu.find('.current').removeClass('current');
							$content.stop(true, true).fadeOut(400);
							return true;
						},
						response: function() {
							// Prepare
							var Ajaxy = $.Ajaxy;
							var data = this.State.Response.data;
							var state = this.state;
							var State = this.State;

							// Adjust Menu
							$menu.find('a[href="' + State.raw.state + '"]').addClass('current');

							// Show Content
							var Action = this;
							$content.html(data.content);
							initialize();

							$content.fadeIn(400, function() {
								Action.documentReady($content);
							});

							return true;

						},
						error: function() {
							// hmmm
							return true;
						}
					}
				}
			});

	function initialize() {

		// pokazujemy polec nas newsletter
		$("#top").find(".recommend, .newsletter").show();


		var $page = $("#scroll");

		//linki ajaxy
		$('#main').find('a.internal').addClass('ajaxy');

		$page.animate({
					height: $(window).height() - 250
				}, 1000, function() {
			$page.jScrollPane({
						scrollbarWidth: 15,
						dragMinHeight: 86,
						dragMaxHeight: 86,
						showArrows: true,
						arrowSize: 10
					});
		});

	}


});
