// JavaScript Document
/* <![CDATA[ */
var myBook;

function flipBook(startPage){
	// Use a variable to reference the embedded SWF file.
	this.isIE = navigator.appName.indexOf("Microsoft") != -1;
	this.flashVideoPlayer = (this.isIE) ? window['videoPlayer'] : document['videoPlayer'];
	
	this.correctPage = false;
	this.leftPage = '';
	this.rightPage = '';
	this.leftPageName = '';
	this.rightPageName = '';
	this.totalPages = '';
	this.guideNum = '';
	
	this.leftNavItem = null;
	this.navPageSelected = null;
	
	this.statusLocation = null;
	this.leftPageNameLocation = null;
	this.rightPageNameLocation = null;
			
	this.setInitPage = function (startPage){		
		if(this.correctPage == true) this.gotoPage(startPage);
		else var t = setTimeout("myBook.setInitPage(" + startPage + ")", 300);
	}
			
	this.nextPage = function () {
		this.flashVideoPlayer.nextPage();		
	}
	
	this.prevPage = function () {
		this.flashVideoPlayer.prevPage();		
	}
	
	this.gotoPageForm = function (destPage) {		
		destPage++;
		this.gotoPage(destPage);
	} 
	
	this.gotoPage = function (destPage) {		
		this.flashVideoPlayer.gotoPage(destPage);			
	}
	
	this.gotoFirstPage = function () {
		this.flashVideoPlayer.gotoFront();		
	}
	
	this.gotoLastPage = function () {
		this.flashVideoPlayer.gotoBack();			
	}
	
	  // Call the pauseResume() function within the SWF file.
	this.setPage = function (destPage) {
		this.flashVideoPlayer.setPage(destPage);		
	}
	
	this.pageLoaded = function (pageNum){
		if( typeof(this.flashVideoPlayer.pageLoaded) == 'function')
			this.flashVideoPlayer.pageLoaded(pageNum);			
		return this.correctPage;
		
	}

	this.pageInfo = function (){
		this.flashVideoPlayer.pageInfo();
	}
	
	this.zoomPage = function (pageDirection){	
		if(pageDirection == 'left' && this.leftPageName !== '')
			this.openZoomPage(this.leftPageName);
		else if(pageDirection == 'right' && this.rightPageName !== '')
			this.openZoomPage(this.rightPageName);
	}
	
	this.printPage = function (pageDirection){	
		if(pageDirection == 'left' && this.leftPageName !== '')
			this.openPrintPage(this.leftPageName);
		else if(pageDirection == 'right' && this.rightPageName !== '')
			this.openPrintPage(this.rightPageName);
	}
	
	this.openZoomPage = function(pageNumber){	
		var guide = parseInt(this.guideNum);
		calWindow = window.open("zoom.php?ID=" + pageNumber + "&guide=" + guide, "calWin", "width=800, height=1048, toolbar=0, location=0, status=0, directories=0, scrollbars=1, menubar=1, resizable=1, fullscreen=0");
	}
	
	this.openPrintPage = function(pageNumber){	
		var guide = parseInt(this.guideNum);
		calWindow = window.open("print_tmp.php?ID=" + pageNumber + "&guide=" + guide, "calWin", "width=800, height=1048, toolbar=0, location=0, status=0, directories=0, scrollbars=1, menubar=1, resizable=1, fullscreen=0");
	}
	
	this.buildPageNav = function(){		
		var navSection = '';
		var totalNavUnits = 12;
		var totalNavPages = totalNavUnits * 2;
		
		var startPage = this.leftPageName - (totalNavPages / 2);
		if(startPage < 0) startPage = 0;
		
		var endPage = startPage + (totalNavPages);			
		if(((parseInt(this.leftNavItem) !== parseInt(startPage)) || (this.leftNavItem==null) || (this.navPageSelected!==this.rightPage)) && parseInt(this.totalPages) > 0) {
			this.leftNavItem = startPage;		
			for(var i=startPage; i < endPage; i+=2){				
				var gotoPage = null;
				var displayPage = null
				var leftNumber = (i-1);			
				if(leftNumber < 0) leftNumber = '';					
				
				navSection += "<a href=\"\" class=\"";			
				if( (leftNumber == this.leftPage) || (i == this.rightPage)){
					navSection += "pages_nav_selected";
					this.navPageSelected = i;
				}
				else navSection += "pages_nav";
				
				if( leftNumber < this.totalPages ) {
					gotoPage = leftNumber;					
					if(leftNumber !== ''){
						if((leftNumber === 0 || leftNumber === (this.totalPages - 1))){							
							leftNumber = 'Cover';
						}
						else leftNumber -= 1;
					}					
					displayPage = (leftNumber);
				} 
				if( i < this.totalPages ){
					gotoPage = i;
					var rightCover = i
					if(displayPage !== '')
						displayPage += "-";
					if(rightCover !== ''){						
						if((rightCover === 0 || rightCover === (this.totalPages - 1))){							
							rightCover = 'Cover';
						}
						else rightCover -= 1;
					}					
					displayPage += rightCover;
				}
				if(gotoPage != null)
					navSection += "\" onclick=\"myBook.gotoPage(" + gotoPage + "); return false;\">" + displayPage +"</a>";
				else
					navSection += "\" onclick=\"return false;\"></a>";
			}				
			document.getElementById('page_nav_holder').innerHTML = navSection;				
		}		
		
	}
	
	this.updatePageInfo = function (message){		
		var response = eval('(' + message + ')');
		this.correctPage = response.correctPage;
		this.leftPage = response.leftPageNumber;
		this.rightPage = response.rightPageNumber;
		this.leftPageName = response.leftPageName;
		this.rightPageName = response.rightPageName;		
		if(isNaN(this.rightPage)){ this.rightPage=''; this.rightPageName = ''; }
		if(isNaN(this.leftPage)){ this.leftPage=''; this.leftPageName = ''; }
		this.buildPageNav();
		if( this.statusLocation != null ){
			this.statusLocation.innerHTML = this.rightPage + " of " + this.totalPages + " pages";			
		}
		if( this.leftPageName != null ){
			this.leftPageNameLocation.innerHTML = this.leftPageName;
		}
		if( this.rightPageName != null ){
			this.rightPageNameLocation.innerHTML =  this.rightPageName;
		}
		
	}
	
	this.updateStatus = function (message) {
		var response = eval('(' + message + ')');		
		this.correctPage = response.correctPage;
		this.totalPages = response.totalPages;
	}
	
	this.showMessage = function (message) {
		//document.forms['videoForm'].videoStatus.value += message + "\n";	
		alert(message);
	}
	
	if(startPage > 0) this.setInitPage(startPage);
	
}

