//******************************************************************************
//Content Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function Content(file)
{
	this._xml = xmlLoadFromFile(file);
	this._meta = new Meta(this._xml.getElementsByTagName("MetaData")[0]);	
	this._chapters = new Chapters(this._xml.getElementsByTagName("RecordingEvent"));
	this._slides = new Slides(this._xml.getElementsByTagName("RecordingEvent"));
	this._videos = new Videos(this._xml.getElementsByTagName("RecordingView"));
	this._searchItems = new SearchItems(this._xml.getElementsByTagName("RecordingEvent"));
}

////////////////////////////////////////////////////////////////////////////////
//private members

Content.prototype._xml;
Content.prototype._meta;
Content.prototype._chapters;
Content.prototype._slides;
Content.prototype._videos;
Content.prototype._searchItems;

////////////////////////////////////////////////////////////////////////////////
//public members

Content.prototype.Xml = function(){
		return this._xml;
	}
Content.prototype.Meta = function(){
		return this._meta;
	}

Content.prototype.Chapters = function(){
		return this._chapters;
	}

Content.prototype.Slides = function(){
		return this._slides;
	}

Content.prototype.Videos = function(){
		return this._videos;
	}

Content.prototype.SearchItems = function(){
		return this._searchItems;
	}


//******************************************************************************
//Meta Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function Meta(xml)
{
	this._xml = xml;
}

////////////////////////////////////////////////////////////////////////////////
//private members

Meta.prototype._xml;

////////////////////////////////////////////////////////////////////////////////
//public members

Meta.prototype.GetTitle = function(){
		return xmlGetElementValue(this._xml,"Subject");
	}

Meta.prototype.GetAuthor = function(){
		return xmlGetElementValue(this._xml,"Speakers");
	}

Meta.prototype.GetDate = function(){
		return xmlGetElementValue(this._xml,"DateString");
	}


//******************************************************************************
//Chapters Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function Chapters(xml)
{
	this._xml = xml;
	this._count = 0;
	this._chapters = new Array();

	for(var i=0;i<this._xml.length;i++)
	{
		if(xmlGetElementValue(this._xml[i],"Type")=="chapter")
		{
			this._chapters[this._count] = new Chapter(this._xml[i]);
			this._count += 1;
		}		
	}

}

////////////////////////////////////////////////////////////////////////////////
//private members

Chapters.prototype._xml;
Chapters.prototype._count;
Chapters.prototype._chapters;

////////////////////////////////////////////////////////////////////////////////
//public members

Chapters.prototype.GetCount = function(){
		return this._count;
	}

Chapters.prototype.GetChapter = function(index){
		return this._chapters[index];
	}

//******************************************************************************
//Chapter Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function Chapter(xml)
{
	this._xml = xml;
	this._title = xmlGetElementValue(this._xml,"Title");
	this._time = xmlGetElementValue(this._xml,"TimeInSeconds");
}

////////////////////////////////////////////////////////////////////////////////
//private members

Chapter.prototype._xml;
Chapter.prototype._title;
Chapter.prototype._time;

////////////////////////////////////////////////////////////////////////////////
//public members

Chapter.prototype.GetTitle = function(){
		return this._title;
	}

Chapter.prototype.GetTime = function(){
		return this._time;
	}



//******************************************************************************
//Slides Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function Slides(xml)
{
	this._xml = xml;
	this._count = 0;

	this._slides = new Array();

	for(var i=0;i<this._xml.length;i++)
	{
		if(xmlGetElementValue(this._xml[i],"Type")=="image")
		{
			this._slides[this._count] = new Slide(this._xml[i]);
			this._count += 1;
		}		
	}
	
}

////////////////////////////////////////////////////////////////////////////////
//private members

Slides.prototype._xml;
Slides.prototype._count;
Slides.prototype._slides;

////////////////////////////////////////////////////////////////////////////////
//public members

Slides.prototype.GetCount = function(){
		return this._count;
	}

Slides.prototype.GetSlide = function(index){
		return this._slides[index];
	}


//******************************************************************************
//Slide Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function Slide(xml)
{
	this._xml = xml;
	this._time = xmlGetElementValue(this._xml,"TimeInSeconds");
	this._fileThumb = xmlGetElementValue(this._xml,"Parameter") + "_thumb.JPG";
	this._fileNormal = xmlGetElementValue(this._xml,"Parameter") + "_normal.JPG" 
	this._fileLarge = xmlGetElementValue(this._xml,"Parameter") + "_large.JPG" 
}

