/*
 * Copyright (c) 1995-2011 by 4system Polska Sp. z o.o.
 * All Rights Reserved. v4
 */
//-------------------------------------------------------------------------------------------
//pg2-limit time for some pages
function __LimitTimeForQuizTimer() //pg2-limit timer
{
	this.id = null;
	this.interval = 10000; //10 sec
	this.pageBeforeQuizGIX = -1;
	this.pageAfterQuizGIX = -1;
	this.pagesWithinQuiz = new Array();
	this.busy = 0;
	this.ready = 0;
	this.paramsSeparator = '||';
	this.correctParamsLength = 4;
	this.quizPagesSeparator = ',';
	
	this.subID = null;
	this.subBusy = 0;
	this.dateEnd = 0;
}

__LimitTimeForQuizTimer.prototype.onInterval = function()
{
	try {
		this.stop();
		this.ready = 0;
		this.busy = 0;
		if (!player) return;
		try {
			if (player.gotoPage) player.gotoPage(this.pageAfterQuizGIX);
			/*
			var frm = player.getFrame(player.gix).frame;//player.getFrame(player.gix).frame.PageInterface.connectedPage; //player.getFrame(player.gix).PlayerInterface.connectedPage;
			if (frm) {
				frm.pc.timerText.setHTML("bla");
			}*/
		} catch(e) {};
	} catch(e) {};
}

__LimitTimeForQuizTimer.prototype.subInterval = function()
{
	try {
		window.clearTimeout(this.subID);
		if (this.dateEnd == 0) {
			this.subBusy = 0;
			return;
		}
		var date2 = new Date();
		var ms2 = date2.getTime();
		
		var timeShift = this.dateEnd - ms2;
		var str = calculateTimeIntToString(timeShift/1000);
		var dotPos = str.indexOf('.');
		if (dotPos > 0) str = str.substr(0, dotPos);
		
		var frm = null;
		if (player && player.getFrame) {
			frm = player.getFrame(player.gix).frame; //if on a page there is text component named 'timerText' - withing it will be displayed remaining time for a quiz
			if (frm) {
				if (frm.pc && frm.pc.timerText) {
					frm.pc.timerText.setHTML(str);
					frm.pc.timerText.show();
				}
			}
		}
		
		if (this.subBusy) this.subID = window.setTimeout('player.limitQuizTimeTimer.subInterval();', 500);
	} catch(e) {
		this.subBusy = 0;
	};
}


__LimitTimeForQuizTimer.prototype.start = function()
{
	if (!this.ready || this.busy) return;
	this.stop();
	try {
		this.id = window.setTimeout('player.limitQuizTimeTimer.onInterval();', this.interval);
	} catch(e) {
		this.busy = 0;
	}
	try { 
		var dt = new Date();
		this.dateEnd = dt.getTime() + this.interval;
		this.subID = window.setTimeout('player.limitQuizTimeTimer.subInterval();', 500);
		this.subBusy = 1;
		//
	} catch(e) {
		this.subBusy = 0;
	};
}

__LimitTimeForQuizTimer.prototype.stop = function()
{
	window.clearTimeout(this.id);
	this.id = null;
	this.busy = 0;
	this.dateEnd = 0;
	this.subBusy = 0;
	window.clearTimeout(this.subID);
	this.id = null;
	this.subID = null;
}

__LimitTimeForQuizTimer.prototype.notifyNavigateToPage = function(GIX)
{
	if (typeof(GIX) == "undefined") return;
	if (!this.ready) return;
	if (GIX == -1) {
		this.stop();
		return;
	}
	try {
		var pageGIX = parseInt(GIX);
		if (pageGIX == this.pageAfterQuizGIX && this.busy) {
			this.stop();
			return;
		}
		
		var pageInArray = false;
		var pageInArrayNo = -1;
		for (var i=0; i<this.pagesWithinQuiz.length; i++) {
			var pageGIXFromArray = this.pagesWithinQuiz[i];
			if (pageGIXFromArray == pageGIX) {
				pageInArray = true;
				pageInArrayNo = i;
				break;
			}
		}
		if (pageInArray && pageInArrayNo == 0) {
			this.start(); //1st quiz page, start timer
		}
		if (!pageInArray) this.stop();
		
	} catch(e) {
		//
	}
}

__LimitTimeForQuizTimer.prototype.setParameters = function(params) // pageBeforeQuizGIX || quizPage1, quizPage2, ..., guizPageN || pageAfterQuizGIX || interval
{
	if (this.busy) return;
	this.ready = 0;
	if (typeof(params) == "undefined") return;
	if (params == "") return;
	
	try {
		var paramsList = params.split(this.paramsSeparator);
		if (paramsList.length != this.correctParamsLength) return;
		
		//page before quiz
		var pageGIX = 0;
		try {
			pageGIX = parseInt(paramsList[0]);
		} catch(e) {
			pageGIX = -1;
		};
		if (pageGIX < 2) return;
		this.pageBeforeQuizGIX = pageGIX; //
		
		//page after quiz
		pageGIX = 0;
		try {
			pageGIX = parseInt(paramsList[2]);
		} catch(e) {
			pageGIX = -1;
		}
		if (pageGIX < 2) return;
		this.pageAfterQuizGIX = pageGIX;
		
		//timer interval - time to go through all quiz pages
		var interval = 0;
		try {
			interval = parseInt(paramsList[3]);
		} catch(e) {
			interval = -1;
		}
		if (interval < 1000) return;
		this.interval = interval;
		
		// remove all elements from array
		delete this.pagesWithinQuiz;
		this.pagesWithinQuiz = new Array();
		
		//quiz pages
		var quizPages = paramsList[1];
		var quizPagesArray = quizPages.split(this.quizPagesSeparator);
		if (quizPagesArray.length == 0) return;
		var parseError = 0;
		for (var i=0; i<quizPagesArray.length; i++) {
			try {
				pageGIX = parseInt(quizPagesArray[i]);
				if (pageGIX < 2) {
					parseError = 1;
					break;
				} else {
					this.pagesWithinQuiz.push(pageGIX);
				}
			} catch(e) {
				parseError = 1;
				break;
			}
		}
		if (parseError == 1) return;
		
		this.ready = 1;
	} catch(e) {
		this.ready = 0;
		this.busy = 0;
	}
}

