    var currentPage = 0;
    var currentCat = 0;
    var total = 99;
    var buttons = new Array( "templates/new/images/butWszystkieH.jpg", 
    						 "",
    						 "templates/new/images/butSprzetH.jpg",
    						 "templates/new/images/butMultimediaH.jpg",
    						 "templates/new/images/butInternetH.jpg",
    						 "templates/new/images/butOprogramowanieH.jpg" );
    						 
    var oldbuttons = new Array( "templates/new/images/butWszystkie.jpg", 
    						 	"",
    						 	"templates/new/images/butSprzet.jpg",
    						 	"templates/new/images/butMultimedia.jpg",
    						 	"templates/new/images/butInternet.jpg",
    						 	"templates/new/images/butOprogramowanie.jpg" );

    function $(id) {
    
        return document.getElementById(id);
    }
    
    function parseRecords(content) {
	    
	    /**
	     * nie mam zamiaru sie meczyc z IE - pod ktorym xml oczywiscie nie dzialal ( dlatego jest zwyczajnie xhtml :) )
	     */
        if( content == '' ){
	        $("dynamicNews").innerHTML = '<div class="box" style="margin: 0 4px 0 0; text-align: center; height: 150px; padding-top: 100px; vertical-align: middle;"><strong>Brak danych...</strong></div><div class="box" style="margin: 4px 4px 0 0; text-align: center; height: 150px; padding-top: 100px; vertical-align: middle;"><strong>Brak danych...</strong></div><div class="box" style="margin: 4px 4px 0 0; text-align: center; height: 150px; padding-top: 100px; vertical-align: middle;"><strong>Brak danych...</strong></div>';
        }
        else{
	        $("dynamicNews").innerHTML = content;
        }
    }
    
    function getRecords() {
    
        advAJAX.get({
            url : "news.php?page="+currentPage+"&cat="+currentCat,
            uniqueParameter: "uniq",
            onInitialization : function() {
                $("dynamicNews").innerHTML = '<div class="box" style="margin: 0 4px 0 0; text-align: center; height: 150px; padding-top: 100px; vertical-align: middle;"><img src="templates/new/images/loading.gif" alt="" style="vertical-align: middle;" /> &nbsp; <strong> Pobieranie danych...</strong></div><div class="box" style="margin: 4px 4px 0 0; text-align: center; height: 150px; padding-top: 100px; vertical-align: middle;"><img src="templates/new/images/loading.gif" alt="" style="vertical-align: middle;" /> &nbsp; <strong> Pobieranie danych...</strong></div><div class="box" style="margin: 4px 4px 0 0; text-align: center; height: 150px; padding-top: 100px; vertical-align: middle;"><img src="templates/new/images/loading.gif" alt="" style="vertical-align: middle;" /> &nbsp; <strong> Pobieranie danych...</strong></div>';
            },
            onSuccess : function(obj) {
                parseRecords(obj.responseText);
            }
        });
    }
    
    function changePage(p) {
    
        currentPage += p;
        if( currentPage < 0 ){
	        alert( 'To jest pierwsza strona!' );
	        currentPage -= p;
        }else if( (currentPage+1) > total ){
	        alert( 'To jest ostatnia strona!' );
	        currentPage -= p;
        }else{
        	getRecords();
    	}
    }
    
    function setCat(cat) {
    
	    parentBut = $("but"+currentCat);
        parentBut.src = oldbuttons[currentCat];
        parentBut = $("but"+currentCat+"d");
        parentBut.src = oldbuttons[currentCat];

        currentBut = $("but"+cat);
        currentBut.src = buttons[cat];
        currentBut = $("but"+cat+"d");
        currentBut.src = buttons[cat];
        
        currentCat = cat;
	    currentPage = 0;
        getRecords();
    }