// Inventing v.1 media popups

/* The following functions are for launching the various types of resources from the resource listings. 
   or from the annotation/feature listing. (The features will need to be made to handle these.)
   Tyler DeWall, 7-15-02
*/

var myWindow; 
var filename;  
var fileTitle;

function loadDocument(titleRef, fileNameRef){
	// This function loads a text-only document(html)
	// titleRef is the text of the link clicked on, for use in title tag of popup
	// fileNameRef is the filename of the document to load
	
	myWindow = window.open(fileNameRef, 'openwin','width=640,height=480,scrollbars=yes');
        myWindow.focus;
}

function loadImage(titleRef, fileNameRef){
	//This function displays an image
	// titleRef is the text of the link clicked on, for use in title tag of popup
	// fileNameRef is the filename of the image to load

	var title;	
	title = unescape(titleRef);
	filename = fileNameRef.substr(14, (fileNameRef.length - 14));
	//change size from width=590,height=440 TD-8-15-02
        myWindow = window.open('../../v1/imageloader.html','','width=740,height=540');
}

function loadMap(titleRef, fileNameRef){
	// This function displays a map
	// titleRef is the text of the link clicked on, for use in title tag of popup
	// Note that maps can be static (.jpg) or animated(.swf)
	// fileNameRef is the filename of the map to load


        var title;
	myRegEx = new RegExp("\w*\.jpg$") 
	title = unescape(titleRef);
	filename = fileNameRef.substr(14, (fileNameRef.length - 14));

	if(myRegEx.test(fileNameRef)) {
		//change size from width=590,height=440 TD-8-15-02
	        myWindow = window.open('../../v1/imageloader.html','','width=740,height=540');
	}
	else {	
		myWindow = window.open('','','toolbar=no,width=580,height=680');
		myWindow.document.writeln('<html><head><title>');
		myWindow.document.write(title);
		myWindow.document.write('</title></head><body>');
		myWindow.document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="560" height="660">');
		myWindow.document.write('<param name=movie value=');
		myWindow.document.write(fileNameRef);
		myWindow.document.write('>');
		myWindow.document.write('<param name=quality value=high>');
		myWindow.document.write('<embed src=');
		myWindow.document.write(fileNameRef);
		myWindow.document.write(' quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="560" height="660">');
		myWindow.document.write('</embed></object>');
		myWindow.document.write('</body></html>');
		myWindow.document.close();
	       	myWindow.focus;
	}
}

function loadAudio (titleRef, fileNameRef, narrationFileRef){
	// This function plays an audio resource
	// titleRef is the title of the audio file, it'll be displayed if no narration
	// fileNameRef is the file to be played
	// narrationFileRef is the text of the audio, display it if available.

        var title;
	fileTitle = titleRef;
	title = unescape(titleRef);
	filename = fileNameRef.substr(14, (fileNameRef.length - 14));

  	if(narrationFileRef != "") {
            textWindow = window.open(narrationFileRef, 'openwin','width=640,height=480,scrollbars=yes');
  	}

        myWindow = window.open('../../v1/audioPlayer.html','','width=140,height=15');
        myWindow.focus;
}

function loadVideo (titleRef, fileNameRef){
	// This function displays a video resource
	// titleRef is the text of the link clicked on, for use in title tag of popup
	// fileNameRef is the filename of the video to load

        var title;
	fileTitle = titleRef;
	title = unescape(titleRef);
	filename = fileNameRef.substr(14, (fileNameRef.length - 14));
        myWindow = window.open('../../v1/vidPlayer.html','','width=250,height=210');
	myWindow.focus;
}

// Popup Windows

var newwindow;

function imap(url)
{
	newwindow=window.open(url,'name','height=421,width=761,resizable=1');
	if (window.focus) {newwindow.focus()}
}

var newwindow;

