//globals
 var news_arr=new Array();
 var news_count=1;
 var max_news=0;

$(document).ready(function() {

	$("#scroll_handle_down").bind("click",function(){
	    
	   
	    news_count +=1;
	    
	        
	    news_url=SYSTEMPATH+"code/news/get_news.php";
    	var o={};
        o.news_idx=news_count -1;
    	$.getJSON(news_url,o,function (result) {
      		 news_arr=result.liste;
      		 max_news=result.anzahl;
      		 
    		refresh_news(news_arr);
    		
    		 
    	   // if(max_news > 2 && news_count == max_news -1){
    	   //     $("#scroll_handle_down").css({visibility:"hidden"});
    	   //    
	       // }
    	});
    	
	});	
	
	//up
	$("#scroll_handle_up").bind("click",function(){
	    
	    
	    news_count -=1;
	    console.log("news_count:::"+news_count);
	    if(news_count == 1){
	      console.log("hiiierrr??????:::"+news_count);
	        $("#scroll_handle_up").css({visibility:"hidden"});
        }
	    news_url=SYSTEMPATH+"code/news/get_news.php";
    	var o={};
        o.news_idx=news_count -1;
    	$.getJSON(news_url,o,function (result) {
      		 news_arr=result.liste;
    		refresh_news(news_arr);
    	});
	});
	
	if(news_count == 1 )
        $("#scroll_handle_up").css({visibility:"hidden"});
        
	
});
/**********************************/
function refresh_news(){

        var anz=2;
    for(i=0;i<anz;i++){
        //$(’table > tr’);

        $("#news_loop_"+i+" .news_preview_titel").html(news_arr[i].titel);
        $("#news_loop_"+i+" .news_preview_date").html(news_arr[i].date);
        
        $("#news_loop_"+i+" .news_preview_content").html(news_arr[i].inhalt);
        $("#news_loop_"+i+" a").attr({href:news_arr[i].link});
       
    }
    
    if(news_count == 1)
	    $("#scroll_handle_up").css({visibility:"hidden"});
	else
	    $("#scroll_handle_up").css({visibility:"visible"});
	    
    if(news_count == max_news -1)
	    $("#scroll_handle_down").css({visibility:"hidden"});
	else
	    $("#scroll_handle_down").css({visibility:"visible"});
}

