function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

/* Function that loads images for swapping. */
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

/* Function that pops up keyword window */

function OpenKeywords (c) {
    newwindow=window.open(c,
                    'keyword',
                    'width=480,height=600,scrollbars=yes,status=yes');
	if (window.focus) {newwindow.focus()}
}

/* Function that pops up gallery window */

function OpenGallery (c) {
   newwindow=window.open(c,
                    'media',
                    'width=755,height=535,scrollbars=yes,status=yes');
   if (window.focus) {newwindow.focus()}
}

function OpenS2S (c) {
   newwindow=window.open(c,
                    'media',
                    'width=750,height=650,scrollbars=yes,status=yes');
   if (window.focus) {newwindow.focus()}
}

/* Function that pops up video player window */

function OpenVideo (c) {
    newwindow=window.open(c,
                    'clip',
                    'width=755,height=455,scrollbars=yes,status=yes');
	if (window.focus) {newwindow.focus()}
}

/* Function that pops up audio player window */

function OpenAudio (c) {
    OpenVideo(c);
}

/* Function that pops up scrapbook window */

function OpenScrapbook (c) {
    newwindow=window.open(c,
                    'media',
                    'width=670,height=530,scrollbars=yes,status=yes');
	if (window.focus) {newwindow.focus()}
}

/* Function that pops up scrapbook window */

function OpenNewPage (c) {
    newwindow=window.open(c,
                    'media',
                    'width=820,height=530,scrollbars=yes,status=yes');
	if (window.focus) {newwindow.focus()}
}

/* function that pops up an invite window */

function OpenInvite (c) {
	var partyDate = new Date;
	partyDate.setDate(13);
	partyDate.setMonth(8); /*Jan = 0*/
	partyDate.setYear(2005);
	var today = new Date;
	/*if(today.getTime() < myDate.getTime()) {*/
     	window.open('invite.html',
                    'invite',
                    'width=470,height=560,scrollbars=no,status=no');
	/*}
	else
	{
		alert ('Party has passed.');
	}*/
}

/* function that closes the keyword if the user came from pe; otherwise, the script opens a new window to the home page */

function KeywordClick () {
//	if (document.referrer.indexOf('projectexplorer.org') != -1) 
	if (opener.location.href.indexOf('projectexplorer.org') != -1)
	{
		window.close();
	}
	else
	{
		window.open('http://www.projectexplorer.org/','pe');
	}
}

/* functions for linking Javascript and Flash */

function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
//  if (window.document[movieName]) 
//  {
//	  alert(movieName);
//      return window.document[movieName];
//  }
//  if (navigator.appName.indexOf("Microsoft Internet")==-1)
//  {
    if (document.embeds && document.embeds[movieName]){
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  } 
}

// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
  // First make sure the movie's defined.
  if (typeof(theMovie) != "undefined") {
    // If it is, check how much of it is loaded.
    return theMovie.PercentLoaded() == 100;
  } else {
    // If the movie isn't defined, it's not loaded.
    return false;
  }
}

function pressPlay(movieId) {

 var myMovie = thisMovie("audioplayer" + movieId);
 if (movieIsLoaded(myMovie)) {
 	if(myMovie.TGetProperty('/', 4) > 2) {
 	    ap_stopAll('foo');
 	}
 	else
 	{
 		ap_stopAll(movieId);
 		myMovie.Play();
	}
 }
}

var ap_instances = new Array();

function ap_stopAll(playerID) {
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) thisMovie("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
			else thisMovie("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName("object");
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
		if(objectID.indexOf("audioplayer") == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

var ap_clearID = setInterval( ap_registerPlayers, 100 );