//-------------------------------------------------------------------------------------------
function __Frame()
{
	this.locked = false;
	this.content = false;
	this.gix = -1;
	this.frame = null;
};
function __Timer()
{
	this.interval = 250;
	this.tryCounter = 0;
	this.id = null;
};
__Timer.prototype.onInterval = function()
{
	this.stop();
	var frm = player.getFrame(player.gix);
	if (!frm) {
		player.pgPreloaderLoad(player.gix);
		frm = player.getFrame(player.gix);
	}
	if (frm) {
		if (frm.frame.PlayerInterface 
			&& frm.frame.PlayerInterface.connectedPage 
			&& player.gix == frm.frame.PlayerInterface.connectedPage.p_globalIndex) 
		{ 	
			if (!frm.frame.PlayerInterface.connectedPage.allowPreload) {
				return;
			};		
			if ((frm.frame.PlayerInterface.connectedPage.waitingForRun) || (this.tryCounter > 20)) {
				this.tryCounter = 0;
				frm.frame.PlayerInterface.connectedPage.loadContent();
			} else 
			if (frm.frame.PlayerInterface.connectedPage.isRuning) {				
				player.preloadPages(player.gix);
				return;
			}
		} else {
			try { //pg2-in case of https:// and a course in new window, there could be an exception- just intercept it, do nothing
				if (frm.frame.extContent) {
					if ((frm.frame.waitingForRun) || (this.tryCounter > 20)) {
						this.tryCounter = 0;
						frm.frame.loadContent();
					} else
					if (frm.frame.isReady) {
						player.preloadPages(player.gix);
						return;
					}
				}
			} catch(e) {};
		}
	}
	this.tryCounter++;
	this.run();
};
__Timer.prototype.run = function()
{
	this.stop();
	this.id = window.setTimeout('__timer.onInterval();', this.interval);
};
__Timer.prototype.stop = function()
{
	if (this.id != null) {
		window.clearTimeout(this.id);
		this.id = null;
	}
};
var __timer = new __Timer();
// debugger
var ___cool_timer_enabled = false;
var ___cool_timer_turn = false;
var ___cool_timer_last_gix = -1;
var ___cool_timer = null;
var ___cool_timer_interval = 1000;
function ___cool_timer_stop() {
	if (___cool_timer != null) {
		window.clearTimeout(___cool_timer);
		___cool_timer = null;
	}
};
function ___cool_timer_start() {
	___cool_time = window.setTimeout('___cool_timer_onInterval();', ___cool_timer_interval);
};
function ___cool_timer_onInterval() {
	___cool_timer_stop();
	if (!___cool_timer_turn) {
		if (player.further()) ___cool_timer_last_gix = -1;
	} else {
		player.backwards();
	}
	if (___cool_timer_last_gix == player.gix) {
		___cool_timer_turn = !___cool_timer_turn;
	}
	___cool_timer_last_gix = player.gix;
	___cool_timer_start();
};
// debugger end
function Player()
{
	// debugger
	this.gixF = -1;
	this.gixL = -1;
	// debugger end
	
	this.STATUS_NOT_ATTEMPTED = "not attempted";
	this.STATUS_INCOMPLETE = "incomplete";
	this.STATUS_COMPLETED = "completed";
	this.STATUS_UNKNOWN = "unknown";
	this.STATUS_PASSED = "passed";
	this.STATUS_FAILED = "failed";
	
	this.gix = 0;
	this.last_gix = 0;
	this.framesToLoad = 0;
	this.baseurl = location.href.split("?");
	this.naviPathToRoot = this.baseurl[0].substring(0, this.baseurl[0].lastIndexOf('/')) + '/';
	this.sid = this.createSID();
	
	this.isLightVersion = false;
	this.courseVersion = 0;
	
	if (this.naviPathToRoot == "") this.naviPathToRoot = location.href.substring(0, location.href.lastIndexOf('\\')) + '/';
	
	this.setupURIParams();
	
	this.enablePagesPreloader = false;
	this.pagesPreloaderFrame = null;
	this.pagesPreloaderContentFrame = null;
	//this.pgPreloaderSrc = this.naviPathToRoot;
	this.isLoaded = false;
	this.wasLoaded = false;
	this.passLevel = 100;	
	
	this.gix_offset = 0;
	this.down_max = 1;
	this.up_max = 2;
	this.pg_max = 1;
	
	this.__frames = new Object();
	this.pageChanged = null;
	this.startTime = new Date();
	this.debugMode = false;
	this.lmsTimer = null;
	this.activTimer = null;
	this.updateLMSTimeInterval = 0; //co ile wysłać info do lms'a o: stronie na ktorej jestem
	this.lastActiveStudentTime = new Date(); //ostatnia atywnosc studenta
	this.activityTime = 0; //laczny czas aktywnosci studenta w tej sesji jako int w sek
	this.lessonBreak = false; //jesli true nie licz aktuwnosci i nie pokazuj warning popup
	//dbg course
	this.resetCourseData = false;  
	this.dbgCourseScore = -1;  
	this.dbgCourseStatus = ""; 		
	this.reinitializeTree = false; //pg2-bsh -for repainting statuses of pages in template's tree
	
	this.openWindows = new Array();	
	this.pageFirstStepListeners = new Array();
	this.pageLastStepListeners = new Array();
	
	this.courseHasInteractions = true; //pg2
	
	this.limitQuizTimeTimer = new __LimitTimeForQuizTimer(); //pg2-limit timer
	//this.limitQuizTimeTimer.setParameters("2||3,4,5,6,7||8||3000"); //pg2-limit timer test
};

Player.prototype.limitQuizTimeInit = function(params)
{
	if (typeof(params) == "undefined") params = "";
	if (this.limitQuizTimeTimer) this.limitQuizTimeTimer.setParameters(params);
}

Player.prototype.limitQuizTimeStart = function()
{
	if (!this.limitQuizTimeTimer) return;
	this.limitQuizTimeTimer.start();
}

Player.prototype.limitQuizTimeStop = function()
{
	if (!this.limitQuizTimeTimer) return;
	this.limitQuizTimeTimer.stop();
}

Player.prototype.limitQuizTimeNotifyNavigateToPage = function(params)
{
	if (!this.limitQuizTimeTimer) return;
	if (typeof(params) == "undefined") return;
	if (params == "") params = -1;
	this.limitQuizTimeTimer.notifyNavigateToPage(params);
}

