// AdvanceOnline Solutions, Inc. (c) 2006
// Written by Julian Calzada

function AUModel(sCourse, sModule, aSection, sCourseFolder, sModuleFolder, aSectionPage, sPageTemplate, nTotalPages, sAudioTemplate) {
	this.$courseTitle  = sCourse;
	this.$moduleTitle  = sModule;
	this.$sectionTitle = aSection;
	this.$courseFolder = sCourseFolder;
	this.$moduleFolder = sModuleFolder;
	this.$sectionPage  = aSectionPage;
	this.$pageTemp     = sPageTemplate;
	this.$totalPages   = nTotalPages;
	this.$audioTemp    = sAudioTemplate;
	this.$sectionIndex = 0;
	this.$currentPage  = 1;
};

AUModel.prototype.gotoPage = function(nPage) {
	this.$currentPage = nPage;
	
	for (var x = 0; x < this.$totalPages; x++) {
		var nSec  = this.$sectionPage[x];
		var nNSec = this.$sectionPage[x + 1];
		if (nSec <= nPage && nPage < nNSec) {
			this.$sectionIndex = x;
			break;
		} else if (isNaN(nNSec)) {
			this.$sectionIndex = x;
			break;
		}
	}
	
	var sURL   = this.$courseFolder + this.$moduleFolder + this.$pageTemp + this.$currentPage + '.htm';
	var sAudio = '../../' + this.$courseFolder + this.$moduleFolder + 'audiovideo/' + this.$audioTemp + this.$currentPage + '.flv';
	
	onChangeSection(this.$sectionPage[this.$sectionIndex]);
	onChangePage(this.$currentPage);
	onChangeAudio(sAudio);
	onChangeContent(sURL);
	this.$showButtons();
};
AUModel.prototype.goBack = function() {
	if (this.$currentPage != 1) this.gotoPage(--this.$currentPage);
};
AUModel.prototype.goNext = function() {
	if (this.$currentPage < this.$totalPages) this.gotoPage(++this.$currentPage);
};
AUModel.prototype.gotoSection = function(nSection) {
	this.gotoPage(nSection);
};

AUModel.prototype.$showButtons = function() {
	(this.$currentPage == 1) ? onShowBack(false) : onShowBack(true);
	(this.$currentPage == this.$totalPages) ? onShowNext(false) : onShowNext(true);
};
