jQuery.noConflict();
(function(a) {
	a.fn.center = function(b) {
		var c = {
			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(e) {
			if (e == 0) {
				var g = a(this);
				var d = g.height();
				var f = c.top() + (c.height() / 2) - (d / 2);
				g.css({
					position: "absolute",
					marginTop: "0",
					top: f
				});
			}
		});
	};
})(jQuery);

function Windows(b, a) {
	var c = (typeof b === "undefined") ? "#window" : b;
	var a = (typeof a === "undefined") ? true : false;
	var e = "#overlay";
	var f = this;
	this.handler;
	this.closeAction = function() {};
	this.openAction = function() {};
	this.closeElement;
	this.openElement;
	this.init = function(i) {
		var h = {
			height: jQuery("body").height(),
			width: jQuery("body").width()
		};
		jQuery('<div id="overlay"></div>').animate({
			opacity: 0
		},
		0).prependTo("body").css(h).animate({
			opacity: 0.6
		},
		180, function() {
			var j = jQuery(i).animate({
				opacity: 0
			},
			0).prependTo("body").animate({
				opacity: 1
			},
			260, function() {
				if (jQuery.browser.msie) {
					this.style.removeAttribute("filter");
				}
				if (jQuery.browser.msie && jQuery.browser.version < 7) {
					var k = jQuery('<script type="text/javascript" src="/script/png.js"><\/script>');
					jQuery(k).appendTo("head");
				}
				f.openAction();
				f.prepareClose();
			});
			if (a) {
				j.center();
			}
		});
	};
	this.open = function(h, i, j) {
		if (typeof j === "function") {
			f.openAction = function() {
				j();
			};
		} else {
			f.openAction = function() {
				return true;
			};
		}
		f.requestAction = function() {
			i();
		};
		jQuery(h).bind("click", function() {
			f.openElement = this;
			return d(this);
		});
	};
	var d = function(h) {
		f.handler = jQuery(h).attr("rel");
		f.requestAction();
		return false;
	};
	this.close = function(h, i) {
		if (typeof i === "function") {
			f.closeAction = function() {
				i();
			};
		} else {
			f.closeAction = function() {
				return true;
			};
		}
		f.prepareClose = function() {
			jQuery(h + ", " + e).bind("click", function() {
				f.closeElement = this;
				return g();
			});
		};
	};
	var g = function() {
		f.closeAction();
		jQuery(c).fadeOut(130, function() {
			jQuery(c).remove();
			jQuery(e).fadeOut(90, function() {
				jQuery(e).remove();
			});
		});
		return false;
	};
	this.terminate = function() {
		g();
	};
	this.projection = function() {
		f.requestAction();
	};
}


function Loader(d, c, dontResize) {
	var e = new Image();
	var a;
	e.onload = function() {
		var h = e.width;
		var f = e.height;
		if(dontResize != 1)
		{
			if (h > f) {
				if (h > 960) {
					f = f / (h / 960);
					h = 960;
				}
			}
			if (f > h) {
				if (f > 600) {
					h = h / (f / 600);
					f = 600;
				}
			}
		}
		var g = jQuery(c).find(".image");
		jQuery("#image_window a").attr("href", d.href);
		g.attr("title", d.title);
		var i = jQuery('<img src="' + d.src + '" />');
		i.attr("width", h).attr("height", f).appendTo(g);
		if(dontResize == 1)
		{
			h = 960;
			jQuery("#image_window .content").width(h).css({'overflow-x':'auto','height':'auto'});
			f = f+30;
		}
		b(h, f);
		e.onload = function() {};
	};
	e.src = d.src;

	function b(i, f) {
		var h = i / 2;
		var g = f / 6;
		var g = ((f - 333)) / 2;
		jQuery(c).animate({
			width: i,
			height: f + 33,
			marginLeft: -h,
			marginTop: -g,
			left: "50%",
			opacity: 1
		},
		600, function() {});
	}
}

function Close() {
	jQuery("#image_overlay, #image_window .terminate").click(function() {
		jQuery("#image_window").fadeOut("120", function() {
			jQuery("#image_overlay").fadeOut("60", function() {
				jQuery("#image_window").remove();
				jQuery("#image_overlay").remove();
			});
		});
		return false;
	});
}


