// JavaScript Document
	//const
	var PAGE_SIZE = 10;
	
	//Global_var
	var newsList = null;
	var totalRecord;
	var beginRecord;
	var endRecord;
	var curPage = 1;
	var totalPages = 1;
	
	function getArticles(){
		$.getJSON(CONST_URL_NEWS,
		{"method":"getArticlesListToJSON",
			"records":1000000,
			"catalogName":"marketing",
			"time":new Date()},
			initData
			);
	}
			
	function initData(data){
		newsList = data;
		totalRecord = newsList.length;
		changePage(1);
	}
	
	function calculate(currentPage){
		totalPages = Math.floor(totalRecord / PAGE_SIZE);
        if (totalRecord % PAGE_SIZE > 0 ) totalPages++;
        if (currentPage*PAGE_SIZE>totalRecord){
            currentPage = totalPages;
            endRecord = totalRecord-1;
        }
        if (currentPage<1) currentPage = 1;
        curPage = currentPage;
        //calculate the beginResult
        beginRecord = (currentPage-1)*PAGE_SIZE;
        endRecord = beginRecord + PAGE_SIZE;
        if (beginRecord<0) beginRecord = 0;
        if (endRecord>=totalRecord) endRecord = totalRecord-1;
	}
	
	function changePage(currentPage){
		calculate(currentPage);
		var filterData = $.grep(newsList,function(n,i){
			return (i>=beginRecord && i<= endRecord);
		})
		renderTable(filterData);
	}
			
	function renderTable(data){
			$('#marketing').html("");
			$.each(data, addOneTd);
			
	}
			
	function addOneTd(index,entry){
			var title = entry.title;
			if(title.length>=26) title = title.substring(0,27)+"...";
			var html = '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
			html += '<tr>';
			html += '<td width="25%" height="38" align="left" valign="middle"><a href="'+entry.artURL+'" target="_blank"><img src="'+ entry.imgsrc+'" border="0" align="absmiddle" /></a></td>';
			html += '<td width="75%" height="38" valign="middle">'+ '<a href="aboutExample2.html?id='+entry.id+'" target="_blank">' + title + '</a></td>';
			
			html += '</tr>';
            html += '<tr>';
			$('#marketing').append(html);
	}
			
	$(document).ready(getArticles);
	