/*
 * jqPLScrollable
 * by Piotr Łojewski piotr.l@aginus.pl
 *
******************************************** */
(function($){
		  
	$.fn.jqPLScrollable = function(){
		
		$('ul.wrapper').wrapInner('<div class="scrollable" />');
		
		return this.each(function(){
			
			var wrapper = $(this);
			var scrollable = $(this).children('div.scrollable');
			wrapper.css({overflow: 'hidden'});				
			
			var inactiveMargin = 50;
			var wrapperWidth = wrapper.width();
			var wrapperHeight = wrapper.height();
			var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
		
			wrapper.mousemove(function(e){
				var wrapperOffset = wrapper.offset();
				var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;	
				if (top < 0){
					top = 0;
				}
				wrapper.scrollTop(top);
			});
			
		});
	
	}
		
})(jQuery);


$(document).ready(function() {
	
	// WARSTWA PRZEWIJANA
	$('div.menu-prawe ul li ul').jqPLScrollable();

	// NOWE OKNO DLA LINKÓW Z ATRYBUTEM REL="TARGET"
	$('a[rel="target"]').click(function() {
		var newWindow = window.open(this.href);
		return false;
	});

	// RAMKA FANÓW FACEBOOK
	$('div.facebook').mouseenter(function(){
		$(this).stop(true, false).animate({"right": "0"}, 400);
	});
	$('div.facebook').mouseleave(function(){
		$(this).stop(true, false).animate({"right": "-320px"}, 400);
	});
	
});

// ŚRODKOWANIE UL (bez określania szerokości) DLA MENU Z LI Z FLOAT LEFT (styl niezbędny dla ul: display: inline; float: left; dla div konieczna szerokość)
$.fn.ulAlign = function() {
	return this.each(function(i){
		var szerokosc_div = $(this).width();
		var szerokosc_ul = $(this).children().width();
		var margines = (szerokosc_div - szerokosc_ul) / 2;
		$(this).children().css('margin-left', margines);
	});
};

$(document).ready(function() {
	$("div.menu").ulAlign();
});
