// JavaScript DocumentuserAgent = window.navigator.userAgent;
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 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 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;
}
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];}
}
//
//COOKIE TOOLS
//define function to set a cookie
function writeCookie(cookieName, cookieValue, daysTilExpiry){
	var the_cookie;
	//create variable that will be used to set document cookie.
	var expDate = new Date();
	//create new date container for expiration
	expDate.setTime (expDate.getTime() + 1000 * 60 * 60 * 24 * daysTilExpiry);
	//set the expiration date however many days in the future.
	the_cookie = cookieName + "=" + escape (cookieValue) + "; path=/; expires=" + expDate.toGMTString();
 	//path variable makes cookie available throughout site, including intro page
	//must connvert expiration date to proper GMT format
    document.cookie = the_cookie;
	//the cookie is set for the page
}
//define function to read the value of cookie named 'name'
//if cookie value is == 1, go to flash interface
function readCookie(name) {
	if (document.cookie == '') { 
    	//alert('clause 1: theres no cookie, so go no further'); 
    	return false;
	} else {
		//alert('there is a cookie');
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);
		// find the start of 'name'
		if(firstChar != -1)  {
			// if you found the cookie
			firstChar += name.length + 1;
			// skip 'name' and '='
	   		lastChar = theBigCookie.indexOf(';', firstChar);
		    // Find the end of the value string (i.e. the next ';').
		   	if(lastChar == -1){
				lastChar = theBigCookie.length;
			}
			var result = unescape(theBigCookie.substring(firstChar, lastChar));
			//alert('readCookie found result='+result);
			return result;
		} else {
	   		// If there was no cookie of that name, return false.
			return false;
		}
    }
}
//FUNCTION TO RESET COOKIES (EDIT WHICH COOKIES ARE EFFECTED)
function killCookies(){
	writeCookie('careers', 0, -10);
	writeCookie('medical-animation', 0, -10);
	writeCookie('gallery', 0, -10);
	writeCookie('company', 0, -10);
	writeCookie('news', 0, -10);
	writeCookie('contact', 0, -10);
	writeCookie('foo', 0, -10);
	alert ("Cookies zeroed. "+document.cookie);
	window.location.replace('index.html');
}
//function to check a given section to see if it's already played audio. 
//if hasn't already played, play it & tag cookie to disable playback for 1 day.
function audioCheck(section){
	//alert('audiochecking '+section);
	//alert('readCookie(section) returned '+readCookie(section));
	if (readCookie(section) != 1){
		//haven't played recently - go for it.
		//plop appropriate audio swf on page
		document.write('<div id="audio">');
  		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
		document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="20" height="20">');
    	document.write('<param name="movie" value="../flash/audio/'+section+'.swf">');
    	//alert('embedding ../flash/audio/'+section+'.swf')
		document.write('<param name="quality" value="high">');
    	document.write('<embed src="../flash/audio/'+section+'.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="20" height="20"></embed>');
		document.write('</object>');
		document.write('</div>');
		//alert('tag cookie to indicate that this page has played already');
		writeCookie(section,1,1);
	}
}