//****************************************************************
//****************************************************************
// Copyright 2007, Vertex Software
//****************************************************************
//****************************************************************


//****************************************************************
//****************************************************************
// Viewer
// Functions as interface between HTML and flash
//****************************************************************
//****************************************************************
function Viewer( ) {
	this.goToPage = goToPage;
	this.vocabLnk = vocabLnk;
	this.viewVocabularyActivity = viewVocabularyActivity;
	this.printExtra = printExtra;
	this.viewActivity = viewActivity;

	//-----------------------------------------------------------
	// GetShell
	//-----------------------------------------------------------
	function GetShell( ) {
		return document.getElementById("shell");
		}


	//****************************************************************
	// viewActivity
	//****************************************************************
	function viewActivity( url ) {
		try {
			var activityType = url.match( /\/([^_\/]+)_g[0-9]/g ) ? RegExp.$1 : "";
			var features = "width=250px,height=225px";
			switch (activityType) {		
				case "vocab":
					//Vocabulary             700X600 - allow resizing (scrolling)
					features = "width=700,height=600,scrollbars=1";
					break;
				case "ai":
					//Author Illustrator   700X600
					features = "width=700,height=600";
					break;
				case "fs":
					//Focus Skills            Gr1-2 waiting on vendor  Gr3-4 waiting on vendor - allow resizing (scrolling)
					features = "width=700,height=600,scrollbars=1,resizable=1";
					break;
				case "ps":
					//	Phonic Skills           waiting on vendor - allow resizing (scrolling)
					features = "width=700,height=600,scrollbars=1,resizable=1";
					break;
				case "rw":
					//Reading Writing      720X600 - allow resizing (scrolling)
					features = "width=700,height=600,scrollbars=1,resizable=1";
					break;
				}
			var newWindow = window.open(url,'Activity',features);
			newWindow.focus();
			}
		catch (error) {
			alert( "viewActivity: " + error.description );
			}
		}
	


	//****************************************************************
	// printExtra
	//****************************************************************
	function printExtra(file) {
		try {
			//GetShell().HandleSetTitle( "Need Spec for action: printExtra" );
			var browserName=navigator.appName; 
			if (browserName=="Netscape") {
				var url = "../../assets/go/" + file + ".pdf";
				}
				else {
					var url = "assets/go/" + file + ".pdf";
				} 
				var newWindow = window.open(url,"Print");
				//newWindow.focus();
			}
		catch (error) {
			alert( "printExtra: " + error.description );
			}
		}
	

	//****************************************************************
	// viewVocabularyActivity
	//****************************************************************
	function viewVocabularyActivity( ) {
		try {
			GetShell().HandleVocabularyActivityLink();
			}
		catch (error) {
			alert( "viewVocabularyActivity: " + error.description );
			}
		}
	

	//****************************************************************
	// goToPage
	//****************************************************************
	function goToPage( pageNumber ) {
		try {
			GetShell().HandleGoToPage( pageNumber );
			}
		catch (error) {
			alert( "goToPage: " + error.description  );
			}
		}


	//****************************************************************
	// vocabLnk
	// Function changes based on grade and volume
	//****************************************************************
	function vocabLnk( word ) {
		try {
			var grade = GetShell().GetGrade();
			var volume = GetShell().GetVolume();
			// Treat Grade 2 Volume 1 like Grade 1
			if (grade == 1 || (grade == 2 && volume == 1)) { 
				GetShell().HandlePlayAudioAsset( "vocab/" + word.replace( /[^a-z0-9]/i, "") );
				}
			else {
				//var url = "../../assets/vocab/vocab_pop.html?vocab=" + word + "&grade=" + grade;
			var browserName=navigator.appName; 
			if (browserName=="Netscape") {
				var url = "../../assets/vocab/vocab_pop.html?vocab=" + word + "&grade=" + grade;
				}
				else {
					var url = "assets/vocab/vocab_pop.html?vocab=" + word + "&grade=" + grade;
				} 
				var features = "scrollbars=no,menubar=no,toolbar=no,status=no,width=250px,height=225px,resizable=no";
				var newWindow = window.open(url,'Vocabulary',features);
				newWindow.focus();
				}
			}
		catch (error) {
			alert( "vocabLnk: " + [word,error.description] );
			}
		}


	}



API = new Viewer();

