oped_itemsPerPage = 5;
oped_curPos = 0;

$(function() {
	$.ajax({
		type: "GET",
		url: "./oped.xml",
		dataType: "xml",
		success: function(xmlData)
		{
			oped_xmlDataSet = xmlData;
			oped_XML();
		}
	});
});

function oped_XML()
{

	oped_resultSetLength = $("article",oped_xmlDataSet).length;
	oped_strToAppend = "";

	$("name:lt(" + parseInt(oped_curPos + oped_itemsPerPage) + ")",oped_xmlDataSet).filter(":gt(" + parseInt(oped_curPos - 1) + ")").each(function(i) {
		oped_strToAppend += '<p class="project"><a href="' + $("link:eq(" + parseInt(oped_curPos + i) + ")",oped_xmlDataSet).text() + '">';
		oped_strToAppend +=  $(this).text() + "</a></p>";
		oped_strToAppend += ' <p class="meta">' + $("author:eq(" + parseInt(oped_curPos + i) + ")",oped_xmlDataSet).text() + '  |  ';
		oped_strToAppend += $("pub:eq(" + parseInt(oped_curPos + i) + ")",oped_xmlDataSet).text() + '  |  ';
		oped_strToAppend += $("date:eq(" + parseInt(oped_curPos + i) + ")",oped_xmlDataSet).text() + '</p>';
	});


		oped_strToAppend += "<div class='Nav'>";		

		if (oped_itemsPerPage != oped_resultSetLength)
		{
			if (oped_curPos == 0) // First page. Go forward only.
			{
				oped_strToAppend += "<img src='images/prev_disabled.jpg' />";

					if (oped_curPos + oped_itemsPerPage > oped_resultSetLength)
					{
						showingThrough = oped_resultSetLength;
					}
					else
					{
						showingThrough = parseInt(oped_curPos + oped_itemsPerPage);
					}
					
				oped_strToAppend += "<a href='#' onclick='oped_curPos += " + oped_itemsPerPage + ";oped_XML();return false;'><img src='images/next.jpg' /></a>";
			}
			if (oped_curPos > 0 && parseInt(oped_curPos + oped_itemsPerPage) < oped_resultSetLength) // Somewhere inbetween.
			{
				oped_strToAppend += "<a href='#' onclick='oped_curPos -= " + oped_itemsPerPage + ";oped_XML();return false;'><img src='images/prev.jpg' /></a>";

					if (oped_curPos + oped_itemsPerPage > oped_resultSetLength)
					{
						showingThrough = oped_resultSetLength;
					}
					else
					{
						showingThrough = parseInt(oped_curPos + oped_itemsPerPage);
					}
					
				oped_strToAppend += "<a href='#' onclick='oped_curPos += " + oped_itemsPerPage + ";oped_XML();return false;'><img src='images/next.jpg' /></a>";
			}
			if (parseInt(oped_curPos + oped_itemsPerPage) >= oped_resultSetLength) // Last page. Go back only.
			{
				oped_strToAppend += "<a href='#' onclick='oped_curPos -= " + oped_itemsPerPage + ";oped_XML();return false;'><img src='images/prev.jpg' /></a>";

					if (oped_curPos + oped_itemsPerPage > oped_resultSetLength)
					{
						showingThrough = oped_resultSetLength;
					}
					else
					{
						showingThrough = parseInt(oped_curPos + oped_itemsPerPage);
					}
					
				oped_strToAppend += "<img src='images/next_disabled.jpg' />";				
			}
		}

		oped_strToAppend += "<div>";
		
/*
	Populate our DIV with the HTML we have constructed.
*/
	$("#opedWidget").html(oped_strToAppend);
}
/*
	Obfuscated, and without comments, this script would
	probably only be about 2 KB.
*/