Player.prototype.findTypeAndCallFunc = function(type, func)
{
	//this
	try {
		var frm = player.getFrame(player.gix);
		if (frm && frm.frame.PlayerInterface && frm.frame.PlayerInterface.connectedPage) {
			frm.frame.PlayerInterface.connectedPage.findTypeAndCallFunc(type, func);
		} else 
		if (typeof(page) == "object") {
			page.findTypeAndCallFunc(type, func);
		}
	} catch(e) {}
	//child
	for (var i in this.openWindows) {
		try {
			var w = this.openWindows[i];
			w.page.findTypeAndCallFunc(type, func);
		} catch(e) {}
	}
	//parent
	try {
		if (typeof(opener.getPlayer) == "object") {
			var p = opener.getPlayer();
			if (p) {
				p.findTypeAndCallFunc(type, func);
			}
		}
	} catch(e) {}
}
Player.prototype.setupURIParams = function()
{
	var v = getURIParam("wbteLightVersion");
	if (v == "true" || v == "1")
	{
		this.isLightVersion = true;
	}
	var v = getURIParam("wbteVersion");
	if (v != "")
	{
		this.courseVersion = v;
	}
};
Player.prototype.setLightVersion = function(b)
{
	this.isLightVersion = (b == true);
	this.gotoPage(this.gix);
};
Player.prototype.getLightVersion = function()
{
	return this.isLightVersion;
};
//jk  move to uelo
Player.prototype.getLessonStatusWithoutSendIdPage = function(thisId)
{
	for (var i = 0; i < struct.length(); i++) {
		if ((struct.item(i)["visible"] == "1") && (struct.item(i)["index"] != thisId)) 
			if (struct.item(i)["status"] == "I" || struct.item(i)["status"] == "N") return this.STATUS_INCOMPLETE;
	}
	return this.STATUS_COMPLETED;
};
Player.prototype.getStatusPassedFailed = function()
{
	var score = this.getTotalScore();
	
	if (score == "") {
		return this.STATUS_UNKNOWN;
	} else {
		if (this.getTotalScore() >= uelo.passThreshold){
			return this.STATUS_PASSED;
		} else {
			return this.STATUS_FAILED;
		}
	}
}
Player.prototype.getPercCompletedFailedPassed = function()
{
	var allVisible = 0;
	var allCounted = 0;
	
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["iss"] == "0") continue;		
		if (item["visible"] == "1") {
			if (item["status"] == "C" || item["status"] == "P" || item["status"] == "F") {
				allCounted++;				
			};
			allVisible++;
		};
	};
	var prec = parseInt((allCounted/allVisible*100).toFixed(0));
	return prec;
}
Player.prototype.getAllPagesCount = function() //modyfication from MK
{
	var allVisible = 0;
	var allCounted = 0;
	
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["iss"] == "0") continue;		
		if (item["visible"] == "1") {
			if (item["status"] == "C" || item["status"] == "P" || item["status"] == "F") {
				allCounted++;				
			};
			allVisible++;
		};
	};
	return allVisible;
}
Player.prototype.getVisitedPagesCount = function() //modyfication from MK
{
	var allVisible = 0;
	var allCounted = 0;
	
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["iss"] == "0") continue;		
		if (item["visible"] == "1") {
			if (item["status"] == "C" || item["status"] == "P" || item["status"] == "F") {
				allCounted++;				
			};
			allVisible++;
		};
	};
	return allCounted;
}
Player.prototype.getStatusCompletedIncompleted = function()
{
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["iss"] == "0") continue;		
		if (item["visible"] == "1") {
			if (item["status"] == "I" || item["status"] == "N") {
				return this.STATUS_INCOMPLETE;
			};
		};
	};
	return this.STATUS_COMPLETED;
}
Player.prototype.getProgressMeasure = function()
{
	var c = 0;
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["iss"] == "0") continue;		
		if (item["visible"] == "1") {
			if ((item["status"] == "C") || (item["status"] == "P") || (!this.courseHasInteractions && item["status"] == "F")) { //pg2-completion -if course has no interactions (but on some page answer was checked without exercise component...
				c++;
			}
		};
	};
	
	if (c == struct.length()) {
		return "1.0";
	} else if (c == 0) {
		return "0.0";
	} else {
		if (config.progressMeasure3State) {
			return "0.5";
		} else {
			return (c / struct.length()).toFixed(2);
		}
	}
}
Player.prototype.getLessonStatus = function()
{
	if (this.dbgCourseStatus != "") return this.dbgCourseStatus;
	
    if(config.sendPassedFailedToServer){
		return this.getStatusPassedFailed();
    } else {
		return this.getStatusCompletedIncompleted();
    };
};
Player.prototype.getLessonCIPF = function(pf)
{
	if (pf) {
		var result = this.STATUS_UNKNOWN;
	} else {
		var result = this.STATUS_NOT_ATTEMPTED;
	}
	var stLen = struct.length();
	for (var i = 0; i < stLen; i++) {
		var item = struct.item(i);
		if (item["visible"] == "1") {
			var as = item["status"];
			if (pf) {
				if (as == "F") {
					return this.STATUS_FAILED;
				} else 
				if (as == "P") {
					result = this.STATUS_PASSED;
				}
			} else {
				if (as == "I" || as == "N") {
					return this.STATUS_INCOMPLETE;
				} else 
				if (as == "C") {
					result = this.STATUS_COMPLETED;
				}
			}
		}
	}
	
	return result;
};
//jk  move to uelo
Player.prototype.getItemStatus = function(index)
{
	if (index == null || index == "undefined") index = this.gix;
	var itemStatus = struct.findItem(index)["status"];
	switch (itemStatus) {
		case "N": return this.STATUS_NOT_ATTEMPTED; break;
		case "I": return this.STATUS_INCOMPLETE; break;
		case "C": return this.STATUS_COMPLETED; break;
		case "P": return this.STATUS_PASSED; break;
		case "F": return this.STATUS_FAILED; break;
	}
};
Player.prototype.checkPageStatus = function(index, status, checkChildren)
{
	if (index == null || index == "undefined") index = this.gix;
	var item = struct.findItem(index);
	var result = this.inArray(this.getItemStatus(item["gix"]), status.split(","));
	if (checkChildren) {
		for (var i=0; i < struct.length(); i++) {
			var childItem = struct.item(i);
			if (childItem["parent"] == item["index"]) {
				if (this.hasChildren(childItem["gix"])) {
					result = result + this.checkPageStatus(childItem["gix"], status, checkChildren);
				} else {
					result = result + this.inArray(this.getItemStatus(childItem["gix"]), status.split(","));
				}
			}
		}
	}
	return result;
};
Player.prototype.hasChildren = function(index)
{
	if (index == null || index == "undefined") index = this.gix;
	var item = struct.findItem(index);
	for (var i = 0; i < struct.length(); i++) {
		var childItem = struct.item(i);
		if (childItem["parent"] == item["index"]) return true;
	}
	return false;
};
Player.prototype.loadContent = function(gix)
{
	if (this.enablePagesPreloader) return;
	this.setSessionTime();
	this.gix = gix;
	
	var tree_frame = this.findFrame("tree");
	if (tree_frame) tree_frame.expandMyParents(this.gix);
	var item = struct.findItem(gix);
		
	this.updateTemplateProgress(item);
		
	if (item) {
		var link = this.naviPathToRoot + item["href"];
		if (item["type"] == "0") {
			link += '_page.' + this.courseVersion;
			if (this.isLightVersion)
			{
				link += '.light';
			}
			link += '.html';
		}
		this.loadContentFrameset(link);
		this.setNaviHtml("_page_no_navi", struct.getVisibleItemsIndex(this.gix) 
			+ " / " + struct.getVisibleItemsCount());
			
		this.updateTemplateTitle(item);
	}
};
Player.prototype.resetCourseFrames = function()
{
	var course_frame = this.findFrame("course_frame");
	if (course_frame && course_frame.setFrames) {
		return course_frame.setFrames();
	}
	return false;
}
Player.prototype.getVisibleItemsIndex = function()
{
	return struct.getVisibleItemsIndex(this.gix);
};
Player.prototype.getVisibleItemsCount = function()
{
	return struct.getVisibleItemsCount();
};
Player.prototype.getStartPage = function()
{
	var g = getCommandUrl('gix', player.findFirstPage());
	return g;
}
Player.prototype.findFirstPage = function(status)
{
	if (status != null && status != "undefined") {
		for (var i=0; i < struct.length(); i++) {
			var item = struct.item(i);
			var res = this.inArray(this.getItemStatus(item["gix"]), status.split(","));
			if (item["visible"] != "1") continue;
			if (item["href"] != "" && res) return item["gix"];
		}
	}
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["visible"] != "1") continue;
		if (item["href"] != "") return item["gix"];
	}
	return null;
};
Player.prototype.findParent = function(index)
{
	if (index == null || index == "undefined") index = this.gix;
	var currentItem = struct.findItem(index);
	
	for (var i=0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["href"] != "" && item["index"] == currentItem["parent"]) return item["gix"];
	}
	return null;
};
Player.prototype.restoreExitPage = function(gix)
{
	var isMixed = (struct.firstOffsetPages != 0 || struct.lastOffsetPages != 0 || struct.countShowPages != 0);	
	
	var item = null;
	if (isMixed){
		item = struct.findItem(gix);
		if (item){
			if (item.isExamPage == 1){
				this.gotoPage(struct.examParentGix);
			} else {
				this.gotoPage(gix);
			};
		} else {
			this.gotoPage(struct.examParentGix);
		};
	} else {
		this.gotoPage(gix);
	};
}
Player.prototype.gotoPage = function(g)
{
	// ograniczenie czasowe
	// trzeba gdzies wpisac w kodzie
	// np : player.expire = new Date(2005, 7, 18);
	if (typeof(this.expire) != "undefined" && typeof(this.expire.getTime) == "function") {
		var now = new Date();
		if (now.getTime() > this.expire.getTime())
		{
			this.loadContentFrameset(this.naviPathToRoot + "pages/html/expire.html");
			return;
		}
	}
	var item = struct.findItem(g);
	if (item == null) {
		item = struct.findItem(player.findFirstPage());
	}	
	if (item) {
		if (item["href"] != "") {
			if (config.usePlayerPreloader) {
				this.pgPreloaderLoad(item["gix"]);
			} else {
				this.loadContentFramesetByGix(item["gix"]);
			}
			return;
		}
	}
};
Player.prototype.gotoEncyclopedia = function(wordToSearch)
{
	if (lms.gotoEncyclopedia) {
		lms.gotoEncyclopedia(wordToSearch);
	}
	return;
};
Player.prototype.firstPage = function()
{
	this.gotoPage(0);
}
Player.prototype.lastPage = function()
{
	var p = uelo.pages[uelo.pagesCount - 1];
	this.gotoPage(p.globalIndex);
}
Player.prototype.nextPage = function(passInvisible, status) 
{
	if (passInvisible == null || passInvisible == "undefined") passInvisible = false;
	
	var i = this.gix;
	var item = null;
	
	if (status != null && status != "undefined") {
		while (item = struct.getNextItem(i)) {
			var res = this.inArray(this.getItemStatus(item["gix"]), status.split(","));
			if (item["href"] != "" && (!passInvisible && item["visible"] == "1") && res) {
				if (this.enablePagesPreloader) {
					this.pgPreloaderLoad(item["gix"]);
				} else {
					this.loadContentFramesetByGix(item["gix"]);
				}
				return;
			}
			
			i = item["gix"];
		}
	} else {
		while (item = struct.getNextItem(i)) {
			if (item["href"] != "" && (!passInvisible && item["visible"] == "1")) {
				if (this.enablePagesPreloader) {
					this.pgPreloaderLoad(item["gix"]);
				} else {
					this.loadContentFramesetByGix(item["gix"]);
				}
				return;
			}
			i = item["gix"];
		}
	}
	
	if (this.enablePagesPreloader) {
		this.pgPreloaderLoad(this.gix);
	} else {
		this.loadContentFramesetByGix(this.gix);
	}
};
Player.prototype.previousPage = function(passInvisible, status)
{
	if (passInvisible == null || passInvisible == "undefined") passInvisible = false;
	
	var i = this.gix;
	var item = null;
	
	if (status != null && status != "undefined") {
		while (item = struct.getPreviousItem(i)) {
			var res = this.inArray(this.getItemStatus(item["gix"]), status.split(","));
			if (item["href"] != "" && (!passInvisible && item["visible"] == "1") && res) {
				if (this.enablePagesPreloader) {
					this.pgPreloaderLoad(item["gix"]);
				} else {
					this.loadContentFramesetByGix(item["gix"]);
				}
				return;
			}
			i = item["gix"];
		}
	} else {
		while (item = struct.getPreviousItem(i)) {
			if (item["href"] != "" && (!passInvisible && item["visible"] == "1")) {
				if (this.enablePagesPreloader) {
					this.pgPreloaderLoad(item["gix"]);
				} else {
					this.loadContentFramesetByGix(item["gix"]);
				}
				return;
			}
			i = item["gix"];
		}
	}
	
	if (this.enablePagesPreloader) {
		this.pgPreloaderLoad(this.gix);
	} else {
		this.loadContentFramesetByGix(this.gix);
	}
};
Player.prototype.nextSCO = function()
{
	if (typeof(lms) != "undefined" && typeof(lms.nextSCO) != "undefined") lms.nextSCO();
};
Player.prototype.prevSCO = function()
{
	if (typeof(lms) != "undefined" && typeof(lms.prevSCO) != "undefined") lms.prevSCO();
};
Player.prototype.reload = function()
{
	var item = struct.findItem(this.gix);
	if (item["href"] != "") {
		if (this.enablePagesPreloader) {
			this.pgPreloaderLoad(item["gix"]);
		} else {
			this.loadContentFramesetByGix(item["gix"]);
		}
		return;
	}
};
Player.prototype.further = function(passInvisible) 
{
	var result = false;
	if (this.enablePagesPreloader) {
		var frm = player.getFrame(player.gix);
		if (frm) {
			if (frm.frame.PlayerInterface && frm.frame.PlayerInterface.connectedPage) {
				result = frm.frame.PlayerInterface.connectedPage.further();
			} else this.nextPage();
		} else this.nextPage();
	} else {
		var content_frame = this.findFrame("content");
		if (content_frame && content_frame.PlayerInterface
				&& content_frame.PlayerInterface.connectedPage) {
			result = content_frame.PlayerInterface.connectedPage.further();
		} else this.nextPage();
	}
	return result;
};
Player.prototype.backwards = function(passInvisible)
{
	this.previousPage(passInvisible);
};
Player.prototype.findFrame = function(name, frame)
{
	try { //pg2-2iframe when some online page is loaded into it and it's visible, and 'prev/nextPage' action is performed- for some time ('till unloading iframe content) "access denied" is invoked
		if (name == "content") {
			if (frames.course_frame && frames.course_frame.content) return frames.course_frame.content;
		}
		if (name == "tree") {
			if (frames.course_frame && frames.course_frame.tree) return frames.course_frame.tree;
		}
		if (name == "navigation") {
			if (frames.course_frame && frames.course_frame.navigation) return frames.course_frame.navigation;
		}
		
		if (typeof(frame) == "undefined") {
			frame = frames;
		}
		for (var i = 0; i < frame.length; i++) {
			if (frame[i].name == name) {
				return frame[i];
			} else {
				var result = this.findFrame(name, frame[i]);
				if (result) return(result);
			}
		}
	} catch(e) {
		if (typeof(log) != 'undefined') log.error("classPlayer.findFrame: " + e.description); //pg2-condition
		return null; //pg2-now in the methods which use it and exception 'access denied' will occure
	}
	return(null);
};
Player.prototype.loadContentFrameset = function(href) 
{
	if (this.enablePagesPreloader) return;
	
	var content_frame = this.findFrame("content");
	if (content_frame) { //pg2
		content_frame.location.href = href;
	}
		
	this.updateTemplateTree();
};
Player.prototype.loadContentFramesetByGix = function(gix) 
{
	if (this.enablePagesPreloader) return;
	if (uelo.getPageAccess(gix) == false) {
		alert(MESSAGE_NOT_HAVE_PERMISSION_TO_ACCESS_THIS_PAGE);
		return;
	}
	this.loadContentFrameset(this.naviPathToRoot + "navi/html/loadcontent.html?gix=" + gix);
	var p = uelo.FindPage(gix);
	if (typeof(p) != 'undefined' && p != null && typeof(p.visitedCount) != 'undefined') p.visitedCount++; //pg2-without 'if', in some cases p wasn't found and an exception was invoked
	
	this.limitQuizTimeNotifyNavigateToPage(gix); //pg2-limit timer
};
Player.prototype.checkWerePagesSolved = function(rangeBegin, rangeEnd)
{
	var complete = false;
	
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (parseInt(item['index']) < rangeBegin || parseInt(item['index']) > rangeEnd)
		{
			continue;
		}
		if (item["visible"] == "1"){
			if (item["status"] == "P" || item["status"] == "F") {
				complete = true;
				break;
			}
		}
	}
	return complete;
}

