(function($) {
	$.gaTrack = function(code, opts) {
		opts = jQuery.extend({
			download: '/downloads/',
			extensions: ['pdf', 'doc', 'xls', 'csv', 'jpg', 'gif', 'mp3', 'swf', 'txt', 'ppt', 'zip', 'gz', 'dmg', 'xml'],
			cd_active: false,
			cd_domainname: "none"
		},
		opts);

		function addTracking() {
			var pageTracker = _gat._getTracker(code);
			if (opts.cd_active) {
				pageTracker._setDomainName(opts.cd_domainname);
				if (opts.cd_domainname == "none") {
					pageTracker._setAllowLinker(true)
				} else if (opts.cd_domainname.substr(0, 1) == ".") {
					pageTracker._setAllowHash(false)
				}
			};
			pageTracker._initData();
			pageTracker._trackPageview();
			$('a').each(function() {
				var _self = $(this);
				var u = $(this).attr('href');
				var isDownload = false;
				if (typeof(u) != 'undefined') {
					if (u.indexOf("?") != -1) {
						uext = u.substring(0, u.lastIndexOf("?"))
					} else {
						uext = u
					};
					var ext = uext.split('.')[uext.split('.').length - 1];
					var exts = opts.extensions;
					for (i = 0; i < exts.length; i++) {
						if (ext == exts[i]) {
							_self.click(function() {
								pageTracker._trackPageview(opts.download + cleanURL(_self.attr('href')))
							});
							isDownload = true;
							break
						}
					};
					if (!isDownload && opts.cd_active && (opts.cd_domainname == "none")) {
						$(this).click(function() {
							pageTracker._link(u);
							return false
						})
					}
				}
			})
		};

		function cleanURL(link_href) {
			return link_href.replace(/..\//g, "")
		};

		function initGA() {
			try {
				var gaURL = (location.href.indexOf('https') == 0 ? 'https://ssl' : 'http://www');
				gaURL += '.google-analytics.com/ga.js';
				$.getScript(gaURL, function() {
					addTracking()
				})
			} catch(err) {
				console.log('Failed to load Google Analytics:' + err)
			}
		};
		initGA()
	}
})(jQuery);
(function($) {
	$.fn.center = function(options) {
		var pos = {
			top: function() {
				return window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop
			},
			height: function() {
				return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight
			}
		};
		return this.each(function(index) {
			if (index == 0) {
				var $this = $(this);
				var height = $this.height();
				var top = pos.top() + (pos.height() / 2) - (height / 2);
				$this.css({
					position: 'absolute',
					marginTop: '0',
					top: top
				})
			}
		})
	}
})(jQuery);


function Pager(target) {
	var $target = jQuery(target + ' .content ul');
	var $count = jQuery(target + ' .count');
	var $pager = jQuery(target + ' .pager');
	var view = $target.parent().height();
	var count = 1;
	normal = $target.height() / view;
	fixed = parseInt(normal.toFixed(0));
	var delimeter = 0;
	if (normal > fixed) delimeter = fixed + 1;
	else delimeter = fixed;
	$count.attr('class', 'count ' + 'number-' + delimeter);

	function number(index) {
		jQuery(target + ' .index').attr('class', 'index ' + 'number-' + index)
	}
	bind();

	function bind() {
		$pager.find('a').bind('click', binded)
	}

	function unbind() {
		$pager.find('a').unbind('click', binded)
	}

	function active(action) {
		if (action == 'prev') if ((count) == 1) return false;
		if (action == 'next') if ((count) == delimeter) return false;
		return true
	}

	function move(action, $self) {
		$self.attr('class', '');
		if (action == 'prev') {
			count--;
			if (count == 1) $self.attr('class', 'prev-end')
		}
		if (action == 'next') {
			count++;
			if (count == delimeter) $self.attr('class', 'next-end')
		}
		position = (count - 1) * view;
		number(count);
		$target.animate({
			'marginTop': -position
		},
		300)
	}

	function binded() {
		var name = jQuery(this).attr('class');
		var $parent = jQuery(this).parent();
		switch (name) {
		case 'prev':
			if (active('prev')) move('prev', $parent);
			break;
		case 'next':
			if (active('next')) move('next', $parent)
		}
		return false
	}
}


function Loader(image, target) {
	var oimage = new Image();
	var ration;
	oimage.onload = function() {
		var width = oimage.width;
		var height = oimage.height;
		if (width > height) {
			if (width > 980) {
				height = height / (width / 980);
				width = 980
			}
		}
		if (height > width) {
			if (height > 500) {
				width = width / (height / 500);
				height = 500
			}
		}
		var $image = jQuery(target).find('.image');
		jQuery('#layer a').attr('href', image.href);
		$image.attr('title', image.title);
		var $source = jQuery('<img src="' + image.src + '" />');
		$source.attr('width', width).attr('height', height).appendTo($image);
		resize(width, height);
		oimage.onload = function() {}
	};
	oimage.src = image.src;

	function resize(wwidth, wheight) {
		var left = wwidth / 2;
		var top = wheight / 6;
		var top = ((wheight - 333)) / 2;
		jQuery(target).animate({
			width: wwidth,
			height: wheight + 0,
			marginLeft: -left,
			marginTop: -top,
			left: '50%',
			opacity: 1
		},
		300, function() {})
	}
}


function Close() {
	jQuery('#overlay, #layer a').click(function() {
		jQuery('#layer').fadeOut('120', function() {
			jQuery('#overlay').fadeOut('60', function() {
				jQuery('#layer').remove();
				jQuery('#overlay').remove()
			})
		});
		return false
	})
};


function Windows() {
	var container = '#window';
	var overlay = '#overlay';
	var curent = this;
	this.handler;
	this.editor;
	this.closeAction;
	this.openAction;
	this.closeElement;
	this.openElement;
	this.init = function(content) {
		var values = {
			'height': jQuery('body').height(),
			'width': jQuery('body').width()
		};
		jQuery('<div id="overlay"></div>').animate({
			opacity: 0
		},
		0).prependTo('body').css(values).animate({
			opacity: 0.6
		},
		180, function() {
			jQuery(content).animate({
				opacity: 0
			},
			0).prependTo('body').animate({
				opacity: 1
			},
			260, function() {
				if (jQuery.browser.msie) this.style.removeAttribute('filter');
				curent.openAction();
				curent.prepareClose()
			}).center()
		})
	};
	this.open = function(element, request, action) {
		if (typeof action === 'function') {
			curent.openAction = function() {
				action()
			}
		} else {
			curent.openAction = function() {
				return true
			}
		}
		curent.requestAction = function() {
			request()
		};
		jQuery(element).live('click', function() {
			curent.openElement = this;
			return openEach(this)
		})
	};
	var openEach = function(element) {
		curent.handler = jQuery(element).attr('rel');
		curent.requestAction();
		return false
	};
	this.close = function(element, action) {
		if (typeof action === 'function') {
			curent.closeAction = function() {
				action()
			}
		} else {
			curent.closeAction = function() {
				return true
			}
		}
		curent.prepareClose = function() {
			jQuery(element + ', ' + overlay).bind('click', function() {
				curent.closeElement = this;
				return closeEach()
			})
		}
	};
	var closeEach = function() {
		curent.closeAction();
		jQuery(container).fadeOut(130, function() {
			jQuery(container).remove();
			jQuery(overlay).fadeOut(90, function() {
				jQuery(overlay).remove()
			})
		});
		return false
	};
	this.terminate = function() {
		closeEach()
	};
	this.projection = function() {
		curent.requestAction()
	}
}



function strip_tags(b, c) {
	var f = "",
		d = false;
	var a = [];
	var g = [];
	var e = "";
	var j = 0;
	var i = "";
	var l = "";
	var h = function(m, k, n) {
		return n.split(m).join(k);
	};
	if (c) {
		g = c.match(/([a-zA-Z]+)/gi);
	}
	b += "";
	a = b.match(/(<\/?[\S][^>]*>)/gi);
	for (f in a) {
		if (isNaN(f)) {
			continue;
		}
		l = a[f].toString();
		d = false;
		for (i in g) {
			e = g[i];
			j = -1;
			if (j != 0) {
				j = l.toLowerCase().indexOf("<" + e + ">");
			}
			if (j != 0) {
				j = l.toLowerCase().indexOf("<" + e + " ");
			}
			if (j != 0) {
				j = l.toLowerCase().indexOf("</" + e);
			}
			if (j == 0) {
				d = true;
				break;
			}
		}
		if (!d) {
			b = h(l, "", b);
		}
	}
	return b;
}
var time = 300;
var message = {
	schortQuery: "Podana fraza jest za krótka.",
	closeEmptyRequest: "Podana fraza nie została odnaleziona. Spróbuj zmodyfikować swoje zapytanie.",
	searchError: "Podczas wyszukiwania wystąpił błąd. Spróbuj ponownie.",
	searchWorking: "Trwa wyszukiwanie"
};
var searchAddress = "/services/livesearch.php";
var livesearch = {
	start: function() {
		this.construct();
		this.proced();
	},
	construct: function() {
		var b = $('<div id="livesearch-content"></div>');
		$('<div class="content"><div class="message"></div><div class="submit"></div></div>').appendTo(b);
		b.appendTo("#livesearch").hide(0);
	},
	proced: function() {
		var $container = $("#livesearch-content");
		var $query = $("#livesearch-query");
		var $results = $('<a href="/szukaj">zobacz wszystkie wyniki wyszukiwania</a>');
		var $message = $("#livesearch-content .message");
		var temporary = null;
		$results.appendTo("#livesearch-content .content .submit").hide();



		function messageStatus(data) {
			$message.find("span").remove();
			$results.hide();
			if (data) {
				data = eval("message." + data);
				if (data) {
					var $proces = $(document.createElement("span")).text(data);
					$proces.appendTo($message);
				}
			}
			return false;
		}



		function clickStatus() {
			var close = true;
			$(this).parents().map(function() {
				return this.id;
			}).each(function(e) {
				if (this == "livesearch") {
					close = false;
				}
			});
			if (close == true) {
				closeSearch();
			}
			return close;
		}



		function suspendSearch() {
			if ($container.not(":visible")) {
				jQuery("#livesearch-query").attr("value", "");
				$container.find("dl").remove();
			}
		}



		function newLocation() {
			window.location = $(this).attr("href");
		}



		function openSearch() {
			$container.not(":visible").fadeIn(500).attr("visible", true);
			$("body").addClass("livesearch");
			$("*:not(#livesearch-content *, #livesearch-content)").bind("click", clickStatus);
			$("#livesearch-content .submit a").click(function() {
				$("form#livesearch").submit();
				return false;
			});
		}



		function closeSearch() {
			$(".livesearch *").unbind("click", clickStatus);
			$("body").removeClass("livesearch");
			$container.fadeOut(500).attr("visible", false);
		}
		$query.focus(function() {
			if ($container.not(":visible") && $(this).val().length > 0) {
				openSearch();
			}
		});



		function emptyRequest(response) {
			timeEmpty = setTimeout(function() {
				$container.find("dl").remove();
				if (response) {
					messageStatus(response);
				}
			},
			300);
		}
		$query.bind("keyup", function(e) {
			var query = $(this).val();
			if (e.keyCode === 39 || e.keyCode === 37) {
				return false;
			}
			if (query.length == 0) {
				emptyRequest("schortQuery");
				return false;
			}
			if (query.length < 4) {
				emptyRequest("schortQuery");
				return false;
			}
			if (query === temporary) {
				return false;
			}
			clearTimeout(time);
			messageStatus("searchWorking");
			time = setTimeout(function() {
				jQuery.ajax({
					url: searchAddress,
					data: "search=" + query,
					dataType: "json",
					success: function(data) {
						if (data.status == false) {
							emptyRequest("closeEmptyRequest");
						} else {
							emptyRequest("closeDefault");
							timeWrite = setTimeout(function() {
								livesearch.parse(data.data);
								$results.show();
							},
							300);
						}
					},
					complete: function(request, status) {
						switch (status) {
						case "parsererror":
							emptyRequest("closeEmptyRequest");
							break;
						case "error":
							emptyRequest("searchError");
							break;
						}
					}
				});
			},
			600);
			temporary = query;
			openSearch();
			return false;
		});
	},
	parse: function(data) {
		for (key in data) {
			var $content = $('<dl class="' + key + '"><dt></dt></dl>');
			var row = eval("data." + key);
			$.each(row, function(i, e) {
				var title = e.title.replace("<br />", "");
				var anchor = '<dd><a href="/artykul/' + e.id + '">';
				switch (key) {
				case "feuilletons":
					anchor += "<span>" + e.title + "<em>" + e.author + '</em></span><img src="' + e.image + '" />';
					break;
				case "opinions":
					anchor += "<em>" + e.author + "</em><span>" + e.title + "</span>";
					break;
				case "others":
					anchor += "<span>" + title + "</span>";
					break;
				}
				anchor += "</a></dd>";
				$(anchor).appendTo($content);
			});
			$content.insertBefore("#livesearch-content .content .message").fadeIn();
		}
	}
};
var mediaplayer = {
	image: function(f) {
		var d = jQuery('<div id="layer"></div>');
		d.append('<div class="content"><a class="image" href="" title="" target="_blank"></a></div>');
		d.append('<div class="close"><a class="terminate" href="#"></a></div>');
		var e = {
			height: jQuery("body").height(),
			width: jQuery("body").width()
		};
		f = {
			href: "#",
			src: "/public/media/electric/" + f
		};
		jQuery('<div id="overlay"></div>').animate({
			opacity: 0
		},
		0).prependTo("body").css(e).animate({
			opacity: 0.6
		},
		180, function() {
			jQuery(d).animate({
				opacity: 0
			},
			0).prependTo("body").animate({
				opacity: 1
			},
			360, function() {
				new Loader(f, "#layer");
				Close();
			}).center();
		});
	},
	animation: function(f) {
		var d = jQuery('<div id="layer" class="flashplayer electric_flash_3"></div>');
		d.append('<div class="content" id="video_player"></div>');
		var e = {
			height: jQuery("body").height(),
			width: jQuery("body").width()
		};
		f = "/public/media/electric/" + f;
		jQuery('<div id="overlay"></div>').animate({
			opacity: 0
		},
		0).prependTo("body").css(e).animate({
			opacity: 0.6
		},
		180, function() {
			jQuery(d).animate({
				opacity: 0
			},
			0).prependTo("body").animate({
				opacity: 1
			},
			360, function() {
				var c = {};
				var a = {
					scale: "noscale",
					allowFullScreen: "true"
				};
				var b = {};
				swfobject.embedSWF(f, "video_player", "800", "600", "9.0.0", "/public/flash/expressinstall.swf", c, a, b);
				Close();
			}).center();
		});
	},
	video: function(g, h) {
		var e = jQuery('<div id="layer" class="flashplayer"></div>');
		e.append('<div class="content" id="video_player"></div>');
		var f = {
			height: jQuery("body").height(),
			width: jQuery("body").width()
		};
		jQuery('<div id="overlay"></div>').animate({
			opacity: 0
		},
		0).prependTo("body").css(f).animate({
			opacity: 0.6
		},
		180, function() {
			jQuery(e).animate({
				opacity: 0
			},
			0).prependTo("body").animate({
				opacity: 1
			},
			360, function() {
				var c = {
					description: h,
					video_file: g
				};
				var a = {
					scale: "noscale",
					allowFullScreen: "true"
				};
				var b = {};
				swfobject.embedSWF("/public/flash/video_player_electric.swf", "video_player", "480", "430", "9.0.0", "/public/flash/expressinstall.swf", c, a, b);
				Close();
			}).center();
		});
	}
};



function Layer(g) {
	var e = jQuery('<div id="layer"></div>');
	e.append('<div class="content"><a class="image" href="" title="" target="_blank"></a></div>');
	e.append('<div class="close"><a class="terminate" href="#"></a></div>');
	var f = {
		height: jQuery("body").height(),
		width: jQuery("body").width()
	};
	var h = {
		href: g.rel,
		src: g.src,
		title: g.title
	};
	jQuery('<div id="overlay"></div>').animate({
		opacity: 0
	},
	0).prependTo("body").css(f).animate({
		opacity: 0.3
	},
	180, function() {
		jQuery(e).animate({
			opacity: 0
		},
		0).prependTo("body").animate({
			opacity: 1
		},
		360, function() {
			new Loader(h, "#layer");
			Close();
		}).center();
	});
}
var electric = {
	image: function(f) {
		var d = $('<div id="layer"></div>');
		d.append('<div class="content"><a class="image" href="" title="" target="_blank"></a></div>');
		d.append('<div class="close"><a class="terminate" href="#"></a></div>');
		var e = {
			height: $("body").height(),
			width: $("body").width()
		};
		source = {
			src: "/public/media/electric/" + f.source
		};
		$('<div id="overlay"></div>').animate({
			opacity: 0
		},
		0).prependTo("body").css(e).animate({
			opacity: 0.6
		},
		180, function() {
			d.animate({
				opacity: 0
			},
			0).prependTo("body").animate({
				opacity: 1
			},
			360, function() {
				new Loader(source, "#layer");
				Close();
			}).center();
		});
		return false;
	},
	animation: function(h) {
		var e = $('<div id="layer" class="flashplayer electric_flash_3"></div>');
		e.append('<div class="content" id="animation"></div>');
		var f = {
			height: $("body").height(),
			width: $("body").width()
		};
		var g = "/public/media/electric/" + h.source;
		$('<div id="overlay"></div>').animate({
			opacity: 0
		},
		0).prependTo("body").css(f).animate({
			opacity: 0.6
		},
		180, function() {
			e.animate({
				opacity: 0
			},
			0).prependTo("body").animate({
				opacity: 1
			},
			360, function() {
				var c = {};
				var a = {
					scale: "noscale",
					allowFullScreen: "true",
					wmode: "opaque"
				};
				var b = {};
				swfobject.embedSWF(g, "animation", "800", "600", "9.0.0", "/public/flash/expressinstall.swf", c, a, b);
				Close();
			}).center();
		});
		return false;
	},
	video: function(l) {
		try {
			var p = {
				description: strip_tags(l.description),
				video_file: l.source
			};
			if (l.category == "material" || l.category == "keynote") {
				var k = "/public/flash/video_player_electric.swf";
			} else {
				var h = l.directory.split("_");
				var k = "/public/flash/video_player_flash.swf";
				p.year = h[0];
				p.issue = h[1];
			}
			var o = {
				height: $("body").height(),
				width: $("body").width()
			};
			var m = $('<div id="layer" class="flashplayer"></div>');
			m.append('<div class="content" id="video_player"></div>');
			$('<div id="overlay"></div>').animate({
				opacity: 0
			},
			0).prependTo("body").css(o).animate({
				opacity: 0.6
			},
			180, function() {
				m.animate({
					opacity: 0
				},
				0).prependTo("body").animate({
					opacity: 1
				},
				360, function() {
					var a = {
						scale: "noscale",
						allowFullScreen: "true",
						wmode: "opaque",
						bgcolor: "#000000"
					};
					var b = {};
					swfobject.embedSWF(k, "video_player", "480", "430", "9.0.0", "/public/flash/expressinstall.swf", p, a, b);
					Close();
				}).center();
			});
		} catch(n) {
			alert(n);
		}
		return false;
	},
	audio: function(n, m) {
		var p = $(m).parent().attr("id");
		var h = n.directory.split("_");
		var k = {
			description: jQuery(n.description).html(),
			video_file: n.source,
			year: h[0],
			issue: h[1]
		};
		var l = {
			scale: "noscale",
			allowFullScreen: "true",
			wmode: "transparent"
		};
		var o = {};
		swfobject.embedSWF("/public/flash/audio_player_small.swf", p, "220", "120", "9.0.0", "/public/flash/expressinstall.swf", k, l, o);
	}
};
var engine = {
	start: function() {
		this.cufon();
		this.google();
		this.print();
		this.archive();
		this.newsletter();
		if (document.getElementById("list")) {
			this.fixed();
		}
		if (document.getElementById("poem")) {
			this.poems();
		}
		if (document.getElementById("electric")) {
			this.electric();
		}
		this.category();
		if (document.getElementById("felietony")) {
			this.authors();
		}
		if (document.getElementById("homepage")) {
			this.homepage();
		}
		this.images();
		this.tags();
		this.media();
	},
	cufon: function() {
		Cufon.replace("#list h4, .articles h4, #shortly .content .title, #fictions dt, #feuilletons .title a", {
			hover: true,
			fontFamily: 'Baskerville Win95BT'
		});
		Cufon.replace(".content h2", {
			fontFamily: 'Baskerville Win95BT'
		});
	},
	homepage: function() {
		Pager("#news");
	},
	authors: function() {
		jQuery(".filter .authors").bind("click", function() {
			jQuery("#authors").toggle(1);
		});
		jQuery("#authors .content a").bind("click", function() {
			jQuery(this).toggleClass("selected");
			return false;
		});
		jQuery("#authors .proced").bind("click", function() {
			var f = new Array();
			jQuery("#authors .content .selected").each(function(b, a) {
				f[b] = jQuery(a).attr("rel");
			});
			var d = "" + jQuery(this).attr("href");
			var e = f.join(",");
			address = "/archiwum/autor-" + e + "/felietony.html";
			if (f.length > 0) {
				jQuery(this).attr("href", address);
			}
		});
	},
	category: function() {
		jQuery(".filter .category").bind("click", function() {
			jQuery("#category").toggle(1);
		});
		jQuery("#category .content a").bind("click", function() {
			jQuery(this).toggleClass("selected");
			return false;
		});
		jQuery("#category .proced").bind("click", function() {
			var f = new Array();
			jQuery("#category .content .selected").each(function(b, a) {
				f[b] = jQuery(a).attr("rel");
			});
			var d = "" + jQuery(this).attr("href");
			var e = f.join("+");
			address = "/kategorie," + e + "/elektryczne.html";
			if (f.length > 0) {
				jQuery(this).attr("href", address);
			}
		});
	},
	tags: function() {
		jQuery(".filter .tags").bind("click", function() {
			jQuery("#tags").toggle(1);
		});
		jQuery("#tags .content a").bind("click", function() {
			jQuery(this).toggleClass("selected");
			return false;
		});
		jQuery("#tags .proced").bind("click", function() {
			var f = document.getElementById("collectioncloud") ? "" : "/archiwum/tagi/";
			var g = new Array();
			jQuery("#tags .content .selected").each(function(b, a) {
				g[b] = jQuery(a).attr("rel");
			});
			if (document.getElementById("collectioncloud")) {
				var h = "" + jQuery(this).attr("href");
				var e = g.join("+");
				f += (e.length == 0) ? "" : h.replace(/archiwum/, "archiwum/" + e);
			} else {
				f += g.join("+") + ".html";
			}
			if (g.length > 0) {
				jQuery(this).attr("href", f);
			}
		});
	},
	google: function() {
		jQuery.gaTrack("UA-7542753-2");
	},
	newsletter: function() {
		var b = jQuery("#newsletter");
		jQuery("#navigation .newsletter").click(function() {
			b.toggle(1);
			return false;
		});
		jQuery("#newsletter form").submit(function() {
			var a = jQuery("#newsletter input[name='action']:checked").val();
			jQuery.ajax({
				type: "POST",
				url: "/newsletter/" + a + "/format/json",
				data: "email=" + jQuery("#newsletter .email").val(),
				dataType: "json",
				beforeSend: function() {
					jQuery("#newsletter .message").html("Trwa zapisywanie...");
				},
				success: function(c) {
					if (typeof c === "object") {
						jQuery("#newsletter .message").fadeIn(100, function() {
							jQuery(this).html(c.message);
						});
						if (c.status == true) {
							setTimeout(function() {
								b.hide(1);
								jQuery("#newsletter .message").fadeOut(100);
							},
							2400);
						}
					}
				}
			});
			return false;
		});
	},
	print: function() {
		jQuery("#print a").click(function() {
			$('<img src="/public/image/logo.png" border="0" class="printme" />').insertBefore("#header h2:first");
			print();
			return false;
		});
	},
	images: function() {
		$(".zoom").click(function() {
			var b = {};
			$anchor = $(this);
			b.src = $anchor.attr("href");
			b.href = $anchor.attr("href");
			b.title = $anchor.find(".legend").html();
			new Layer(b);
			return false;
		});
		jQuery("#materials .media-anchor").bind("click", function() {
			var e = $(this).attr("rel");
			var f = $(this).attr("href");
			var d = $(this).attr("title");
			switch (e) {
			case "mediatype-video":
				mediaplayer.video(f, d);
				break;
			case "mediatype-image":
				mediaplayer.image(f);
				break;
			case "mediatype-animation":
				mediaplayer.animation(f);
				break;
			}
			return false;
		});
	},
	electric: function() {
		$("#electric .mediatype a").each(function() {
			var c = $(this);
			var d = {};
			d.source = c.attr("href");
			d.category = c.attr("title");
			d.type = c.attr("rel");
			d.description = $(this).parent().parent().find(".description").html();
			d.directory = c.find("img").attr("alt");
			switch (d.type) {
			case "video":
				$(this).bind("click", function() {
					electric.video(d);
					return false;
				});
				break;
			case "image":
				$(this).bind("click", function() {
					electric.image(d);
					return false;
				});
				break;
			case "animation":
				$(this).bind("click", function() {
					electric.animation(d);
					return false;
				});
				break;
			case "audio":
				electric.audio(d, c);
				break;
			}
		});
	},
	archive: function() {
		jQuery(".prev-end, .next-end").click(function() {
			return false;
		});
		var d = 0;
		jQuery("#header .archive").bind("click", function() {
			jQuery(this).toggleClass("active");
			jQuery("#archive").slideToggle(600);
			if (d == 0) {
				$("#archive .slide dl").each(function() {
					d += $(this).outerWidth(true);
				});
				$("#archive .slide").width(d);
			}
			return false;
		});
		var c = 0;
		$("#archive .prev a").click(function() {
			if ((d - (97 * c)) < 970) {
				return false;
			}
			c++;
			var a = $("#archive .slide");
			a.animate({
				right: -(97 * c) - 1
			},
			300);
			return false;
		});
		$("#archive .next a").click(function() {
			c = c == 0 ? 0 : (c - 1);
			var a = $("#archive .slide");
			a.animate({
				right: -(97 * c) - 1
			},
			300);
			return false;
		});
	},
	fixed: function() {
		if ($(".article .related li").size() > 4) {
			$(".article .related li:gt(3)").hide();
			$(".article .related ul").after('<a class="more" href="#">pokaż wszystkie</a>');
			var s = 2;
			$(".article .more").click(function() {
				var b = this;
				var a = s++%2 == 0;
				$(".article .related ul li:gt(3)").slideToggle(300, function() {
					if (a) {
						$(b).html("schowaj");
					} else {
						$(b).html("pokaż wszystkie");
					}
				});
				return false;
			});
		}
		var r = (document.getElementById("felietony")) ? 3 : 4;
		var p = document.getElementById("list");
		var n = p.getElementsByTagName("li");
		var l = Math.ceil(n.length / r);
		var t, o;
		for (i = 0; i < l; i++) {
			o = 0;
			for (j = 0; j < r; j++) {
				var q = i * r + j;
				var m = jQuery(n[q]).height();
				t = ((q + 1) > n.length) ? false : true;
				if (t) {
					if (m > o) {
						o = m;
					}
				}
			}
			for (j = 0; j < r; j++) {
				var q = i * r + j;
				n[q].style.height = o + "px";
				if ((q + 1) == (n.length)) {
					return false;
				}
			}
		}
		return false;
	},
	media: function() {
		jQuery(".mediacreator").each(function(f, a) {
			var b = $(this).find("img").attr("alt");
			jQuery(mediacontainer).each(function(h, e) {
				if (b == e.id) {
					$(a).empty();
					$(a).append('<div id="mediacreator-' + e.id + '"></div>');
					switch (e.type) {
					case "audio":
						c(e);
						break;
					case "video":
						d(e);
						break;
					}
				}
			});
		});



		function c(b) {
			var h = {
				description: b.description,
				video_file: b.source,
				year: b.year,
				issue: b.issue
			};
			var a = {
				scale: "noscale",
				allowFullScreen: "true"
			};
			var e = {};
			swfobject.embedSWF("/public/flash/audio_player_flash.swf", "mediacreator-" + b.id, "480", "86", "9.0.0", "/public/flash/expressinstall.swf", h, a, e);
		}



		function d(b) {
			var h = {
				description: b.description,
				video_file: b.source,
				year: b.year,
				issue: b.issue
			};
			var a = {
				scale: "noscale",
				allowFullScreen: "true"
			};
			var e = {};
			swfobject.embedSWF("/public/flash/video_player_flash.swf", "mediacreator-" + b.id, "480", "430", "9.0.0", "/public/flash/expressinstall.swf", h, a, e);
		}
	},
	poems: function() {
		$("#poem .chapter:first").addClass("description").before('<p id="print"><a href="" title="">Wersja do druku</a></p>');
	}
};

jQuery().ready(function() {

	livesearch.start();
	engine.start();

	$('#comments .controll').click(function() {
		parent = $(this).parents('#comments');
		if (parent.is('.visible')) {
			parent.removeClass('visible');
			$(this).attr('Schowaj');
			parent.find('.form, .body').slideUp(300, function() {

			});
		} else {
			parent.addClass('visible');
			$(this).attr('Pokaż');
			parent.find('.form, .body').slideDown(300, function() {

			});
		}
	});

	return false;
});

