// 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(url,'imap','height=421,width=761,resizable=1');
	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=271,width=341');
	if (window.focus) {newwindow.focus()}
}

var newwindow;

function chrono(url)
{
	newwindow=window.open(url,'chrono','height=450,width=670,resizable=1,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

var newwindow;

function worksheet(url)
{
	newwindow=window.open(url,'worksheet','height=400,width=471,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: Microbiology Website Referral";
u = window.location;
window.location="mailto:"+e_add+"?subject="+subj+"&body=Check out this W. W. Norton and Company: Microbiology Website Page: "+u;
}