//jk  move to uelo
//Player.prototype.getScoreMaxScore = function()

Player.prototype.getScoreDataState = function()
{
	var maxScore = 0;
	var possibleScore = 0;
	var score = 0;
	var courseHasInteractions = false;
	
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["iss"] == "0") continue;		
		var pageMS = parseInt(item["ms"]);
		if (!isNaN(pageMS)) {
			if (item["visible"] == "1"){
				var p = uelo.FindPage(item["gix"]);
				if (p && p.pageType == PAGETYPE_EXERCISE && p.isAssessment) { //pg2-qr -get score only from pages in assessment
					maxScore += 100;
					if (!isNaN(p.score)) {
						score += (p.score == ""?0:parseInt(p.score));//p.score; //pg2-fixed
					}
					if (p.status != PAGESTATUS_NOT_ATTEMPTED) possibleScore += 100;
					if (p.interactions.length > 0) courseHasInteractions = true;
				}
			}
		}
	}
	this.courseHasInteractions = courseHasInteractions;
	return [score, maxScore, possibleScore];
}

Player.prototype.getTotalScore = function() //pg2-qr fixed
{
	if (this.dbgCourseScore != -1) return this.dbgCourseScore;
	
	var scoreDS = this.getScoreDataState();
	
	//pg2-qr
	var score = scoreDS[0];
	var maxScore = scoreDS[1];
	var res = Math.ceil(((100 / maxScore) * score));
	//
	if (struct.isCourseMixed){
		//pg2-qr
		var wasSolved = this.checkExamWasSolved();
		var reallyMixedAndInAssessment = uelo.wasCourseReallyMixedAndPagesInAssessment();
		
		if (!wasSolved && reallyMixedAndInAssessment[0] && reallyMixedAndInAssessment[1]) return uelo.courseOryginalScore; else //
		if (!wasSolved && !reallyMixedAndInAssessment[0] && !reallyMixedAndInAssessment[1] && !uelo.pageInAssessmentCheckAnswerInSession) return uelo.courseOryginalScore;
		return isNaN(res) ? "":res;
		//
	} else {
		/* //pg2-qr removed
		score = scoreDS[0];
		maxScore = scoreDS[1];
		var res = Math.ceil(((100 / maxScore) * score)); */
		return isNaN(res) ? "":res;
	}	
};
Player.prototype.getPossibleScore = function() //pg2-qr fixed
{
	if (this.dbgCourseScore != -1) return this.dbgCourseScore;
	
	var scoreDS = this.getScoreDataState();
	
	var maxScore = scoreDS[1];
	var possibleScore = scoreDS[2];
	var res = Math.ceil(((100 / maxScore) * possibleScore));
	
	if (struct.isCourseMixed){
		//pg2-qr
		var wasSolved = this.checkExamWasSolved();
		var reallyMixedAndInAssessment = uelo.wasCourseReallyMixedAndPagesInAssessment();
		
		if (!wasSolved && reallyMixedAndInAssessment[0] && reallyMixedAndInAssessment[1]) return uelo.courseOryginalScore; else
		if (!wasSolved && !reallyMixedAndInAssessment[0] && !reallyMixedAndInAssessment[1] && !uelo.pageInAssessmentCheckAnswerInSession) return uelo.courseOryginalScore;
		return isNaN(res) ? "":res;
		//
	} else {
		/* //pg2-qr removed
		maxScore = scoreDS[1];
		possibleScore = scoreDS[2];
		var res = Math.ceil(((100 / maxScore) * possibleScore));*/
		return isNaN(res) ? "":res;
	}	
};
Player.prototype.checkExamWasSolved = function()
{
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (item["iss"] == "0") continue;		
		var pageMS = parseInt(item["ms"]);
		if (!isNaN(pageMS)) {
			if (item["visible"] == "1"){
				if (item["isExamPage"] == "1" && item["status"] != "N") {
					return true;
				}
			}
		}
	}
	return false;
}
Player.prototype.setNaviHtml = function(obj_name, value)
{
	var navigation = this.findFrame("navigation");
	if (navigation != undefined) {
		var obj = navigation.document.getElementById(obj_name);
		if (obj != undefined) obj.innerText = value;
	}
};
Player.prototype.contentDestroy = function()
{
	if (this.enablePagesPreloader) {
		this.pgPreloaderUnloadContent();
	} else {
		var f = findFrame("content");
		if (f) {
			try { //pg2-in case of https:// and a course in new window, there could be an exception- just intercept it, do nothing
				if (f.PlayerInterface) {
					f.PlayerInterface.connectedPage.unloadContent();
				} else 
				if (f.extContent) f.unloadContent();
			} catch(e) {};
		}
	}
	this.clearActivityTimer();
	this.clearLessonTimerTimer();
};
Player.prototype.createSID = function ()
{
	var d = new Date();
	return d.getTime();
};
//jk  move to uelo
Player.prototype.resetPagesStatus = function ()
{
	for (var i = 0; i < struct.length(); i++) {
		struct.item(i)["status"] = "N";
	}
};
Player.prototype.getPagesCountInChapter = function(root) {
	var result = 0;
	for (var i = 0; i < struct.length(); i++) {
		var item = struct.item(i);
		if (parseInt(item["parent"]) == parseInt(root["index"])) result++;
	}
	return result;
};
Player.prototype.getPageNoInChapter = function(root, item) {
	var result = 0;
	for (var i = 0; i < struct.length(); i++) {
		var item_s = struct.item(i);
		if (parseInt(item_s["parent"]) == parseInt(root["index"])) {
			result++;
			if (item_s["gix"] == item["gix"]) return result;
		}
	}
	return result;
};
Player.prototype.nextPageInChapter = function(passInvisible, status)
{
	if (passInvisible == null || passInvisible == "undefined") passInvisible = false;
	var i = this.gix;
	var root = struct.findItem(this.gix);
	var item = null;
	
	if (status != null && status != "undefined") {
		if (this.hasChildren()) {
			while (item = struct.getNextItem(i)) {
				var res = this.inArray(this.getItemStatus(item["gix"]), status.split(","));
				if (item["href"] != "" 
						&& (!passInvisible && item["visible"] == "1")
						&& item["parent"] == root["index"]
						&& res) {
					if (this.enablePagesPreloader) {
						this.pgPreloaderLoad(item["gix"]);
					} else {
						this.loadContentFramesetByGix(item["gix"]);
					}
					return;
				}
				i = item["gix"];
			}
		}
	} else {
		if (this.hasChildren()) {
			while (item = struct.getNextItem(i)) {
				if (item["href"] != "" && (!passInvisible && item["visible"] == "1")
						&& item["parent"] == root["index"]) {
					if (this.enablePagesPreloader) {
						this.pgPreloaderLoad(item["gix"]);
					} else {
						this.loadContentFramesetByGix(item["gix"]);
					}
					return;
				}
				i = item["gix"];
			}
		}
	}
	
	var idx = this.findParent(this.gix);
	if (idx != null) {
		if (this.enablePagesPreloader) {
			this.pgPreloaderLoad(idx);
		} else {
			this.loadContentFramesetByGix(idx);
		}
	} else {
		idx = this.findFirstPage();
		if (idx != null) {
			if (this.enablePagesPreloader) {
				this.pgPreloaderLoad(idx);
			} else {
				this.loadContentFramesetByGix(idx);
			}
		}
	}
};
Player.prototype.previousPageInChapter = function(passInvisible, statuses)
{
	if (passInvisible == null || passInvisible == "undefined") passInvisible = false;
	var i = this.gix;
	var root = struct.findItem(this.gix);
	var item = null;
	
	if (status != null && status != "undefined") {
		if (this.hasChildren()) {
			while (item = struct.getPreviousItem(i)) {
				var res = this.inArray(this.getItemStatus(item["gix"]), status.split(","));
				if (item["href"] != "" 
						&& (!passInvisible && item["visible"] == "1")
						&& item["parent"] == root["index"]
						&& res) {
					if (this.enablePagesPreloader) {
						this.pgPreloaderLoad(item["gix"]);
					} else {
						this.loadContentFramesetByGix(item["gix"]);
					}
					return;
				}
				i = item["gix"];
			}
		}
	} else {
		if (this.hasChildren()) {
			while (item = struct.getPreviousItem(i)) {
				if (item["href"] != "" && (!passInvisible && item["visible"] == "1")
						&& item["parent"] == root["index"]) {
					if (this.enablePagesPreloader) {
						this.pgPreloaderLoad(item["gix"]);
					} else {
						this.loadContentFramesetByGix(item["gix"]);
					}
					return;
				}
				i = item["gix"];
			}
		}
	}
	
	var idx = this.findParent(this.gix);
	if (idx != null) {
		if (this.enablePagesPreloader) {
			this.pgPreloaderLoad(idx);
		} else {
			this.loadContentFramesetByGix(idx);
		}
	} else {
		idx = this.findFirstPage();
		if (idx != null) {
			if (this.enablePagesPreloader) {
				this.pgPreloaderLoad(idx);
			} else {
				this.loadContentFramesetByGix(idx);
			}
		}
	}
};
Player.prototype.setTitle = function(item, frameName, objName)
{
	if (!item) item = struct.findItem(this.gix);
	var header = this.findFrame(frameName);
	
	if (header && item) {
		var obj = header.document.getElementById(objName);
		if (obj != undefined) obj.innerText = item["title"];
	}
};
Player.prototype.setNumber = function(item, format, frameName, objName)
{
	var clear = false;
	var header = this.findFrame(frameName);
	if (!item) {
		item = struct.findItem(this.gix);
	}
	var item_parent = struct.findItemByParent(parseInt(item["parent"]));
	if (!item_parent || parseInt(item["parent"]) == 1) {
		clear = true;
		format = "";
	} else {
		var count = this.getPagesCountInChapter(item_parent);
		var page_no = this.getPageNoInChapter(item_parent, item);
		format = format.replace("%1", page_no);
		format = format.replace("%2", count - 1);
	}
	
	if (header && item) {
		var obj = header.document.getElementById(objName);
		if (obj != undefined) obj.innerText = format;
	}
};
Player.prototype.setPageHidden = function(index)
{
	if (index == null || index == "undefined") return false;
	var item = struct.findItem(index);
	if (item) item["visible"]="0";
	if (uelo){
		uPage=uelo.FindPage(index);
		if(uPage) uPage.pageType='Hidden';
	}
};
Player.prototype.setPageVisible = function(index,type)
{
	if (index == null || index == "undefined") return false;
	var item = struct.findItem(index);
	if(item) item["visible"]="1";
	if(uelo){
		uPage=uelo.FindPage(index);
		if(uPage) uPage.pageType=type;
	}
};
Player.prototype.setPagesInStruct = function(type)
{
	for (var i = 1; i < struct.length(); i++) {		
		if (type == 'hidden') this.setPageHidden(i);
		else this.setPageVisible(i,type);
	}
};
Player.prototype.getLMS = function()
{
	return lms;
};
Player.prototype.setCourseVersion = function(vindex)
{
	if (!struct.existsVersionItem(vindex)) return;
	
	this.courseVersion = vindex;
	var treeFrame = this.findFrame("tree");
	if (treeFrame) {
		treeFrame.setCourseVersion(this.courseVersion);
	}
	
	if (this.enablePagesPreloader) this.resetFrames();
	this.gotoPage(this.gix);
}
Player.prototype.getFrame = function(id, base)
{
	if (typeof(base) != "undefined") {
		for (var k in this.__frames) {
			if (this.__frames[k] && k == id) {
				return this.__frames[k];
			}
		}
	} else {
		for (var k in this.__frames) {
			if (this.__frames[k] && this.__frames[k].gix == id) {
				return this.__frames[k];
			}
		}
	}
	return null;
};
Player.prototype.getFreeFrame = function()
{
	for (var k in this.__frames) {
		if (this.__frames[k].locked == false && this.__frames[k].content == false) {
			return this.__frames[k];
		}
	}
	return null;
};
Player.prototype.getIndex = function(gix)
{
	var item = struct.findItem(gix);
	if (item) {
		return parseInt(item["index"]);
	}
	return -1;
};
Player.prototype.getGIX = function(idx)
{
	var item = struct.findItemBy(idx, "index");
	if (item) {
		return parseInt(item["gix"]);
	}
	return -1;
};
Player.prototype.getFirstVisible = function(gix, prev)
{
	if (prev) {
		var item = struct.findPrevVisibleItem(gix);
		if (item) {
			return parseInt(item["gix"]);
		}
	} else {
		var item = struct.findNextVisibleItem(gix);
		if (item) {
			return parseInt(item["gix"]);
		}
	}
	return -1;
};
Player.prototype.preloadPages = function(gix)
{
	if(config.useMicroPreloader){
		this.preloadPagesMicro(gix);
	} else {
		this.preloadPagesFull(gix);
	}
}
Player.prototype.preloadPagesFull = function(gix)
{
	this.updateTemplateTree();
	
	var prev = false;
	var next1 = false;
	var next2 = false;
	
	var idx = this.getIndex(gix);
	
	var gix_prev = this.getFirstVisible(gix, true);
	var gix_next1 = this.getFirstVisible(gix);	
	var gix_next2 = -1;
	if (gix_next1 != -1) {
		var gix_next2 = this.getFirstVisible(gix_next1);
	}
		
	var idx_prev = this.getIndex(gix_prev);
	var idx_next1 = this.getIndex(gix_next1);
	var idx_next2 = this.getIndex(gix_next2);
	
	for (var k in this.__frames) {
		if (this.__frames[k].gix == gix) {
			this.__frames[k].locked = true;
		} else 
		if (gix_prev != -1 && this.__frames[k].gix == gix_prev) {
			this.__frames[k].locked = true;
			prev = true;
		} else 
		if (gix_next1 != -1 && this.__frames[k].gix == gix_next1) {
			this.__frames[k].locked = true;
			next1 = true;
		} else 
		if (gix_next2 != -1 && this.__frames[k].gix == gix_next2) {
			this.__frames[k].locked = true;
			next2 = true;
		}
	}
	
	//z ofsetem	
	if (!prev && gix_prev != -1) {
		var frm = this.getFreeFrame();
		if (frm) {
			frm.locked = true;
			frm.gix = gix_prev;
			frm.frame.location = this.prepareFrameSrc(gix_prev);
		}
	}
	
	if (!next1 && gix_next1 != -1) {
		var frm = this.getFreeFrame();
		if (frm) {
			frm.locked = true;
			frm.gix = gix_next1;
			frm.frame.location = this.prepareFrameSrc(gix_next1);
		}
	}
	
	if (!next2 && gix_next2 != -1) {
		var frm = this.getFreeFrame();
		if (frm) {
			frm.locked = true;
			frm.gix = gix_next2;
			frm.frame.location = this.prepareFrameSrc(gix_next2);
		}
	}
	
};
Player.prototype.preloadPagesMicro = function(gix)
{
	this.updateTemplateTree();
	
	//var prev = false;
	var next1 = false;
	//var next2 = false;
	
	var idx = this.getIndex(gix);
	
	//var gix_prev = this.getFirstVisible(gix, true);
	var gix_next1 = this.getFirstVisible(gix);
	/*
	var gix_next2 = -1;
	if (gix_next1 != -1) {
		var gix_next2 = this.getFirstVisible(gix_next1);
	}
	*/
	/*var gix_prev = this.getGIX(idx - 1);
	var gix_next1 = this.getGIX(idx + 1);
	var gix_next2 = this.getGIX(idx + 2, new Array(gix_next1));*/
	
	//var idx_prev = this.getIndex(gix_prev);
	var idx_next1 = this.getIndex(gix_next1);
	//var idx_next2 = this.getIndex(gix_next2);
	
	for (var k in this.__frames) {
		if (this.__frames[k].gix == gix) {
			this.__frames[k].locked = true;
		}/* else if (gix_prev != -1 && this.__frames[k].gix == gix_prev) {
			this.__frames[k].locked = true;
			prev = true;
		} */
		else 
		if (gix_next1 != -1 && this.__frames[k].gix == gix_next1) {
			this.__frames[k].locked = true;
			next1 = true;
		} /*else if (gix_next2 != -1 && this.__frames[k].gix == gix_next2) {
			this.__frames[k].locked = true;
			next2 = true;
		}*/
	}
	
	//z ofsetem
	/*
	if (!prev && gix_prev != -1) {
		var frm = this.getFreeFrame();
		if (frm) {
			frm.locked = true;
			frm.gix = gix_prev;
			frm.frame.location = this.prepareFrameSrc(gix_prev);
		}
	}
	*/
	if (!next1 && gix_next1 != -1) {
		var frm = this.getFreeFrame();
		if (frm) {
			frm.locked = true;
			frm.gix = gix_next1;
			frm.frame.location = this.prepareFrameSrc(gix_next1);
		}
	}
	/*
	if (!next2 && gix_next2 != -1) {
		var frm = this.getFreeFrame();
		if (frm) {
			frm.locked = true;
			frm.gix = gix_next2;
			frm.frame.location = this.prepareFrameSrc(gix_next2);
		}
	}
	*/
};
Player.prototype.prepareFrameSrc = function(gix)
{
	var result = "";
	var item = struct.findItem(gix);
	if (item) {
		if (item["href"] != "") {
			if (item["type"] == "0") {
				result = this.naviPathToRoot + item["href"] + "_page." + this.courseVersion + ".html";
			} else {
				result = this.naviPathToRoot + item["href"];
			}
		}
	}
	if (result == "") {
		result = this.naviPathToRoot + "pages/html/blank.html";
	}
	return result;
};
Player.prototype.prepareFrame = function(gix, name)
{
	var frm = null;
	if (typeof(name) != "undefined") {
		frm = this.getFrame(name, true);
		if (frm) {
			frm.gix = gix;
			frm.frame.location = this.prepareFrameSrc(gix);
		}
	} else {
		frm = this.getFrame(gix);
		if (!frm) {
			frm = this.getFreeFrame(gix);
			if (frm) {
				frm.gix = gix;
				frm.frame.location = this.prepareFrameSrc(gix);
			}
		}
	}
	return frm;
};
Player.prototype.pgPreloaderUnloadContent = function()
{
	var frm = this.getFrame(this.gix);
	if (frm) {
		try {
			if (frm.frame.PlayerInterface && frm.frame.PlayerInterface.connectedPage) {
				frm.frame.PlayerInterface.connectedPage.unloadContent();
			} else
			if (frm.frame.extContent) {
				frm.frame.unloadContent();
			}
		} catch(e) {};
	}
};
Player.prototype.pgPreloaderLoad = function(gix)
{
	if (uelo.getPageAccess(gix) == false) {
		alert(MESSAGE_NOT_HAVE_PERMISSION_TO_ACCESS_THIS_PAGE);
		return
	}
	
	__timer.stop();
	
	var item = struct.findItem(gix);
	if (item) {
		var frm = this.getFrame(this.gix);
		if (frm) {
			try {
				if (frm.frame.PlayerInterface && frm.frame.PlayerInterface.connectedPage) {
					frm.frame.PlayerInterface.connectedPage.unloadContent();
				} else
				if (frm.frame.extContent) {
					frm.frame.unloadContent();
				}
			} catch(e) {};
		}
		
		this.setSessionTime();
		this.gix = gix;
		
		for (var k in this.__frames) {
			this.__frames[k].locked = false;
			this.__frames[k].content = false;
		}
		
		var frm = this.getFrame(this.gix);
		if (!frm) {
			frm = this.prepareFrame(this.gix, "p1000");
		}
		
		frm.content = true;
		var cols = "";
		
		for (var k in this.__frames) {
			if (this.__frames[k].content) {
				cols += "*%,"
			} else {
				cols += "0%,"
			}
		}
		
		cols = cols.substr(0, cols.length - 1);
		this.pagesPreloaderFrame.cols = cols;
		
		this.updateTemplateTree();
		this.updateTemplateExpand(item);
		this.updateTemplateProgress(item);
		this.updateTemplateTitle(item);
		
		__timer.run();
		
		var p = uelo.FindPage(gix);
		if (typeof(p) != 'undefined' && p != null && typeof(p.visitedCount) != 'undefined') p.visitedCount++; //pg2-without 'if', in some cases p wasn't found and an exception was invoked
		
		this.limitQuizTimeNotifyNavigateToPage(gix); //pg2-limit timer
	}
};
Player.prototype.resetFrames = function()
{
	for (var k in this.__frames) {
		this.__frames[k].locked = false;
		this.__frames[k].content = false;
		this.__frames[k].gix = -1;
	}
};
Player.prototype.initFrames = function()
{
	if (!this.pagesPreloaderFrame) {
		alert("Pages preloader error.\nPlease contact your course developer.");
		return;
	}
	
	this.pagesPreloaderFrame.cols = "0%,*%,0%,0%";
	
	var content_frame = this.findFrame("content");
	
	if (content_frame) { //pg2
		for (var i=0; i<content_frame.frames.length; i++) {
			var frm = content_frame.frames[i];
			this.__frames[frm.name] = new __Frame();
			this.__frames[frm.name].frame = frm;
		}
	} else {
		
	}
	this.pgPreloaderLoad(this.getGIX(2));
};
Player.prototype._doLoad = function()
{
	this.doLoad(this.pagesPreloaderFrame);
	// debugger
	if (is.moz) {
		___cool_timer_stop();
		if (___cool_timer_enabled) {
			___cool_timer_start();
		}
	}
	// debugger end
};
Player.prototype.doLoad = function(obj)
{
	this.enablePagesPreloader = config.usePlayerPreloader;
	this.pg_max = struct.length();
	this.pagesPreloaderFrame = obj;
	if (!this.pagesPreloaderFrame) this.enablePagesPreloader = false;
	if (this.enablePagesPreloader) {
		if (is.opera) {
			this.initFrames();
		} else
		if ((is.moz) && !this.wasLoaded) {
			
		} else {
			this.initFrames();
		}
	}
	this.resetCourseFrames();		
	// debugger
	if (is.ie) {
		___cool_timer_stop();
		if (___cool_timer_enabled) {
			___cool_timer_start();
		}
	}
	// debugger end
	this.runStudentActivityTimer();		
	this.isLoaded = true;
	return false;
};
Player.prototype.runStudentActivityTimer = function(item)
{
	this.runStudentActiveTimer();
	
	if (top && typeof(top.dailySessionUpdateTimeInterval ) != 'undefined'){
			this.updateLMSTimeInterval = top.dailySessionUpdateTimeInterval ;
			this.lmsTimer = setTimeout("player.updateAvtivityToLMS();", this.updateLMSTimeInterval*1000);
	};	
	
	if (config.lessonTimeEnabled && this.lessonTimer == null)
	{
		var timeFromLastBreak  = 0;
		if (top && typeof(top.timeFromLastBreak  ) != 'undefined'){
			timeFromLastBreak  = top.timeFromLastBreak;
		};
		if (config.lessonTime < timeFromLastBreak) timeFromLastBreak = 0;
		this.lessonTimer = setTimeout("player.showEndLessonPopup();", config.lessonTime*60*1000-timeFromLastBreak*60*1000);
	};
}
Player.prototype.updateTemplateExpand = function(item)
{
	var tree_frame = null;
	try {
		tree_frame = this.findFrame("tree");
	} catch(e) {
		tree_frame = null;
		if (typeof(log) != 'undefined') log.error("classPlayer.updateTemplateExpand#1: " + e.description);
	}
	try {
		if (item && item["visible"] == "1" && tree_frame && tree_frame.expandMyParents) {
			tree_frame.expandMyParents(this.gix);
		};
	} catch(e) {
		if (typeof(log) != 'undefined') log.error("classPlayer.updateTemplateExpand#2: " + e.description);
	}
};
Player.prototype.updateTemplateTree = function()
{
	var tree_frame = null;
	try {
		tree_frame = this.findFrame("tree");
	} catch(e) {
		tree_frame = null;
		if (typeof(log) != 'undefined') log.error("classPlayer.updateTemplateTree#1: " + e.description);
	}
	
	try {
		var item = struct.findItem(this.gix);
		
		if (item && item["visible"] == "1" && tree_frame && tree_frame.selectedNode) {
			tree_frame.selectedNode(this.gix);
		}
	} catch(e) {
		if (typeof(log) != 'undefined') log.error("classPlayer.updateTemplateExpand#2: " + e.description);
		alert(e.message);
	}
}
Player.prototype.updateTemplateTitle = function(item)
{
	var tF = null;
	try {
		tF = this.findFrame("title");
	} catch(e) {
		tF = null;
		if (typeof(log) != 'undefined') log.error("classPlayer.updateTemplateTitle#1: " + e.description);
	}
	try {
		if (tF && tF.update) {
			tF.update(item);
		}
	} catch(e) {
		if (typeof(log) != 'undefined') log.error("classPlayer.updateTemplateTitle#2: " + e.description);
	}
}
Player.prototype.updateTemplateProgress = function(item)
{
	var navigation_frame = null;
	try {
		navigation_frame = this.findFrame("navigation");
	} catch(e) {
		navigation_frame = null;
		if (typeof(log) != 'undefined') log.error("classPlayer.updateTemplateProgress#1: finding navigation_frame " + e.description);
	}
	
	var content_frame = null;
	try {
		content_frame = this.findFrame("content");
	} catch(e) {
		content_frame = null;
		if (typeof(log) != 'undefined') log.error("classPlayer.updateTemplateProgress#2: finding content_frame " + e.description);
	}
	
	if (navigation_frame != null && content_frame != null){
		if (navigation_frame.templateProgress){
			//var content_frame = this.findFrame("content");
			navigation_frame.updateProgress(content_frame, item['index']);
		}
		if (navigation_frame.hideShowPrevNextButton){
			//var content_frame = this.findFrame("content");
			navigation_frame.showHideButtons(content_frame, this.gix);
		}
	}
}
Player.prototype.pageLoaded = function(gix)
{
};
Player.prototype.contentLoaded = function()
{
};
Player.prototype.isActiveContent = function(srch)
{
	var result = false;
	var item = struct.findItem(this.gix);
	if (item) {
		var i_srch = item["href"];
		if (i_srch != "") {
			i_srch = i_srch.split("?")[1];
			i_srch = "?" + i_srch.replace(new RegExp('&amp;', "g"), '&');
			srch = srch.replace(new RegExp('&amp;', "g"), '&');
			if (i_srch == srch) {
				result = true;
			}
		}
	}
	return result;
};
Player.prototype.clearAllData = function()
{
	if (uelo && struct) {//pg2-invoked in page preview in wbte
		uelo.clearInteractions();
		struct.setNewStatus("N");
	}
};
Player.prototype.setSessionTime = function()
{
	var item = struct.findItem(this.gix);
	if (item) {
		var t = stampInSec(this.startTime, new Date());
		item["sessionTime"] += t;
	}
	this.startTime = new Date();
}
Player.prototype.getDebugMode = function()
{
	if (this.debugMode) {
		return true;
	} else {
		var debugF = this.findFrame("debug", top);
		if (debugF)
		{
			this.debugMode = true;
			return true;
		};
	};
	return false;	
}
Player.prototype.debugCourse = function()
{
	var debugF = this.findFrame("debug", top);
	if (debugF && debugF.updateDebugInformations) {
		debugF.updateDebugInformations();
	}
}
Player.prototype.calculateTimeIntToString = function(timeInt)
{
	//tools.js
	return calculateTimeIntToString(timeInt);
}
Player.prototype.updateAvtivityToLMS = function()
{
	var updateEnabled = false;
	if (top && typeof(top.sendLearnTime ) != 'undefined'){
		top.sendLearnTime(player.activityTime);
		updateEnabled = true;
	}
	if (top && typeof(top.sendLearnTime ) != 'undefined'){
		var pageName = "";
		var pageGix = "";
		var frm = this.getFrame(this.gix);
		if (frm) {
			if (frm.frame.PlayerInterface && frm.frame.PlayerInterface.connectedPage) 
			{
				pageName = frm.frame.PlayerInterface.connectedPage.p_pageName;
				pageGix = frm.frame.PlayerInterface.connectedPage.p_globalIndex;
			};
		};		
		top.setCurrentLearnPage(pageName, pageGix);
		updateEnabled = true;
	};
	if (updateEnabled) this.lmsTimer = setTimeout("player.updateAvtivityToLMS();", this.updateLMSTimeInterval);
}
Player.prototype.runStudentActiveTimer = function()
{
	if (!config.lessonTimeEnabled || this.lessonBreak) return; 
	
	window.clearTimeout(this.activTimer);	
	this.activTimer = null;
	this.activTimer = setTimeout("player.studentIsInactive(new Date());", config.inactivityTime*60*1000);
}
Player.prototype.studentExitSCO = function()
{	
	var curentDate = new Date
	var inactivTime = curentDate.getMilisecondsBetweenDates(this.lastActiveStudentTime, curentDate);
	var activeTimeInt = (inactivTime/1000);
	
	this.activityTime += activeTimeInt;
	return this.activityTime;
}
Player.prototype.studentIsActive = function(curentDate)
{
	this.lastActiveStudentTime = curentDate;
	this.runStudentActiveTimer();
}
Player.prototype.studentIsInactive = function(curentDate)
{
	var inactivTime = curentDate.getMilisecondsBetweenDates(this.lastActiveStudentTime, curentDate);
	var activeTimeInt = (inactivTime/1000);
	
	this.activityTime += activeTimeInt;
	
	var frm = this.getFrame(this.gix);
	if (frm) {
		if (frm.frame.PlayerInterface && frm.frame.PlayerInterface.connectedPage) {
			frm.frame.PlayerInterface.connectedPage.showWarningPopup();
		};
	};
}
Player.prototype.studentActive = function()
{	
	if (!config.inactivityEnabled) return;
	this.runStudentActiveTimer();
}
Player.prototype.clearActivityTimer = function()
{
	window.clearTimeout(this.activTimer);	
	this.activTimer = null;
}
Player.prototype.clearLessonTimerTimer = function()
{
	window.clearTimeout(this.lessonTimer);	
	this.lessonTimer = null; delete this.lessonTimer;
}
Player.prototype.setLessonBreak = function(lessonBreak)
{
	this.lessonBreak = lessonBreak;
}
Player.prototype.setStudentLessonBreak = function()
{
	this.clearActivityTimer();
	this.setLessonBreak(true);
	this.activTimer = setTimeout("player.setLessonBreak(false);player.runStudentActiveTimer();", 15*60*1000);
	this.lessonTimer = setTimeout("player.showEndLessonPopup();", 15*60*1000 + config.lessonTime*60*1000);
}
Player.prototype.showEndLessonPopup = function()
{
	this.clearActivityTimer();
	this.clearLessonTimerTimer();
	
	var frm = this.getFrame(this.gix);
	if (frm) {
		if (frm.frame.PlayerInterface && frm.frame.PlayerInterface.connectedPage) 
		{
			frm.frame.PlayerInterface.connectedPage.showEndLessonPopup();
		};
	};		
}
Player.prototype.eventPageFirstStep = function() 
{
	for (var i in this.pageFirstStepListeners) {
		try {
			this.pageFirstStepListeners[i]();
		} catch(e) {}
	}
}
Player.prototype.eventPageLastStep = function() 
{
	for (var i in this.pageLastStepListeners) {
		try {
			this.pageLastStepListeners[i]();
		} catch(e) {}
	}
}
function stampInSec(dateStart, dateEnd)
{
	if (typeof(dateEnd) == "undefined") dateEnd = new Date();
	var d = Math.abs(dateEnd.getTime() - dateStart.getTime());
	return d;
};
player = new Player();
