var ds1 = new Spry.Data.XMLDataSet("/xml/portfolio.xml", "rss/channel/item");

function TruncateStrIfNeeded(str, maxChars)
{
	// Decode our string so when we count characters, we aren't counting
	// the chars in an entity name.

	str = Spry.Utils.decodeEntities(str);
	if (str.length > maxChars)
		str = str.substr(0, maxChars - 4) + " ...";
	return Spry.Utils.encodeEntities(str);
}

ds1.addObserver({ onPostLoad: function() {
	var numberOfPanelsPerView = 2;
	var rows = ds1.getData();
	var numRows = rows.length;

	// Add some custom columns to our data set.

	for (var i = 0; i < numRows; i++)
	{
		var row = rows[i];

		// Add a 'teaser' column which is basically the description,
		// but truncated so it can fit within our panel.

		row.teaser = TruncateStrIfNeeded(row.desc, 400);

		// Add a 'viewStartIndex' column that indicates what view this row
		// belongs to.

		row.viewNumber = Math.floor(i / numberOfPanelsPerView) + 1;
		row.viewStartIndex = i - (i % numberOfPanelsPerView);
		row.prevStartIndex = row.viewStartIndex - numberOfPanelsPerView;
		row.nextStartIndex = row.viewStartIndex + numberOfPanelsPerView;
	}
}});