(function($){
		  
	$.fn.jqPLScrollable = function(){

		return this.each(function(){
								  
			var element = $(this);
			element.css({overflow: 'hidden'});
			
			var wysokosc = element.height();
			
			element.mousemove(function(e){
									   
				var polozenie = element.offset();
				var pozycja = e.pageY - polozenie.top;
				if (pozycja < 0) {
					pozycja = 0;
				}
				element.scrollTop(pozycja);
				
			});
		
		});
		
	}
		
})(jQuery);

$(document).ready(function() {
						   
	// WARSTWA PRZEWIJANA
	$('div.menu ul').jqPLScrollable();

	// USUWANIE FOCUSA
	$('a').attr('onfocus', 'blur()');
	
	// NOWE OKNO DLA LINKÓW Z ATRYBUTEM REL="TARGET"
	$('a[rel="target"]').click(function() {
		var newWindow = window.open(this.href);
		return false;
	});
	
	// PŁYNNY POWRÓT DO GÓRY
	$('a[href="#top"]').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	// OSTATNIA POZYCJA MENU
	$('div.menu ul li:last').css('background', 'none');
	
	// PŁYNNE PRZEJŚCIA POMIĘDZY PODSTRONAMI
/*	$('body').css("display", "none");
	$('body').fadeIn(2000);
	$('div.menu ul li a[href!="javascript:void(0);"]').click(function(event){
		event.preventDefault();
		linkLocation = this.href;
		$('body').fadeOut(1000, function() {
			window.location = linkLocation;
		});
	});
	
	// PŁYNNE PRZEJŚCIE KOLORÓW LINKÓW
	$('a').dwFadingLinks();
	
	// jqPLAccordion
	$('div#test ul').jqPLAccordion();*/
	
});


// PŁYNNE PRZEJŚCIE KOLORÓW LINKÓW
$.fn.dwFadingLinks = function(settings) {
	settings = jQuery.extend({
		color: '#000000',
		duration: 500
	}, settings);
	return this.each(function() {
		var original = $(this).css('color');
		$(this).mouseover(function() { $(this).animate({ color: settings.color },settings.duration); });
		$(this).mouseout(function() { $(this).animate({ color: original },settings.duration); });
	});
};

// ŚRODKOWANIE WARSTWY W PIONIE
$.fn.vAlign = function() {
	return this.each(function(i){
		var ah = $(this).height();
		var ph = $(window).height();
	//	var ph = $(this).parent().height();
		var mh = (ph - ah) / 2;
		if (mh < 0) {
			mh = 0;
		}
		$(this).css('margin-top', mh);
  });
};

$(document).ready(function() {
	$("div.main").vAlign();
});

$(window).bind('resize', function(){
	$("div.main").vAlign();
});


// Ś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-poziome").ulAlign();
});
