(function ($) {
	$.fn.scrollable = function (opts) {
		return this.each(function () {
			var target = $(this),
				container = $(opts.container)
			var width = container.width(),
				offset = container.offset().left
		  var width2 = container.outerWidth()
			var pos = 0, speed = 0, ival
			var minPos = width - target.width()
			if (minPos > 0) {
				container.addClass("lft-edge")
				return
			}
			container
				.addClass("scrollable")
				.mouseenter(function (e) {
					ival = setInterval(function () {
						pos += speed * 7
						pos = Math.min(pos, 0)
						pos = Math.max(pos, minPos)
						target.css({ left: pos })
						if (pos == 0) {
							container.addClass("lft-edge")
						} else if (pos == minPos) {
							container.addClass("rgt-edge")
						} else {
							container.removeClass("lft-edge rgt-edge")
						}
					}, 10)
				})
				.mouseleave(function (e) {
					clearInterval(ival)
				})
				.mousemove(function (e) {
					var d = (e.pageX - offset) - width2/2	// d = odleglosc myszy od srodka
					var s = (d > 0 ? -1 : 1)				// s = znak, tj. kierunek przesuwania
					var x = Math.abs(2*d/width2)				// x = d zeskalowane do przedzialu [0,1]
					if (x < 0.8) {
						speed = 0
					} else {
						// funkcja potegowa przesunieta tak, by f(0.8) = 0, f(1) = 1
						speed = s * Math.pow(5*(x-0.8), 3)
					}
				})
				.addClass("lft-edge")
		})
	}
})(jQuery);

jQuery.fn.reduce = function (c, fn) {
	this.each(function (i) { c = fn.apply(this, [c]) })
	return c
}

jQuery(function() {
  $(document).ready(function(){ 
  	$(document).pngFix(); 
  	 $('p.intro').each(function() {
				var htmlStr = $(this).html();
				var text = '<span>'+htmlStr+'</span>';
				$(this).html(text);
			});
 
  }); 
 
  
  $("#menu ul.top li a").hover(function(){
  	var index = $("#menu ul.top li a").index(this) + 1;
  	var str = ":nth-child("+index+")";
		$("#menu ul.bottom li" + str).find('a').addClass("active");
	},function(){
		var index = $("#menu ul.top li a").index(this) + 1;
  	var str = ":nth-child("+index+")";
		$("#menu ul.bottom li" + str).find('a').removeClass("active");
	});
		 
  
	if ($.browser.msie) {
		$("tr:first-child, td:first-child, th:first-child").addClass("first-child")
		$("tr:last-child, td:last-child, th:last-child").addClass("last-child")
		if (parseInt($.browser.version) <= 6) {
			$("#menu img").pngFixImage()
		}
	}
	$('#videos-list').jScrollPane({scrollbarWidth:45, dragMaxHeight:60, scrollbarMargin:50});
	
	$("div.gallery-box").each(function () {
		var big = $(this).find(".big-fotos .big-foto")
		var thumbs = $(this).find("#thumbs a")
		big.css({ position: "absolute", top: 0, left: 0 }).hide().eq(0).show()
		thumbs.click(function () {
			big.fadeOut().eq(thumbs.index(this)).fadeIn()
			thumbs.removeClass("active")
			$(this).addClass("active")
			return false
		})
	})
});
	
	












