

itemsPerPage = 5;
curPos = 0;

$(function() {
	$.ajax({
		type: "GET",
		url: "/c/oth/adsfilm.xml",
		dataType: "xml",
		success: function(xmlData)
		{
			xmlDataSet = xmlData;
			browseXML();
		}
	});

});

function browseXML()
{
	
	resultSetLength = $("adsfilm",xmlDataSet).length;
	strToAppend = "<div>";
	if (curPos + itemsPerPage > resultSetLength)
	{
		showingThrough = resultSetLength;
		
	}
	else
	{
		showingThrough = parseInt(curPos + itemsPerPage);
	}
	pageRecordNum = Math.ceil(resultSetLength/itemsPerPage);
	
strToAppend += "<div style='margin-top:10px!important;margin-bottom:10px;'>";
$("title:lt(" + parseInt(curPos + itemsPerPage) + ")",xmlDataSet).filter(":gt(" + parseInt(curPos - 1) + ")").each(function(i) {
		strToAppend +="<div style='position:relative;'>"
		strToAppend += "<div style='float:left; width:120px'>" + $("images:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text() + "</div>";
		strToAppend += "<div><strong>" + $(this).text() + "</strong>";
		strToAppend += "<br />" + $("link:eq(" + parseInt(curPos + i) + ")",xmlDataSet).text() + "</div>";
		
		strToAppend +="</div><br clear='all' />"
		strToAppend += "<hr />";
	});

	strToAppend += "</div>";
if (itemsPerPage != resultSetLength)
	{
			
			strToAppend += "<div class='paging'><ul>";
			for(var i =0; i<pageRecordNum; i++){
			if (pageRecordNum == i+1)
			{
				if (i*itemsPerPage == curPos)
					{
						strToAppend += "<li class='end active'><a class='bgnone' href='#'  onclick='curPos = " + i*itemsPerPage  + ";browseXML();return false;'>" + (i+1) +   "</a></li>";
					}
				else
					{
					strToAppend += "<li class='end '><a class='bgnone' href='#'  onclick='curPos = " + i*itemsPerPage  + ";browseXML();return false;'>" + (i+1) +   "</a></li>";
					}
			}
			else
			{
				if (i*itemsPerPage == curPos)
					{		
					strToAppend += "<li class='active'><a class='bgnone' href='#'  onclick='curPos = " + i*itemsPerPage  + ";browseXML();return false;'>" + (i+1) +   "</a></li>";
					}
				else
					{
					strToAppend += "<li><a class='bgnone' href='#'  onclick='curPos = " + i*itemsPerPage  + ";browseXML();return false;'>" + (i+1) +   "</a></li>";
					}

			}
}
				strToAppend += "</ul></div>";
							
		
	}
	strToAppend += "</div>";
	
	$("#adsfilmxml").html(strToAppend);
}

