// Douglas County Government. XML feed for news and video on main page.

function loadPage() {	
	// Load dynamic page content
	loadPageContent();
}
var dsHeadlines = new Spry.Data.XMLDataSet("/news/headlines.xml", "rss/channel/item",{sortOnLoad:"pubDate",sortOrderOnLoad:"descending",distinctOnLoad:true,useCache:false});
dsHeadlines.setColumnType("pubDate", "date");

var dsMovie = new Spry.Data.XMLDataSet("/media/main_playlist.xml", "playlist/trackList/track");

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);
}

dsMovie.addObserver({ onPostLoad: function() {
	var numberOfPanelsPerView = 4;
	var rows = dsMovie.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;
	}
}});

var currentPosition;
	var currentItem;
	
	// these functions are caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
	function getUpdate(typ,pr1) {
		if(typ == "time") { currentPosition = pr1; }
		else if(typ == "item") { currentItem = pr1;}
		var id = document.getElementById(typ);	
	};	
	// This is a javascript handler for the player and is always needed.
	function thisMovie(movieName) {
	    if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}