// aktywuje wszystkie linki ajaxowe
function setAjaxLinks(){
	jQuery('.ajax').unbind("click", getAjaxContent).bind("click", getAjaxContent);
}

function getAjaxContent(){
	url = this.href;
	urlArray = url.split('/');

	if(urlArray[0] != "http"){ // wczytujemy tylko lokalne linki
		url+= (url.indexOf('?') == -1 ) ? '?ajax=true' : '&ajax=true';
	
		jQuery('#content').hide().empty(); // chowamy ramkę z treścią
		// pokazujemy informację o ładowaniu strony
		jQuery('#content').before('<div id="preloader"><img src="./img/loading.gif" alt="" /> Trwa wczytywanie strony...</div>');
		jQuery('#preloader').fadeIn();

		// wczytuje tresc za pomoca ajaxa, ukrywa preloader
		jQuery('#content').load(url, '', function(){
			jQuery('#preloader').remove();
			setAjaxLinks();
			jQuery('#content').fadeIn('slow');
		});
		return false;
	}else{
		return true;
	}
}

jQuery(document).ready(setAjaxLinks);
