var topPosition = 1;
var step = 400;
var flaga = 0;


function getNews(){
    var offset = $("#offset").val();
    $.ajax({
        url:'index.php/news/getnews',
        type: 'post',
        data: 'offset='+offset,
        dataType: 'html',
        success: function(html){
            $("#news-abs").append(html);
            $('#offset').val(parseInt(offset) +1);
        }
    });
}

function goDown(){
   
   //console.log(-(parseInt(($('#news-abs').css('top').substr(0,($('#news-abs').css('top').length)-2))))+601+' < '+document.getElementById( 'news-abs' ).clientHeight);
   //window.alert(-(parseInt(($('#news-abs').css('top').substr(0,($('#news-abs').css('top').length)-2))))+601+" < "+parseInt(($('#news-abs').css('height').substr(0,($('#news-abs').css('height').length)-2))));
   if(-(parseInt(($('#news-abs').css('top').substr(0,($('#news-abs').css('top').length)-2))))+step+1 < document.getElementById( 'news-abs' ).clientHeight){
         flaga=1;
        getNews();
        topPosition = topPosition-step;
        
        $('#news-abs').animate({
            top: parseInt(topPosition)+'px'
        },1000,function(){
            flaga=0;
        });
    }
}

function goUp(){
     
    //window.alert(topPosition);
    if(topPosition!=1){
        flaga=1;
        topPosition = topPosition+step;
        $('#news-abs').animate({
            top: topPosition+'px'
        },1000,function(){
            flaga=0;
        });
    }
}

$(document).ready(function(){
 

    //getDivHeight();

    $("#offset").val(1);
    getNews();

    $('#next, #prev').hover(function(){
        $(this).css("backgroundPosition",'0 -32px');
    },function(){
        $(this).css("backgroundPosition",'0 0');
    });

    $('#next').click(function(){
        //console.log(flaga);
        if(flaga==0)goUp();
       // getDivHeight();
    });

    $('#prev').click(function(){
       // console.log(flaga);
        if(flaga==0)goDown();
    });

    $("#bunny").click(function(){
       window.location.href='http://www.gulestus.pl/index.php/site/login';
    });

});

