
  // detect if quicktime and/or flash plugins are available
    if (navigator.plugins) {
      for (var i=0; i < navigator.plugins.length; i++ ) {
        if (navigator.plugins[i].name.indexOf("QuickTime") >= 0)
        { haveqt = true; }
      }
    }
    
    if ((navigator.appVersion.indexOf("Mac") > 0)
      && (navigator.appName.substring(0,9) == "Microsoft")
      && (parseInt(navigator.appVersion) < 5) )
      { haveqt = true; }
  
    // Flash Version check based upon the values entered above in "Globals"
    haveflash = DetectFlashVer(requiredMajorFlashVersion, requiredMinorFlashVersion, requiredFlashRevision);

    function set_cookie ( cookie_name, cookie_value,
        lifespan_in_seconds)
    {		
        document.cookie = cookie_name +
                           "=" + encodeURIComponent( cookie_value ) +
                           "; max-age=" + lifespan_in_seconds +
                           "; path=/; domain=perpetualmotionpictures.com" ;
						   
    }


	function get_cookie(c_name)
	{
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1)
			{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return decodeURIComponent(document.cookie.substring(c_start,c_end));
			}
		  }
		return "";
	}

/*
    function get_cookie2 ( cookie_name )
    {
        var cookie_string = document.cookie;
        if (cookie_string.length != 0) {
            var cookie_value = cookie_string.match (
                            '(^|;)[\s]*' +
                            cookie_name +
                            '=([^;]*)' );
							
			if(cookie_value == null) return '';			
            return decodeURIComponent ( cookie_value[2] ) ;
        }
        return '' ;
    }
*/

    function delete_cookie ( cookie_name, valid_domain )
    {
        var domain_string = valid_domain ?
                           ("; domain=" + valid_domain) : '' ;
        document.cookie = cookie_name +
                           "=; max-age=0; path=/" + domain_string ;
    }

    //returns whether we can play the movie again yet
    function movieTime(movieFile, frequency) {      
		
      if (frequency < 1 || get_cookie(movieFile) == "Yes") {
        return false;
      } else {
		set_cookie(movieFile, "Yes", frequency); 
        return true;
      }   	    
    }

    //video will only auto-replay after the frequency number of seconds has passed
    function addMovie(movieFile, mwidth, mheight, frequency) {     
            //filepath = filepath + '/'
			webhost = 'http://www.perpetualmotionpictures.com'
            filepath = webhost + '/assets/'
            scriptpath = webhost + '/scripts/'
            var qtName = filepath + movieFile + '.mov'
            var flashPlayer = scriptpath + 'player.swf'
            var flashName = filepath + movieFile + '.flv'
            var stillName = filepath + movieFile + '.jpg'
            var movieDivId = "movie" + movieFile
			
		if (haveqt) {
			//document.write('<div id="'+movieDivId+'"></div>')
		  // this code is used if the QuickTime plugin is detected
		  if (movieTime(movieFile, frequency)) {			  
			// no cookie, autoplay defaults to true, movie will run on each page reload
			 QT_WriteOBJECT(qtName, mwidth, mheight, '', 'obj#id', movieDivId, 'emb#name', 
			 'movie1', 'enablejavascript', 'true',
			   'controller', 'false');
		  } else {
			// cookie has been set, use autoplay false so the movie won't run
			//QT controller adds 16 px to height
			mheight += 16
			QT_WriteOBJECT(qtName, mwidth, mheight, '', 'obj#id', movieDivId, 'emb#name', 
			'movie1', 'enablejavascript', 'true',
			'controller', 'true', 'autoplay', 'false');
		  }
		}		
		else if (haveflash) {
			// if we've detected an acceptable version
			// embed the Flash Content SWF when all tests are passed
			document.write('<div id="'+movieDivId+'"></div>')

			var s1 = new SWFObject(flashPlayer,'player', mwidth, mheight,'9', "#ffffff");
			s1.addParam('allowfullscreen','true');
				s1.addParam('allowscriptaccess','always');
			if (! movieTime(movieFile, frequency)) {
				// cookie has been set; just display the last frame
				//document.write('<img src="'+stillName+'" />');
				s1.addParam('flashvars','autostart=false&file=' 
					+ flashName + '&image=' + stillName); 
			} else {  //no cookie, autoplay the flash file
				s1.addParam('flashvars','autostart=true&file=' 
					+ flashName);   
			}
			s1.write(movieDivId);
		} else {  // no quicktime plugin and (flash is too old or we can't detect the flash plugin)
			var alternateContent = '<BR><BR>'
			+ 'This content requires either:<BR>'
		  + '   the Apple QuickTime Player '
			+ '<a href=http://www.apple.com/quicktime/download/>Get QuickTime</a><BR>'
		  + 'or the Adobe Flash Player. '
			+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
			document.write(alternateContent);  // insert non-flash content
		}
   }

/*
	AC_FL_RunContent(
			"src", flashName,
			"width", mwidth,
			"height", mheight,
			"align", "middle",
			"id", "detectionExample",
			"quality", "high",
			"bgcolor", "#FFFFFF",
			"name", "detectionExample",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"LOOP", "false",
			'menu', 'true',
			'allowFullScreen', 'true',
			'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
*/