function Flickr(d) {
	var b = jQuery('<div id="image_window" class="wimage"></div>');
	b.append('<div class="content"><a class="image" href="javascript:void(0);" title="" target="_blank"></a></div>');
	b.append('<div class="close"><a class="flickr" href="javascript:void(0);" title="" target="_blank">Otwórz to zdjęcie w serwisie <span>Flickr</span></a><a class="terminate" href="javascript:void(0);"></a></div>');
	var a = {
		height: jQuery("body").height(),
		width: jQuery("body").width()
	};
	var c = {
		title: "Kliknij aby otworzyć zdjęcie w serwisie Flickr",
		href: d.href,
		src: d.src
	};
	jQuery('<div id="image_overlay"></div>').animate({
		opacity: 0
	},
	0).prependTo("body").css(a).animate({
		opacity: 0.6
	},
	180, function() {
		jQuery(b).animate({
			opacity: 0
		},
		0).prependTo("body").animate({
			opacity: 1
		},
		260, function() {
			Loader(c, "#image_window");
			Close();
		}).center();
	});
}


function Images(d) {
	var b = jQuery('<div id="image_window" class="wimage"></div>');
	b.append('<div class="content"><a class="image" href="javascript:void(0);" title="" target="_blank"></a></div>');
	b.append('<div class="close"><a class="terminate" href="javascript:void(0);"></a></div>');
	var a = {
		height: jQuery("body").height(),
		width: jQuery("body").width()
	};
	var c = {
		title: "Kliknij aby otworzyć zdjęcie w pełnych wymiarach.",
		href: d.rel,
		src: d.src
	};
	jQuery('<div id="image_overlay"></div>').animate({
		opacity: 0
	},
	0).prependTo("body").css(a).animate({
		opacity: 0.6
	},
	180, function() {
		jQuery(b).animate({
			opacity: 0
		},
		0).prependTo("body").animate({
			opacity: 1
		},
		260, function() {
			new Loader(c, "#image_window");
			Close();
		}).center();
	});
}


function Scroller(i) {
	var f = jQuery(i + " .next");
	var d = jQuery(i + " .prev");
	var l = jQuery(i + " .prev, " + i + " .next");
	var g = jQuery(i + " .preview ul");
	var a = 237;
	var n = jQuery(g).find("li").length;
	n = n * 79;
	jQuery(g).css("width", n);
	this.index = 0;
	var b = this;

	function e() {
		var p = n / a;
		if (p > 1) {
			var o = parseInt(p.toFixed(0));
			if (p > o) {
				p = o + 1;
			} else {
				p = o;
			}
		}
		return p;
	}
	var h = e();

	function c(p) {
		if (p >= 0 && p < h) {
			var o = a * p;
			b.index = p;
			jQuery(g).animate({
				left: -o
			},
			300);
			return false;
		} else {
			return false;
		}
	}

	function j() {
		jQuery(l).click(k);
	}

	function m() {
		jQuery(l).unbind("click", k);
	}

	function k() {
		var o = jQuery(this);
		var p = jQuery(o).attr("class");
		switch (p) {
		case "prev":
			c(parseInt(b.index) - 1);
			break;
		case "next":
			c(parseInt(b.index) + 1);
		}
		return false;
	}
	j();
}


function Message(c, b) {
	c = '<div id="message"><ul>' + c + "</ul></div>";
	var a = {
		height: jQuery("body").height(),
		width: jQuery("body").width()
	};
	jQuery('<div id="underoverlay"></div>').animate({
		opacity: 0
	},
	0).prependTo("body").css(a).animate({
		opacity: 0.2
	},
	120, function() {
		jQuery(c).animate({
			opacity: 0
		},
		0).prependTo("#frame_new_" + b + " .content").animate({
			opacity: 1
		},
		160, function() {
			if (jQuery.browser.msie) {
				this.style.removeAttribute("filter");
			}
			jQuery("#underoverlay, #message").click(function() {
				jQuery("#message").fadeOut("120", function() {
					jQuery("#underoverlay").fadeOut("60", function() {
						jQuery("#message").remove();
						jQuery("#underoverlay").remove();
					});
				});
				return false;
			});
		});
	});
}