////////////////////////////////////////////////////////////////////////////////
//private members

Slide.prototype._xml;
Slide.prototype._time;
Slide.prototype._fileThumb;
Slide.prototype._fileNormal;
Slide.prototype._fileLarge;

////////////////////////////////////////////////////////////////////////////////
//public members

Slide.prototype.GetTime = function(){
		return this._time;
	}

Slide.prototype.GetFileThumb = function(){
		return this._fileThumb;
	}

Slide.prototype.GetFileNormal = function(){
		return this._fileNormal;
	}

Slide.prototype.GetFileLarge = function(){
		return this._fileLarge;
	}


//******************************************************************************
//Videos Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function Videos(xml)
{
	this._xml = xml;
	this._count = 0;

	this._videos = new Array();

	for(var i=0;i<this._xml.length;i++)
	{
		this._videos[this._count] = new Video(this._xml[i]);
		this._count += 1;		
	}
	
}

////////////////////////////////////////////////////////////////////////////////
//private members

Videos.prototype._xml;
Videos.prototype._count;
Videos.prototype._videos;

////////////////////////////////////////////////////////////////////////////////
//public members

Videos.prototype.GetCount = function(){
		return this._count;
	}

Videos.prototype.GetVideo = function(index){
		return this._videos[index];
	}


//******************************************************************************
//Video Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function Video(xml)
{
	this._xml = xml;
	this._file = xmlGetElementValue(this._xml,"FileName");
}

////////////////////////////////////////////////////////////////////////////////
//private members
Video.prototype._xml;
Video.prototype._file;

////////////////////////////////////////////////////////////////////////////////
//public members

Video.prototype.GetFile = function(){
		return this._file;
	}



//******************************************************************************
//SearchItems Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function SearchItems(xml)
{
	this._xml = xml;
	this._count = 0;
	this._searchItems = new Array();

	for(var i=0;i<this._xml.length;i++)
	{
		this._searchItems[this._count] = new SearchItem(this._xml[i]);
		this._count += 1;
				
	}

}

////////////////////////////////////////////////////////////////////////////////
//private members

SearchItems.prototype._xml;
SearchItems.prototype._count;
SearchItems.prototype._searchItems;

////////////////////////////////////////////////////////////////////////////////
//public members

SearchItems.prototype.GetCount = function(){
		return this._count;
	}
SearchItems.prototype.GetSearchItem = function(index){
		return this._searchItems[index];
	}

SearchItems.prototype.SearchFor = function(term){
	var results = new Array();
	var resultCnt = 0;
	term = term.toLowerCase();
	for(var i=0; i<this._searchItems.length; i++)
	{
		var t = this._searchItems[i].GetText();
		t = t.toLowerCase();
		if(!(t.indexOf(term)==-1))
		{
			results[resultCnt] = this._searchItems[i];
			resultCnt++;
		}
	}
	if(resultCnt>0)
		return results;
	return null;
}

//******************************************************************************
//SearchItem Class

////////////////////////////////////////////////////////////////////////////////
//contructor
function SearchItem(xml)
{
	this._xml = xml;
	switch(xmlGetElementValue(this._xml,"Type"))
	{
		case "image":
			try
			{
				this._text = xmlGetElementValue(this._xml,"SearchableText");
			}
			catch(ex)
			{
				this._text = "";
			}
			this._time = xmlGetElementValue(this._xml,"TimeInSeconds");
			this._fileThumb = xmlGetElementValue(this._xml,"Parameter") + "_thumb.JPG";
			break;
		case "chapter":
			try
			{
				this._text = xmlGetElementValue(this._xml,"SearchableText");
			}
			catch(ex)
			{
				this._text = "";
			}
			this._time = xmlGetElementValue(this._xml,"TimeInSeconds");
			this._fileThumb = "";
			break;
	}
	
}

////////////////////////////////////////////////////////////////////////////////
//private members

SearchItem.prototype._xml;
SearchItem.prototype._text;
SearchItem.prototype._time;
SearchItem.prototype._fileThumb;

////////////////////////////////////////////////////////////////////////////////
//public members

SearchItem.prototype.GetText = function(){
		return this._text;
	}

SearchItem.prototype.GetTime = function(){
		return this._time;
	}

SearchItem.prototype.GetFileThumb = function(){
		return this._fileThumb;
	}