function imap2(url)
{
	newwindow=window.open('../imaps/'+url,'imap','height=421,width=761,resizable=1');
	if (window.focus) {newwindow.focus()}
}
function mapSheet(url)
{
	newwindow=window.open('../imaps/'+url,'mapSheet','height=446,width=761,resizable=1,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

var newwindow;

function quiz(url)
{
	newwindow=window.open(url,'quiz','height=375,width=550,resizable=1,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

var newwindow;

function ebook(url)
{
	newwindow=window.open(url,'ebook','height=550,width=740,resizable=1');
	if (window.focus) {newwindow.focus()}
}

var newwindow;

function video(url)
{
	newwindow=window.open(url,'video','height=600,width=600,resizable=1,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

var newwindow;

function chrono(url)
{
	newwindow=window.open(url,'chrono','height=600,width=800,resizable=1,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

var newwindow;

function worksheet(url)
{
	newwindow=window.open(url,'worksheet','height=420,width=480,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

// resize popup image window

function PopupPic(sPicURL) { 
	window.open("../multimedia/images/popup.htm?"+sPicURL, "", "scrollbars=1,resizable=1,HEIGHT=200,WIDTH=500");
}

// Bookmark a page

function addToFavorites()
 {
  if (window.external)
  {
   window.external.AddFavorite(urlAddress,pageName)
  }
  else
  { 
   alert("Sorry! Your browser doesn't support this function.");
  }
 }

      function customImageLinks() {
              if (!document.getElementsByTagName) return;
              var anchors = document.getElementsByTagName('a');
              for (var i=0; i<anchors .length; i++) {
                   anchor = anchors[i];
                      var images = anchor.getElementsByTagName('img');
                      if (images[0] != null) {
                              anchor.className = "image";
                      }
              }
      }
       
      if (window.addEventListener)
              window.addEventListener("load", customImageLinks, false)
      else if (window.attachEvent)
              window.attachEvent("onload", customImageLinks)
      else if (document.getElementById)
              window.onload=customImageLinks
 
 // Email a friend
 
function e_friend()
{
var e_add= prompt('Enter your friend\'s email address:',' ');
var subj= prompt('Enter the subject of your message:',' ');
if ((subj==" ") || (subj==null))
 subj="W. W. Norton and Company: Give Me Liberty, 2 ed. Website Referral";
u = window.location;
window.location="mailto:"+e_add+"?subject="+subj+"&body=Check out this W. W. Norton and Company: Give Me Liberty, 2 ed. Website Page: "+u;
}

// other right hand menu links

function goPodcast()
{
	document.location = "../../content/index/podcast.htm";
}

function goChPod(myChap)
{
	document.location = "../../contents/ch" + myChap + "/podcast.asp";
}
function goStudy(myChap)
{
	document.location = "../../contents/ch" + myChap + "/studyplan.asp";
}
function goOutline(myChap)
{
	document.location = "../../contents/ch" + myChap + "/outline.asp";
}
function goProgress(myChap)
{
	document.location = "../../contents/ch" + myChap + "/progress.asp";
}
function goeBook(myChap)
{
	document.location = "../../contents/ch" + myChap + "/ebook.asp";
}
function ebookSecure(theLink){
	ebook('http://www.wwnorton.com/college/history/foner2v1_ebook/welcome.asp?'+theLink);
}
function ebookDemo(theLink){
	ebook('http://www.wwnorton.com/college/history/foner2_ebook_demo/v1/welcome.asp?'+theLink);
}
function ebookSecureV2(theLink){
	ebook('http://www.wwnorton.com/college/history/foner2v2_ebook/welcome.asp?'+theLink);
}
function ebookDemoV2(theLink){
	ebook('http://www.wwnorton.com/college/history/foner2_ebook_demo/v2/welcome.asp?'+theLink);
}
function goFlashcards(myChap)
{
	document.location = "../../contents/ch" + myChap + "/flashcards.asp";
}
function goSources(myChap)
{
	document.location = "../../contents/ch" + myChap + "/sources.asp";
}
function goResources(myResource)
{
	document.location = myResource + ".asp";
}
function goResourcesSecure(myChap, myResource)
{
	document.location = "../../password/ch" + myChap + "/" + myResource + ".asp";
}
function goDocuments(myChap)
{
	document.location = "../../contents/ch" + myChap + "/documents.asp";
}
function goImages(myChap)
{
	document.location = "../../contents/ch" + myChap + "/images.asp";
}
function goAudio(myChap)
{
	document.location = "../../contents/ch" + myChap + "/audio.asp";
}
function goVideo(myChap)
{
	document.location = "../../contents/ch" + myChap + "/video.asp";
}
function goMaps(myChap)
{
	document.location = "../../contents/ch" + myChap + "/worksheet.asp";
}
function goImaps(myChap)
{
	document.location = "../../contents/ch" + myChap + "/imaps.asp";
}
function goChrono(myChap)
{
	chrono("../../contents/ch" + myChap + "/chrono.htm");
}
function goQuiz(myChap)
{
	quiz("../../quizzes/" + myChap + ".htm");
}
function goTFQuiz(myChap)
{
	quiz("../../quizzes/tf" + myChap + ".htm");
}

function goeBookURL()
{
//eBook link
	var url = "http://www.nortonebooks.com/";
	newwindow=window.open(url,'ebook');
	if (window.focus) {newwindow.focus()}
}
function goJukebox(myJbox)
{
//eBook link
	var url = "http://www.wwnorton.com/college/music/enj9/shared/jukebox/";
	newwindow=window.open(url + myJbox,'jbox','width=175,height=300,scrollbars=no,resizable=yes');
	if (window.focus) {newwindow.focus()}
}
function writeMenu(myChap)
{   
	if (myChap == -1) { //write generic menu
		//global
		//
		//Organize
		document.writeln('      <h3 id="organize">Organize</h3>');
		document.writeln('      <ul>');  
		document.writeln('        <li><a href="../index/studyplan.asp" title="Study Plan">Study Plan </a></li>');
		document.writeln('        <li><a href="../index/studyplan.asp" title="Chapter Podcast">Chapter Podcast </a></li>'); 
		document.writeln('        <li><a href="../index/studyplan.asp" title="Outline">Outline </a> </li>');
		document.writeln('        <li><a href="../index/studyplan.asp"" title="Map Worksheet">Map Worksheet </a> </li>');
		document.writeln('		<li id="progress"><a href="../index/studyplan.asp">Progress Report </a></li>');
 		document.writeln('     </ul>');
		//Learn
		document.writeln('      <h3 id="learn">Learn</h3>');
		document.writeln('      <ul>');
		document.writeln('        <li class="lock"><a href="../index/studyplan.asp" title="eBook">eBook </a></li>');
		document.writeln('        <li><a href="../index/studyplan.asp"" title="iMaps">iMaps </a></li>');
 		document.writeln('       <li><a href="../index/studyplan.asp" title="Multiple Choice Quiz">Multiple Choice Quiz </a></li>');
 		document.writeln('       <li><a href="../index/studyplan.asp" title="T/F Quiz">T/F Quiz </a></li>');
		document.writeln('        <li><a href="../index/studyplan.asp" title="Flashcards">Flashcards </a></li>');
		document.writeln('        <li><a href="../index/studyplan.asp"" title="Chrono-Sequencer">Chrono-Sequencer </a></li>');
		document.writeln('      </ul>');
		//Connect
		document.writeln('      <h3 id="Connect">Connect</h3>');
		document.writeln('      <ul>');
		document.writeln('        <li><a href="../index/studyplan.asp" title="Sources of Freedom">Sources of Freedom </a></li>');
		document.writeln('        <li><a href="../index/studyplan.asp" title="Documents">Documents </a></li>');
		document.writeln('        <li><a href="../index/studyplan.asp" title="Images">Images </a></li>');
		document.writeln('        <li><a href="../index/studyplan.asp" title="Audio">Audio </a></li>');
		document.writeln('        <li><a href="../index/studyplan.asp" title="Video">Video </a></li>');
		document.writeln('      </ul>');
	
	} else { // write chapter menu

		//global
		writeNextPrev(myChap);
		//Organize
		document.writeln('      <h3 id="organize">Organize</h3>');
		document.writeln('      <ul>'); 
		document.writeln('        <li><a href="javascript:goStudy(\''+myChap+'\')" title="Study Plan">Study Plan </a></li>'); 
		document.writeln('        <li><a href="javascript:goChPod(\''+myChap+'\')" title="Chapter Podcast">Chapter Podcast </a></li>');
		document.writeln('        <li><a href="javascript:goOutline(\''+myChap+'\')" title="Outline">Outline </a> </li>');
		document.writeln('        <li><a href="javascript:goMaps(\''+myChap+'\')" title="Map Worksheet">Map Worksheet </a> </li>');
		document.writeln('		<li id="progress"><a href="javascript:goProgress(\''+myChap+'\')">Progress Report </a></li>');
 		document.writeln('     </ul>');
		//Learn
		document.writeln('      <h3 id="learn">Learn</h3>');
		document.writeln('      <ul>');
		document.writeln('        <li class="lock"><a href="javascript:goeBook(\''+myChap+'\')" title="eBook">eBook </a></li>');
		document.writeln('        <li><a href="javascript:goImaps(\''+myChap+'\')" title="iMaps">iMaps </a></li>');
 		document.writeln('       <li><a href="javascript:goQuiz(\''+myChap+'\')" title="Multiple Choice Quiz">Multiple Choice Quiz </a></li>');
 		document.writeln('       <li><a href="javascript:goTFQuiz(\''+myChap+'\')" title="T/F Quiz">T/F Quiz </a></li>');
		document.writeln('        <li><a href="javascript:goFlashcards(\''+myChap+'\')" title="Flashcards">Flashcards </a></li>');
		document.writeln('        <li><a href="javascript:goChrono(\''+myChap+'\')" title="Chrono-Sequencer">Chrono-Sequencer </a></li>');
		document.writeln('      </ul>');
		//Connect
		document.writeln('      <h3 id="Connect">Connect</h3>');
		document.writeln('      <ul>');
		document.writeln('        <li><a href="javascript:goSources(\''+myChap+'\')" title="Sources of Freedom">Sources of Freedom </a></li>');
		document.writeln('        <li><a href="javascript:goDocuments(\''+myChap+'\')" title="Documents">Documents </a></li>');
		document.writeln('        <li><a href="javascript:goImages(\''+myChap+'\')" title="Images">Images </a></li>');
		document.writeln('        <li><a href="javascript:goAudio(\''+myChap+'\')" title="Audio">Audio </a></li>');
		document.writeln('        <li><a href="javascript:goVideo(\''+myChap+'\')" title="Video">Video </a></li>');
		document.writeln('      </ul>');
	}

	
}
function writeNextPrev (myChap)
{
	nextChap = eval(myChap.valueOf()) + 1; //eval needed because it wasn't working on Composer & similar pages (with chap=## arg)
	//nextChap = myChap.valueOf() + 1; 
	//alert (nextChap);
	prevChap = myChap.valueOf() - 1;
				
	switch (myChap) {
		case '01':
			document.writeln('    <div id="chapters_nav">&nbsp;&nbsp;&nbsp;&nbsp;Chapter <a href="javascript:goStudy(\''+((nextChap < 10)?'0'+nextChap:nextChap)+'\')"><img src="../../img/arrow_right.png" alt="Next Chapter" width="12" height="12" border="0" /></a></div>');
			break;
		case '28':
			document.writeln('    <div id="chapters_nav"><a href="javascript:goStudy(\''+((prevChap < 10)?'0'+prevChap:prevChap)+'\')"><img src="../../img/arrow_left.png" alt="Previous Chapter" width="12" height="12" border="0" /></a> Chapter&nbsp;&nbsp;&nbsp;&nbsp;</div>');
			break;
		default:

			document.writeln('    <div id="chapters_nav"><a href="javascript:goStudy(\''+((prevChap < 10)?'0'+prevChap:prevChap)+'\')"><img src="../../img/arrow_left.png" alt="Previous Chapter" width="12" height="12" border="0" /></a> Chapter <a href="javascript:goStudy(\''+((nextChap < 10)?'0'+nextChap:nextChap)+'\')"><img src="../../img/arrow_right.png" alt="Next Chapter" width="12" height="12" border="0" /></a></div>');
			break;
	}
}
function writeStudy (myChap)
{
	// write study page description
		document.writeln('<p class="heading">Organize</p>');
		document.writeln('<ol>');
		document.writeln('<li>Watch the chapter-opening <a href="javascript:goChPod(\''+myChap+'\')">Podcasts</a>.</li>');
		document.writeln('<li>Print-out the <a href="javascript:goOutline(\''+myChap+'\')">chapter outline</a> and check the items that your instructor has assigned or covered in class.</li>');
		document.writeln('<li>Print-out the <a href="javascript:goMaps(\''+myChap+'\')">Map Worksheets</a> for this chapter and reconnect the labels offline.</li>');
		document.writeln('<li>Generate a <a href="javascript:goProgress(\''+myChap+'\')">Progress Report</a>.   This report can also be sent to your Gradebook or to your instructor.</li>');
		document.writeln('</ol>');

		document.writeln('<p class="heading">Learn</p>');
		document.writeln('<ol>');
		document.writeln('<li>Read this chapter in your textbook or the <a href="javascript:goeBook(\''+myChap+'\')">eBook</a>.</li>');
		document.writeln('<li>Access the <a href="javascript:goImaps(\''+myChap+'\')">iMaps</a> for this chapter. Use the menus to view only the information you want to see as you study the geography and historical events represented on each map.</li>');
		document.writeln('<li>Take the <a href="javascript:goQuiz(\''+myChap+'\')">Multiple Choice</a> and <a href="javascript:goTFQuiz(\''+myChap+'\')">True / False</a> quizzes. Mail the results to your instructor\'s Gradebook and keep track of your progress in your student Gradebook.</li>');
		document.writeln('<li>Master the key events and terms for this chapter by working through the deck of <a href="javascript:goFlashcards(\''+myChap+'\')">FlashCards</a>. You can even shuffle cards from earlier chapters if you\'re trying to study for a test.</li>');
		document.writeln('<li>Click the <a href="javascript:goChrono(\''+myChap+'\')">Chrono-Sequencer</a> and match the dates and events.</li>');
		document.writeln('</ol>');

		document.writeln('<p class="heading">Connect to Sources of Freedom – Audio, Video,  Images, &amp; Primary Source Documents</p>');
		document.writeln('<p>Access these materials and select a subject for further study, extra credit, or for a project requirement.</p>');
		document.writeln('<p>Every source is accompanied by a Media Analysis Worksheet. Worksheets are designed to be filled-out online as you examine the multimedia resources. Email your observations, expressions, and connections to your instructor, or save a copy in your own course portfolio.</p>');
		document.writeln('<p>&raquo; <a href="javascript:goSources(\''+myChap+'\')">Access this chapter\'s Sources of Freedom</a>.</p>');
}

function showTranscript(myTrans) {
	day = new Date();
	id = day.getTime();
	URL = "../../contents/common/" + myTrans + "_transcript.htm"
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,left = 50,top = 50, width = 400, height = 300');");
}

function popUp1(URL,dimW,dimH) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,left = 50,top = 50, width = "+dimW+", height = "+dimH+"');");
}

//used to determine chapter # in unit pages (music, perspectives, transitions)
function getArgs() {
   var args = new Object();
   var query = location.search.substring(1); //Get query string.
   var pairs = query.split(",");             //Break at comma.
   for (var i = 0; i < pairs.length; i++) {
      var pos = pairs[i].indexOf('=');       //Look for "name=value".
      if (pos == -1) continue;               //If not found, skip.
      var argname = pairs[i].substring(0,pos);  //Extract the name.
      var value = pairs[i].substring(pos+1);    //Extract the value.

      //while (value.indexOf('+') > -1) {
        //value = value.substring(0,value.indexOf('+')) + '/' + value.substring(value.indexOf('+') + 1);
        // Replace each '+' in data string with a '/'.
      //}

      args[argname] = unescape(value);      //Store as a property.
   }
   return args;                            //Return the object.
}

function getChap(){
//	if !(currentChap) {
		var args = getArgs();
		if (args.chap) {
			//return args.chap.valueOf();
			return args.chap;
		} else {
			return -1;
		}
//	}
}