/*
 *    Author:        ...
 *    Description:   Homepage Flash Intro Animation and Body Animation Controls.
 *    Last Update:   Jan 23r, 2007
 */

// Example:

// writeCookie("myCookie", "my name", 24);

// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name, value, hours) {
  	var expire = "";
	if(hours != null) {
    	expire = new Date((new Date()).getTime() + hours * 3600000);
    	expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire;
}

// Example:

// alert( readCookie("myCookie") );

function readCookie(name) {
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search);
    	if (offset != -1) { 
			offset += search.length;
      		end = document.cookie.indexOf(";", offset);
      		if (end == -1) end = document.cookie.length;
      		cookieValue = unescape(document.cookie.substring(offset, end))
    	}
	}
  	return cookieValue;
}

// Borrowed from Moock.org
// var movieName;
function fsMovie(movieName) 
{
  if (window.document[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);
  }
}

/* Cut the Body Animation as it is hidden. Play the Intro Anime. When done playing remove the Intro Anime and Paste in the Body Anime.*/
var hold_myFlash;
function fsIntroduction()
{ 
   // fsMovie('myFlash').TStopPlay("/photo.photo1ani"); Doesn't seem to work.
   // hold_myFlash = document.getElementById('homepage-article').innerHTML; // save the orig movie for later use.
   // document.getElementById('homepage-article').innerHTML = ' '; // cut the orig movie from the DOM.
   

   document.getElementsByTagName('body')[0].innerHTML += ' ' + 
               '<div id="flashShell"  style="position:absolute; top:0; left:0; z-index:1001;"><object id="introFlash" width="990" height="620" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">' + 
                  '<param name="allowScriptAccess" value="sameDomain" />' + 
                  '<param name="movie" value="fitzpatrickIntro.swf?cookieset=' + readCookie('cookieset')+'" />' +
                  '<param name="quality" value="high" />' +
                  '<param name="scale" value="exactfit" />' +
                  '<param name="wmode" value="transparent" />'+
                  '<param name="bgcolor" value="#ffffff" />' +
                  '<embed src="fitzpatrickIntro.swf?cookieset=' + readCookie('cookieset')+'" name="introFlash" width="990" height="620" quality="high" scale="exactfit"  wmode="transparent" bgcolor="#ffffff" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true"  />' +
               '</object></div>';

	writeCookie("cookieset", "viewed", 24);   
}

/* Remove the Intro Movie */
function fswipe()
{
   document.getElementById('flashShell').innerHTML = ' ';
}

/* Flash Interception */
function introFlash_DoFSCommand(command, args)                
{
   setTimeout('fswipe()', 10);
   // document.getElementById('homepage-article').innerHTML =  hold_myFlash; // drop the orig movie back in the DOM.
   fsMovie('myFlash').TGotoFrame("/", 1);
   if (navigator.appName.indexOf("Microsoft") != -1) document.getElementsByTagName('body')[0].style.zoom = '1';
}
   
/* IE Hack */
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) 
{
   document.write('<SCRIPT LANGUAGE=VBScript\> \n');
   document.write('on error resume next \n');
   document.write('Sub introFlash_FSCommand(ByVal command, ByVal args)\n');
   document.write(' call introFlash_DoFSCommand(command, args)\n');
   document.write('end sub\n');
   document.write('</SCRIPT\> \n');
} 