function flagPages(){
	var cookieName = 'flaggedPages';
	var cookieArray = init_array();
	get_array(cookieName, cookieArray);	
	var arrayLength = cookieArray.length;
	document.getElementById('flagged_page_holder').style.display = 'block';
	
	var storedPage = parseInt(myBook.rightPage);
	if((myBook.leftPage + 1) === myBook.totalPages)
		storedPage = myBook.totalPages;
	
	for(i=1; i<=arrayLength; i++){
		if(cookieArray[i] == storedPage) return true;
	}	
	
	var expiresFrom = (1000 * 60 * 60 * 24 * 7);
	var expires = new Date();
	expires.setTime(expires.getTime() + expiresFrom);
	
	var storedPage = parseInt(myBook.rightPage);
	if((myBook.leftPage + 1) === myBook.totalPages)
		storedPage = myBook.totalPages;
	
	cookieArray[arrayLength] = storedPage;
	cookieArray.sort(sortNumber);
	set_array(cookieName, cookieArray, expires);
	
	var arrayLength = cookieArray.length;
	document.getElementById('flagged_page_holder').innerHTML = '';
	for(i=1; i<arrayLength; i++){		
		var pageDesc = ''
		var rightPageNum = cookieArray[i];
		if((parseInt(rightPageNum) === 0) || (rightPageNum == myBook.totalPages)) pageDesc = 'Cover';
		else {
			rightPageNum -= 1;
			pageDesc = (rightPageNum - 1) + "-" + rightPageNum;
		}
		
		document.getElementById('flagged_page_holder').innerHTML += "<a href=\"\" onclick=\"myBook.gotoPage(" + cookieArray[i] + "); return false;\">[ " + pageDesc + "]</a>";
	}	
}


function removeFlagPage(){
	var cookieName = 'flaggedPages';
	var cookieArray = init_array();
	get_array(cookieName, cookieArray);
	var pagePos = '';
	var storedPage = parseInt(myBook.rightPage);
	var arrayLength = cookieArray.length;
	if((myBook.leftPage + 1) === myBook.totalPages)
		storedPage = myBook.totalPages;
		
	for(i=1; i<=arrayLength; i++){
		if(cookieArray[i] == storedPage){
			pagePos = i;
			break;
		}
	}	

	var expiresFrom = (1000 * 60 * 60 * 24 * 7);
	var expires = new Date();
	expires.setTime(expires.getTime() + expiresFrom);
	del_entry(cookieName, cookieArray, pagePos, expires);
	fillFlags();
}

function fillFlags(){
	document.getElementById('flagged_page_holder').innerHTML = '';
	var cookieName = 'flaggedPages';
	var cookieArray = init_array();
	get_array(cookieName, cookieArray);	
	var arrayLength = cookieArray.length;
	
	if(arrayLength == 1){
		document.getElementById('flagged_page_holder').style.display = 'none';
	} else {
		document.getElementById('flagged_page_holder').style.display = 'block';
	}
	
	for(i=1; i<arrayLength; i++){		
		var pageDesc = ''
		var rightPageNum = cookieArray[i];
		if((parseInt(rightPageNum) === 0) || (rightPageNum == myBook.totalPages)) pageDesc = 'Cover';
		else {
			rightPageNum -= 1;
			pageDesc = (rightPageNum - 1) + "-" + rightPageNum;
		}
		
		document.getElementById('flagged_page_holder').innerHTML += "<a href=\"\" onclick=\"myBook.gotoPage(" + cookieArray[i] + "); return false;\">[ " + pageDesc + "]</a>";
	}	
}

function sortNumber(a, b){
	return a - b;
}

function addEvent(obj,eventType,functionReference){
	if(obj.addEventListener){
		obj.addEventListener(eventType,functionReference,true);
	} else if(obj.attachEvent){
		obj.attachEvent('on'+eventType,functionReference);
	} 
}
function removeEvent(obj,eventType,functionReference){
	if(obj.removeEventListener){
		obj.removeEventListener(eventType,functionReference,true);
	} else if(obj.detachEvent){
		obj.detachEvent('on'+eventType,functionReference);
	}
}

/* ]]> */// JavaScript Document