function DocumentItem()
{
	var self = this;

	self.DocumentName = ko.observable("");
	self.URL = ko.observable("");
}

function DocumentManager()
{
	var self = this;

	self.SelectedIndex = ko.observable(0);
	self.Documents = ko.observableArray();

	self.getTotal = ko.computed(function()
	{
		return self.Documents().length;
	});

	self.getCurrentURL = ko.computed(function()
	{
		if(self.Documents().length > 0)
		{
			return self.Documents()[self.SelectedIndex()].URL();
		}
	});

	self.getNavTitle = ko.computed(function()
	{
		return (self.SelectedIndex()  + 1) + " of " + self.Documents().length;
	});

	self.getCurrentTitle = ko.computed(function()
	{
		if(self.Documents().length > 0)
		{
			return self.Documents()[self.SelectedIndex()].DocumentName();
		}
	});

	self.next = function()
	{
		if(self.SelectedIndex() < self.Documents().length - 1)
		{
			self.SelectedIndex(self.SelectedIndex() + 1);
		}
	}

	self.previous = function()
	{
		if(self.SelectedIndex() > 0)
		{
			self.SelectedIndex(self.SelectedIndex() - 1);
		}
	}

	self.loadDocument = function(docs)
	{
		for(var i = 0; i < docs.length; i++)
		{
			var item = new DocumentItem();

			item.DocumentName(docs[i].Category() + " - " + docs[i].DocumentName());
			item.URL(docs[i].getURL());

			self.Documents.push(item);
		}
	}

	self.addDocument = function(name, url)
	{
			var item = new DocumentItem();

			item.DocumentName(name);
			item.URL(url);

			self.Documents.push(item);
	}
}

// Viewmodel
function DocumentViewModel()
{
		var self = this;

		self.DocumentPreview = ko.observable(); 

		self.closeDocumentPreview = function()
		{
			self.DocumentPreview(null);
		}
}