preloadArray('../images/menu/',new Array('home','mycoll','collections','bigsearch','help'),new Array('EN','DE','FR','ES'));
  
function preloadArray(dir,array,lang){
    if (document.images){
	for (var i=0; i<array.length; i++){
	    CURR_ARRAY_ITEM = array[i];
	    for (var j=0;j<lang.length;j++){
		eval(CURR_ARRAY_ITEM+'_'+lang[j]+'_on = new Image()');
		//alert(CURR_ARRAY_ITEM+'_'+lang[j]+'_on.src = dir+"'+CURR_ARRAY_ITEM+'_'+lang[j]+'_on.gif";');
		eval(CURR_ARRAY_ITEM+'_'+lang[j]+'_on.src = dir+"'+CURR_ARRAY_ITEM+'_'+lang[j]+'_on.gif";');
		eval(CURR_ARRAY_ITEM+'_'+lang[j]+'_off = new Image()');
		eval(CURR_ARRAY_ITEM+'_'+lang[j]+'_off.src = dir+"'+CURR_ARRAY_ITEM+'_'+lang[j]+'_off.gif";');
	    }
	}
    }
}
  
     
function rollIn(imgName,lang){
    if (document.images){
	document[imgName].src=eval(imgName + "_" + lang + "_on.src");
    }
}

function rollOut(imgName,lang){
    if (document.images){
	document[imgName].src=eval(imgName + "_" + lang + "_off.src");
    }
}

function f_getcookieval(offset){
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function f_getcookie(name){
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg) return f_getcookieval (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
    }
    return '';
}

function f_setcookie (name, value, expires){
    document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
}

function test4Cookies(){
    if (!test4CookieInt()){
	document.getElementById("cookietest").style.visibility='visible';
    }
}

function test4CookieInt(){
    f_setcookie("testcook","1",null)
    if (f_getcookie("testcook")=="1"){
	return true;
    }else{
	return false;;
    }
}

function clearNew(){
    //clear the 'new' values which are used for page navigation
    //(this protects against problems occuring when the user clicks the
    //browser 'back' button)

    //&newvalues=1 flags the beginning of any 'new' state values that get set for navigation
    //Clear out any existing before setting.
    document.frm.action=removeFromUrl(document.frm.action,'newvalues');
}

function linksearch(module,profile, fieldname, fieldvalue, style, searchdesc){
    checkForSelectedMyColls();
    clearNew();
    document.frm.emu_action.value = 'searchrequest'; 

    //Build the URL-encoded search string
    if (window.encodeURIComponent){
            document.frm.action += '&newvalues=1&rawsearch=' + encodeURIComponent(fieldname) + '/,/is/,/' + encodeURIComponent(fieldvalue) + '/,/false/,/true&newstyle=' + style + '&newprofile=' + profile + '&newsearchdesc=' + encodeURIComponent(searchdesc) + '&newcurrentrecord=1&module='+module + '&moduleid=1';
    }else{
            document.frm.action += '&newvalues=1&rawsearch=' + escape(fieldname) + '/,/is/,/' + escape(fieldvalue) + '/,/false/,/true&newstyle=' + style + '&newprofile=' + profile + '&newsearchdesc=' + escape(searchdesc) + '&newcurrentrecord=1&module='+module+'&moduleid=1';          

    }
    document.frm.submit();
}


function singleview(newpage){
    checkForSelectedMyColls();
    clearNew();
    document.frm.emu_action.value = 'newpage';
    document.frm.action += '&newvalues=1&newstyle=single&newcurrentrecord=' + newpage;
    document.frm.submit();
}

function submitpage(action,para){
    checkForSelectedMyColls();
    clearNew();
    document.frm.emu_action.value = action;
    var cS;
    if (document.frm.action.indexOf("?")==-1){cS='?'}else{cS='&'}
    switch (action){
    case 'newpage' :
	document.frm.action += cS + 'newvalues=1&newcurrentrecord=' + para;
	break
    case 'style' :
	document.frm.action += cS + 'newvalues=1&newstyle=' + para;
	break
    case 'sort' :
	document.frm.action += cS + 'newvalues=1&newcurrentrecord=1&newsortstring=' + para;
	break;
    case 'page' :
	document.frm.emu_action.value = 'newpage';
	document.frm.action += cS + 'newvalues=1&newpage=' + para;
	break;
    case 'profile' :
	document.frm.action += cS + 'newvalues=1&newprofile=' + para;
	break
    default :
	break
    }
    document.frm.submit();
}

// debug: TJC 2/8/07: I don't see this function being used anywhere, and I need similar functionality.  
//			original is saved below.
function switchprofile(profile){
    document.frm.action=appendOrReplace2Url(document.frm.action,'newprofile',profile);
    document.frm.action=appendOrReplace2Url(document.frm.action,'newvalues','1');
}
function switchprofileSAVE(profile){
    checkForSelectedMyColls();
    clearNew();
    document.frm.action=appendOrReplace2Url(document.frm.action,'newprofile',profile);
    document.frm.action=appendOrReplace2Url(document.frm.action,'newvalues','1');
    document.frm.submit();
}
	
function switchlang(lang){
    checkForSelectedMyColls();
		
    var loc=document.location.href;
    loc=appendOrReplace2Url(loc,'lang',lang);
    loc=appendOrReplace2Url(loc,'profile','');
    loc=appendOrReplace2Url(loc,'newprofile','');
    loc=appendOrReplace2Url(loc,'isnewlang','1');

    document.langswop.sessionid.value=document.frm.sessionid.value;
    document.langswop.searchxml.value=document.frm.searchxml.value;
    document.langswop.module.value=document.frm.module.value;
    document.langswop.moduleid.value=document.frm.moduleid.value;
    document.langswop.action=loc;
    document.langswop.submit();
}

function submitcollection(colname,colid){
    checkForSelectedMyColls();
    clearNew();
    document.frm.emu_action.value = 'collection'
    if (window.encodeURIComponent){
	document.frm.action = 'emuseum.asp?emu_action=collection&collection=' + colid + '&collectionname=' + encodeURIComponent(colname) + '&currentrecord=1&moduleid=1&module=';
    }else{
	document.frm.action = 'emuseum.asp?emu_action=collection&collection=' + colid + '&collectionname=' + escape(colname) + '&currentrecord=1&moduleid=1&module=';
    }
    document.frm.profile.value='';
    document.frm.submit();
}

function submitmycollection(colname,colid,isowner){
    checkForSelectedMyColls();
    clearNew();
    document.frm.emu_action.value = 'mycollection'
    if (window.encodeURIComponent){
	document.frm.action = 'emuseum.asp?emu_action=mycollection&mycollection=' + colid + '&mycollectionname=' + encodeURIComponent(colname) + '&currentrecord=1&isowner='+isowner;
    }else{
	document.frm.action = 'emuseum.asp?emu_action=mycollection&mycollection=' + colid + '&mycollectionname=' + escape(colname) + '&currentrecord=1&isowner='+isowner;
    }
    document.frm.submit();
    //window.history.back(1);
}

function activatemycollection(colname,colid){
    clearNew();
    document.frm.emu_action.value = 'mycollectionactivate'
    if (window.encodeURIComponent){
	document.frm.action = 'emuseum.asp?emu_action=mycollectionactivate&mycollection=' + colid + '&mycollectionname=' + encodeURIComponent(colname) + '&currentrecord=1';
    }else{
	document.frm.action = 'emuseum.asp?emu_action=mycollectionactivate&mycollection=' + colid + '&mycollectionname=' + escape(colname) + '&currentrecord=1';
    }
    document.frm.submit();
    //window.history.back(-1);
}

function addobjects2mycoll(byuser){
    var oidtext='';
    var oids='';
    var otexts='';
    var surl='';
    var objids='';
    var pagesize=document.usercoll.pagesize.value;
    var colid=document.usercoll.currentusercollid.value;
    var colname=document.usercoll.currentusercollid[document.usercoll.currentusercollid.selectedIndex].text;
    var modid=document.usercoll.moduleid.value;
    var lang=document.usercoll.lang.value;
    var selectedIDs=document.frm.cachedmycollitems.value;
    var item_notes = document.usercoll.item_notes.value;		// added by TJC 6/28/2007
    var arr_selectedIDs=selectedIDs.split(",");
    
    if (colid=='' && byuser=='1'){
	alert("Please select a my Collection from the drop down list.");
    }else{
	for (var i=0;i<document.selected4mycoll.elements.length;i++) {
	    if (document.selected4mycoll.elements[i].name=='add2mycoll'){
		if(document.selected4mycoll.elements[i].checked==1){
		    oidtext=document.selected4mycoll.elements[i].value;
		    var j = oidtext.indexOf(":::",0);
		    if (j>-1){
			if (!isInCachedMyColls(arr_selectedIDs,modid,oidtext.substring(0,j))){
			    oids+=','+modid+'^'+oidtext.substring(0,j);
			    otexts+='/,/'+oidtext.substring(j+3);
			}
		    }
		    if (byuser=='1'){
			document.selected4mycoll.elements[i].checked=0;
		    }
		}
	    }
	}
	oids=oids.substring(1);
	otexts=otexts.substring(3);
	if (byuser=='1'){
	    if (oids!='' || document.frm.cachedmycollitems.value!=''){
		if (window.encodeURIComponent){
		    surl='AddObjToColl.asp?byuser=1&lang='+lang+'&objectid=' + oids + '&mycollectionid=' + colid + '&objtext=' + encodeURIComponent(otexts)+'&mycollectionname='+encodeURIComponent(colname)+'&item_notes='+encodeURIComponent(item_notes);
		}else{
		    surl='AddObjToColl.asp?byuser=1&lang='+lang+'&objectid=' + oids + '&mycollectionid=' + colid + '&objtext=' + escape(otexts)+'&mycollectionname='+escape(colname)+'&item_notes='+escape(item_notes);
		}

		openWindow(surl,'Confirmation','width=400,height=300,scrollbars=yes,resizable=no,screenx=200,screeny=200,left=200,top=200,titlebar=0');
		document.frm.cachedmycollitems.value='';
	    }
	}else{
	    if (oids!=''){
		document.frm.cachedmycollset.value='1';
		document.frm.cachedmycollitems.value=oids;
		document.frm.cachedmycollitemstext.value=otexts;
	    }
	}
    }
}

function checkForSelectedMyColls(){
    var anySelected=0;
    if (typeof(document.usercoll)!="undefined"){
	for (var i=0;i<document.selected4mycoll.elements.length;i++) {
	    if (document.selected4mycoll.elements[i].name=='add2mycoll'){
		if(document.selected4mycoll.elements[i].checked==1){
		    anySelected=1;
		}
	    }
	}
	document.frm.currentusercollid.value=document.usercoll.currentusercollid.value;
	if (anySelected==1){
	    addobjects2mycoll(0);
	}
    }
}

function checkCachedMyColls(){
    var arr_selectedIDs='';
    if (typeof(document.usercoll)!="undefined"){
	var modid=document.usercoll.moduleid.value;
	arr_selectedIDs=document.frm.cachedmycollitems.value.split(",");

	for (var i=0;i<document.selected4mycoll.elements.length;i++) {
	    var current=document.selected4mycoll.elements[i].value;
	    var j = current.indexOf(":::",0);
	    if (j>-1){
		var oid=current.substring(0,j);
		if (isInCachedMyColls(arr_selectedIDs,modid,oid)){
		    document.selected4mycoll.elements[i].checked=1;
		}
	    }
	}
    }
}

function isInCachedMyColls(arr_selectedIDs,modid,oid){
    var to_return=false;
    for (var k=0;k<arr_selectedIDs.length;k++){
	var singleCached=arr_selectedIDs[k];
	var l=singleCached.indexOf("^",0);
	if (l>-1){
	    var smodid=singleCached.substring(0,l);
	    var soid=singleCached.substring(l+1);
	    if (modid==smodid && soid==oid){
		to_return= true;
	    }
	}
    }
    return to_return;
}

function addQSToURL(){
    checkForSelectedMyColls();
    clearNew();
	
    document.frm.action=appendOrReplace2Url(document.frm.action,'quicksearch',document.frm.quicksearch.value);
}

function appendOrReplace2Url(sUrl,sKey,sValue){
    sUrl=removeFromUrl(sUrl,sKey);
    if (sValue.length>0){
	var cS;
	if (sUrl.indexOf('?')==-1){
	    cS='?';
	}else{
	    cS='&';
	}
	return sUrl+cS+sKey+'='+sValue;
    }else{
	return sUrl;
    }
}

function removeFromUrl(sUrl,sKey){
    var i = sUrl.indexOf('?'+sKey+'=');
    if (i==-1){
	i = sUrl.indexOf('&'+sKey+'=');
    }
    if (i>-1){
	var j=sUrl.indexOf('&',i+1);
	if (j==-1){
	    return sUrl.substr(0,i);
	}else{
	    return sUrl.substr(0,i+1) + sUrl.substr(j+1);
	}
    }else{
	return sUrl;
    }
}

function openWindow(winURL,winName,winFlags){
    var myWindow=window.open(winURL,winName,winFlags);
    if (myWindow!=null){
    	myWindow.focus();
    }
}

function acrobatTest(){
    window.focus();
    if (document.getElementById) {
	if (!acrobat.installed){
	    if (typeof(document.report)!="undefined"){
		if (document.report.exportformat.value=="pdf"){
		    document.getElementById('ppreview').innerHTML='<a href="http://www.adobe.com/products/acrobat/readstep2.html"><img src="../images/get_adobe_reader.gif" width="88" height="31" border="0" name="acrobat" alt="get acrobat reader"/></a>';
		}
	    }
	}
    }
}

function showReport(reportname){
    checkForSelectedMyColls();
    document.report.action = 'eMuseum.asp?emu_action=report&report=' + reportname + '&sessionid=' + document.frm.sessionid.value;
    //openWindow('','reportPopup','width=800,height=600,scrollbars=yes,resizable=yes');
    //document.report.submit(); as it submitted twice!
}

function changepage(page,profile){
    checkForSelectedMyColls();
    clearNew();
    document.frm.emu_action.value = 'newpage';
    document.frm.action=appendOrReplace2Url(document.frm.action,'newprofile',profile);
    document.frm.action=appendOrReplace2Url(document.frm.action,'newpage',page);
    document.frm.action=appendOrReplace2Url(document.frm.action,'newvalues','1');
    document.frm.submit();
}

function setMedia(filename,caption,enlargetext,lang,zoomify){
    //selects a particular media record for enlarging
    document.media.filename.value = filename;
    document.media.caption.value = utf_decode(caption);
    document.media.title.value = utf_decode(enlargetext);
    document.media.zoomify.value = zoomify;
    if( zoomify != 0 )
	spawn('../html/media_enlarged_' + lang + '.html','popup','700','500');
    else
	spawn('../html/media_enlarged_' + lang + '.html','popup','645','450');
}

function spawn(url, nameW, w, h){
    if (navigator.appVersion.indexOf('4') != -1) {
	// Vars for centering the new window on Version 4 Browsers
	x4 = screen.width/2 - (w/2);
	y4 = screen.height/2 - (h/2);
	window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=0,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + x4 + ',top=' + y4 + '');
    }else{
    	window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=0,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=150,top=200');
    }
}

function spawnScroll(url, nameW, w, h){
    if (navigator.appVersion.indexOf('4') != -1) {
	// Vars for centering the new window on Version 4 Browsers
	x4 = screen.width/2 - (w/2);
	y4 = screen.height/2 - (h/2);
	window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=1,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=' + x4 + ',top=' + y4 + '');
    }else{
    	window.open(url, nameW, 'height='+h+',width='+w+',scrollbars=0,resizable=0,menubar=0,toolbar=0,status=0,location=0,directories=0,left=150,top=200');
    }
}

function openImage(imgName,sTitle,sCaption){
    var sHTML = "&lt;html&gt;&lt;head&gt;&lt;title&gt;"+sTitle+"&lt;/title&gt;&lt;link rel='stylesheet' href='../txtStyle.css' type='text/css'/&gt;&lt;/head&gt;&lt;body&gt;&lt;table cellpadding='0' cellspacing='0' border='0' width='100%'&gt;&lt;tr valign='top'&gt;&lt;td class='title'&gt;"+sTitle+"&lt;/td&gt;&lt;td align='right' class='txt'&gt;&lt;a href='javascript:window.close();'&gt;Close&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class='txt'&gt;"+sCaption+"&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br&gt;&lt;img src='getimage.asp?filename="+imgName+"&type=full' width='400' height='400' border='0' alt='"+sTitle+"'&gt;&lt;/body&gt;&lt;/html&gt;";
    var theWindow = "";
    theWindow = window.open("","","height=540,width=540,resizable,scrollbars");
    if(theWindow){
    	theWindow.document.write(sHTML);
    	theWindow.document.close();
    }
}

//
// The following added by Seattle Art Museum in support of SAM's close-ups presentation of the online collection.
//

  //
  //  Current active slide in slideshow.  Used to turn on/off border around selected slide.
  //
  var currentSlide = "";

  //
  // loadTidbit (single image slidshow)
  //
  //  Parameters:	
  //	img		- image to load in image box
  //	fullImg		- full size image
  //	zoomify		- zoomify image flag
  //	caption		- caption for this image
  //	enlargeText	- text for enlarge display
  //	enlargeCaption	- text for enlarge display
  //	header		- header for text in content box
  //	text		- text for content box
  //	objectid	- optional, link to object
  // 
  //
  function loadTidbit( img, fullImg, zoom, caption, enlargeText, enlargeCaption, header, text, objectid ){
    if( document.getElementById ){
	// close old content
	closeTimeline();
	closeMovie();
	closeAudio();
	closeSlideShow();
	closeMap();
	showDiv('refresh01', "", 0);
	showDiv('overview', "", 0);
	hideDiv('cakeLayer', "", 0);
	showDiv('cakeBottom', "", 0);

	showTidbit( img, fullImg, zoom, caption, enlargeText, enlargeCaption, header, text, objectid );
    }
  }

  //
  // loadSlideShow
  //
  //  Parameters:	
  // 	navDiv		- div with slideshow navigation thumbnails
  // 	img		- image to load in image box
  //	fullImg		- full size image
  //	zoomify		- zoomify image flag
  // 	caption		- caption for this image
  //	enlargeText	- text for enlarge display
  //	enlargeCaption	- text for enlarge display
  // 	header		- header for text in content box
  // 	text		- text for content box
  //	currSlide 	- id of currently slideshow navigation div (to highlight)
  //	objectID 	- optional, link to object
  //
  function loadSlideShow( navDiv, img, fullImg, zoom, caption, enlargeText, enlargeCaption, header, text, currSlide, objectid ){
    if( document.getElementById ){
	// close old content
	closeTimeline();
	closeMovie();
	closeAudio();
	closeMap();
	showDiv('refresh01', "", 0);
	showDiv('overview', "", 0);
	hideDiv('cakeLayer', "", 0);
	showDiv('cakeBottom', "", 0);

	// load new content
	srcDiv = document.getElementById( navDiv );
	dstDiv = document.getElementById( 'slide01Content' );
	dstDiv.style.left = "0px";			// reset position!
	if( srcDiv && dstDiv ){
	    dstDiv.innerHTML = srcDiv.innerHTML;
	}
	showDiv( 'slide01', "", 0 );

	// Enable/Disable nav arrows based on content width (is scrolling necessary?)
	var w = dstDiv.offsetWidth;				// slideshow width
	var p = dstDiv.parentNode;				// parent div (containing box)
	var pw = parseInt( p.offsetWidth );			// parent div width
	leftArrow = document.getElementById( "slideLeftArrow" );
	rightArrow = document.getElementById( "slideRightArrow" );
	if( w <= pw ){						// no scrolling necessary, hide arrows
	    leftArrow.style.visibility  = "hidden";
	    rightArrow.style.visibility = "hidden";
	} else {						// do scroll, show arrows
	    leftArrow.style.visibility  = "visible";
	    rightArrow.style.visibility = "visible";
	}

	// more unforseen circumstances... a slideshow without text?!  If so, clear the text pane!
	if( text == "" )
	    text = "<p>&nbsp;</p>";

	// load first slide
	showSlide( img, fullImg, zoom, caption, enlargeText, enlargeCaption, header, text, currSlide, objectid );

	// highlight selected slide
	currentSlide = currSlide;
	srcDiv = document.getElementById( currentSlide );
	if( srcDiv ){
	    srcDiv.style.border = "1px solid #1899C4";		// try: #1899C4 (dark blue)  #B96119 (orange)
	}
    }
  }

  //
  // loadTimeline
  //
  // div	- contains timeline content
  //
  function loadTimeline( timelineDiv ){
    if( document.getElementById ){
	// close old content
	closeSlideShow();
	closeMovie();
	closeAudio();
	closeMap();
	showDiv('refresh01', "", 0);
	hideDiv('overview', "", 0);
	hideDiv('cakeLayer', "", 0);
	showDiv('cakeBottom', "", 0);

	// load new content
	srcDiv = document.getElementById( timelineDiv );
	dstDiv = document.getElementById( 'bigBox01Content' );
	if( srcDiv && dstDiv ){
	    dstDiv.innerHTML = srcDiv.innerHTML;
	}

	showDiv( 'bigBox01', "", 1 );
    }
  }

  //
  //  loadSlideNEW
  //  showSlideNEW
  //  Update slideshow area with image and caption, plus header and text if present.
  //
  //  Parameters:	
  //			navDiv	if not empty, slide navigation div
  //			imgContent	div containing image data
  //			txtContent	div containint text data
  //			currSlide	div ID of current slide
  //
  //  Assumptions:
  //			content01 holds both img01 and txt01
  //			scrollDiv for slide image is 'img01' and content is 'img01Content'
  //			scrollDiv for text is 'txt01' and content is 'txt01Content'
  //
  function loadSlideNEW( navDiv, imgContent, txtContent, currSlide ){
	navDiv = navDiv.replace(/^ */, "");		// strip leading blanks

	// close old content
	closeTimeline();
	closeMovie();
	closeAudio();
	closeMap();
	showDiv('refresh01', "", 0);
	showDiv('overview', "", 0);
	hideDiv('cakeLayer', "", 0);
	showDiv('cakeBottom', "", 0);

	// if navDiv is present, need to load the navigation div
	// load new content
	srcDiv = document.getElementById( navDiv );
	dstDiv = document.getElementById( 'slide01Content' );
	if( srcDiv && dstDiv ){
	    dstDiv.style.left = "0px";			// reset position!
	    dstDiv.innerHTML = srcDiv.innerHTML;
	    showDiv( 'slide01', "", 0 );
	}

	// Enable/Disable nav arrows based on content width (is scrolling necessary?)
	var w = dstDiv.offsetWidth;				// slideshow width
	var p = dstDiv.parentNode;				// parent div (containing box)
	var pw = parseInt( p.offsetWidth );			// parent div width
	leftArrow = document.getElementById( "slideLeftArrow" );
	rightArrow = document.getElementById( "slideRightArrow" );
	if( w <= pw ){						// no scrolling necessary, hide arrows
	    leftArrow.style.visibility  = "hidden";
	    rightArrow.style.visibility = "hidden";
	} else {						// do scroll, show arrows
	    leftArrow.style.visibility  = "visible";
	    rightArrow.style.visibility = "visible";
	}

  	showSlideNEW( imgContent, txtContent, currSlide )
  }
  function showSlideNEW( imgContent, txtContent, currSlide ){

	// Left pane/text content
	selectedDiv = document.getElementById( 'img01Content' );
	scrollDiv = document.getElementById( 'img01' );
	srcDiv = document.getElementById( imgContent );
	if( selectedDiv && srcDiv ){
		selectedDiv.innerHTML = srcDiv.innerHTML;
	        showDiv( 'img01', "", 1 );
	}
	if( scrollDiv ){
		// reset to top of div
	        scrollDiv.contentScroll( "0", "0", false );
	}

	// Right pane/text content
	// Only update if text present (some slideshows don't change the text)
	selectedDiv = document.getElementById( 'txt01Content' );
	scrollDiv = document.getElementById( 'txt01' );
	srcDiv = document.getElementById( txtContent );
	if( selectedDiv && srcDiv ){
		selectedDiv.innerHTML = srcDiv.innerHTML;
	        showDiv( 'txt01', "", 1 );
	}
	if( scrollDiv ){
		// reset to top of div
	        scrollDiv.contentScroll( "0", "0", false );
	}

	// un-highlight prior selection, highlight current
	srcDiv = document.getElementById( currentSlide );
	if( srcDiv ){
	    srcDiv.style.border = "1px solid #85C6D8";
	}
	currentSlide = currSlide;
	srcDiv = document.getElementById( currentSlide );
	if( srcDiv ){
	    srcDiv.style.border = "1px solid #1899C4";		// try: #1899C4 (dark blue)  #B96119 (orange)
	}
  } 

  //
  //  showSlide
  //  Update slideshow area with image and caption, plus header and text if present.
  //
  //  Parameters:	
  //			img		image source
  //			fullImg		full size image
  //			zoomify		zoomify image flag
  //			caption		image caption
  //			enlargeText	text for enlarge display
  //			enlargeCaption	text for enlarge display
  //			header		header text
  //			text		content text
  //			currSlide	id for current navigation thumbnail (to highlight)
  //			objectID 	optional, link to object
  //
  //  Assumptions:
  //			content01 holds both img01 and txt01
  //			scrollDiv for slide image is 'img01' and content is 'img01Content'
  //			scrollDiv for text is 'txt01' and content is 'txt01Content'
  //
  function showSlide( img, fullImg, zoom, caption, enlargeText, enlargeCaption, header, text, currSlide, objectid ){
	// show the slide/text
	showTidbit( img, fullImg, zoom, caption, enlargeText, enlargeCaption, header, text, objectid );

	// un-highlight prior selection, highlight current
	srcDiv = document.getElementById( currentSlide );
	if( srcDiv ){
	    srcDiv.style.border = "1px solid #85C6D8";
	}
	currentSlide = currSlide;
	srcDiv = document.getElementById( currentSlide );
	if( srcDiv ){
	    srcDiv.style.border = "1px solid #1899C4";		// try: #1899C4 (dark blue)  #B96119 (orange)
	}
  }
  function showTidbit( img, fullImg, zoom, caption, enlargeText, enlargeCaption, header, text, objectid ){
	var loadInfo = "";
	var imgSRC = String( img );				// deal with spaces in filenames
	imgSRC = imgSRC.replace(/ /g, "%20");

	var imgCaption = String( caption );			// deal with quotes in caption
	imgCaption = imgCaption.replace(/'/g, '\\\'');
	imgCaption = imgCaption.replace(/"/g, '\%22');

	var imgText = String( enlargeText );			// deal with quotes in text
	imgText = imgText.replace(/'/g, '\\\'');
	imgText = imgText.replace(/"/g, '\%22');

	var imgEnlargeCaption = String( enlargeCaption );	// deal with quotes in enlarge caption
	imgEnlargeCaption = imgEnlargeCaption.replace(/'/g, '\\\'');
	imgEnlargeCaption = imgEnlargeCaption.replace(/"/g, '\%22');

	// if there is enlargeText, use it only; otherwise use caption.
	if( enlargeText == "" ) enlargeText = imgCaption;	//encodeURIComponent( imgCaption );
	else enlargeText = imgText; 				//encodeURIComponent( enlargeText );

	if( document.getElementById ){

	    showDiv( 'content01', "", 0 );

	    // Left pane/image content
	    // Only update if image present, and a real image (not default placeholder)
	    if( img != "" && imgSRC.search(/default/gi) < 0 ){
		selectedDiv = document.getElementById( 'img01Content' );
		scrollDiv = document.getElementById( 'img01' );
		if( selectedDiv ){
		    selectedDiv = document.getElementById( 'img01Content' );

		    // Only put enlarge link if enlarged image is present!
		    var fullSRC = String( fullImg );
		    if( fullSRC != "" & fullSRC.search(/default/gi) < 0 ){
			loadInfo = "<a href=\"javascript:setMedia( '" + fullImg + "', '" + enlargeText + "', '" + imgEnlargeCaption + "', \'EN\', " + zoom + ")\">";
			//loadInfo = "<a href=\"javascript:setMedia( '" + fullImg + "', '', '" + enlargeText + "', \'EN\', " + zoom + ")\">";
			loadInfo += "<img border='0' src='" + imgSRC + "' /></a>";
			loadInfo += "<div class='slideCaption'>" + utf_decode(imgCaption) + "</div>";

			loadInfo += "<a href=\"javascript:setMedia( '" + fullImg + "', '" + enlargeText + "', '" + imgEnlargeCaption + "', \'EN\', " + zoom + ")\"><img src='../images/SAM/enlarge.gif' /></a>";
			//loadInfo += "<a href=\"javascript:setMedia( '" + fullImg + "', '', '" + enlargeText + "', \'EN\', " + zoom + ")\"><img src='../images/SAM/enlarge.gif' /></a>";
		    } else {
			loadInfo = "<img border='0' src='" + imgSRC + "' />";
			loadInfo += "<div class='slideCaption'>" + utf_decode(imgCaption) + "</div>";
		    }

		    // If this object is present in the collection database, link to it!
		    if( objectid ){
			loadInfo += "&nbsp;&nbsp;<a href=\"javascript:linksearch( 'objects','objects','id'," + objectid + ",'single','' )\"><img src='../images/SAM/linkTo.gif' /></a>";
		    }

		    selectedDiv.innerHTML = loadInfo;
		}
		showDiv( 'img01', "", 1 );
	    }

	    // Right pane/text content
	    // Only update if text present (some slideshows don't change the text)
	    selectedDiv = document.getElementById( 'txt01Content' );
	    scrollDiv = document.getElementById( 'txt01' );
	    if( selectedDiv && text ){
		loadInfo = "<h3>" + header + "</h3><p>" + utf_decode(text) + "</p>";
		selectedDiv.innerHTML = loadInfo;
	        showDiv( 'txt01', "", 1 );
	    } else if( scrollDiv ){
		// reset to top of div
	        scrollDiv.contentScroll( "0", "0", false );
	    }
	}
  }

  // Load and play Flash Video
  //  parameters:	div	content holder for movie
  //			src	movie source file
  //			caption	movie caption
  //			text	movie text
  //
  // Flash player expects two FlashVars
  //		FLVmovieSRC	path to movie.flv	movie file
  //		FLVxmlSRC	path to movie.xml	subtitle file
  //

  // Use this function to display a 'FLV' flash video through a standard player (movieXML.swf)
  function showFlashMovie( div, src, caption, text ){
	// This movie may have an XML subtitle file; if so, it is named the same as the movie file
	// with .xml for the extension.  Feed this to the movie player.
	var srcXML = src.replace(/flv/,"xml");	

	if( text )	strText = text;
	else		strText = caption;

	var loadInfo = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
	+ ' CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'
	+ ' WIDTH="320" HEIGHT="280" ID="theMovie">'
	+ ' <PARAM NAME="FlashVars" VALUE="FLVmovieSRC=' + src + '&FLVxmlSRC=' + srcXML + '">'
	+ ' <PARAM NAME="src" VALUE="http://www.seattleartmuseum.org/emuseum/html/movieXML.swf">'
	+ ' <EMBED FlashVars="FLVmovieSRC=' + src + '&FLVxmlSRC=' + srcXML + '" SRC="http://www.seattleartmuseum.org/emuseum/html/movieXML.swf"' 
	+ ' PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"' 
	+ ' WIDTH="320" HEIGHT="280"' 
	+ ' NAME="theMovie"></EMBED> </OBJECT>'
	+ '<p>' + strText + '</p>';

	if( document.getElementById ){
	    // close old content
	    closeSlideShow();
	    closeTimeline();
	    closeAudio();
	    closeMap();
	    showDiv('refresh01', "", 0);
	    hideDiv('overview', "", 0);
	    hideDiv('cakeLayer', "", 0);
	    showDiv('cakeBottom', "", 0);

	    // load new content
	    //showDiv( div, loadInfo, 0 );
	    dstDiv = document.getElementById( 'box01Content' );
	    if( dstDiv ){
		dstDiv.innerHTML = loadInfo;
	    }

	    showDiv( 'box01', "", 1 );
	}
  }

  // Use this function to display a "SWF" flash file
  function showFlashMovieSWF( div, src, caption, text ){

	if( text )	strText = text;
	else		strText = caption;

	var loadInfo = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
	+ 'WIDTH="320" HEIGHT="280"'
	+ 'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
	+ '<PARAM NAME="wmode" VALUE="transparent">'
	+ '<PARAM NAME="MOVIE" VALUE="' + src + '">'
	+ '<PARAM NAME="PLAY" VALUE="true">'
	+ '<PARAM NAME="LOOP" VALUE="false">'
	+ '<PARAM NAME="QUALITY" VALUE="high">'
	+ '<PARAM NAME="MENU" VALUE="false">'
	+ '<EMBED SRC="' + src + '"'
	+ 'WIDTH="320" HEIGHT="280"'
	+ 'wmode="transparent"'
	+ 'PLAY="true"'
	+ 'LOOP="false"'
	+ 'QUALITY="high"'
	+ 'MENU="false"'
	+ 'TYPE="application/x-shockwave-flash"'
	+ 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
	+ '<\/EMBED>'
	+ '<\/OBJECT>'
	+ '<p>' + strText + '</p>';

	if( document.getElementById ){
	    // close old content
	    closeSlideShow();
	    closeTimeline();
	    closeAudio();
	    closeMap();
	    showDiv('refresh01', "", 0);
	    hideDiv('overview', "", 0);
	    hideDiv('cakeLayer', "", 0);
	    showDiv('cakeBottom', "", 0);

	    // load new content
	    //showDiv( div, loadInfo, 0 );
	    dstDiv = document.getElementById( 'box01Content' );
	    if( dstDiv ){
		dstDiv.innerHTML = loadInfo;
	    }

	    showDiv( 'box01', "", 1 );
	}
  }

  // Load and play audio (Windows Media) file
  //  parameters:	div	content holder for movie
  //			src	movie source file
  //
 function playAudioOLD( div, src, caption, text ){

	if( text )	strText = text;
	else		strText = caption;

	var loadInfo = '<OBJECT ID="WMVplayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"'
	+ '     CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"'
	+ '     standby="Loading Microsoft Windows Media Player components..."'
	+ '     TYPE="application/x-oleobject" height="45">'
	+ '	 <PARAM NAME="FileName" VALUE="' + src + '">'
	+ '	 <PARAM NAME="ClickToPlay" VALUE="TRUE">'
	+ '	 <PARAM NAME="AutoStart" VALUE="TRUE">'
	+ '	 <PARAM NAME="ShowAudioControls" VALUE="TRUE">'
	+ '	 <PARAM NAME="AnimationAtStart" VALUE="FALSE">'
	+ '	 <PARAM NAME="ShowDisplay" VALUE="FALSE">'
	+ '	 <PARAM NAME="ShowStatusBar" VALUE="FALSE">'
	+ '	 <PARAM NAME="wmode" VALUE="transparent">'
	+ '	 <embed TYPE="application/x-mplayer2"'
	+ '		  pluginspage="http://www.microsoft.com/windows/windowsmedia/download/"'
	+ '		  filename="' + src + '"'
	+ '		  src="' + src + '"'
	+ '		  Name=MediaPlayer'
	+ '		  ClickToPlay=1'
	+ '		  AutoStart=1'
	+ '		  ShowAudioControls=1'
	+ '		  AnimationAtStart=0'
	+ '		  ShowDisplay=0'
	+ '		  ShowStatusBar=0'
	+ '		  controls="PlayButton"'
	+ '		  wmode="transparent"'
	+ '		  height=45'
	+ '	 </embed>'
	+ '    </OBJECT>'
	+ '<p>' + strText + '</p>';

	if( document.getElementById ){
	    // close old content
	    closeSlideShow();
	    closeTimeline();
	    closeMovie();
	    closeMap();
	    showDiv('refresh01', "", 0);
	    hideDiv('overview', "", 0);
	    hideDiv('cakeLayer', "", 0);
	    showDiv('cakeBottom', "", 0);

	    // load new content
	    showDiv( div, loadInfo, 0 );
	}
  }

  function playAudio( div, src, caption, text ){

	if( text )	strText = text;
	else		strText = caption;

	var loadInfo = '<OBJECT ID="mp3player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
	+ '     CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'
	+ '     WIDTH="100" height="45">'
	+ '	 <PARAM NAME="FlashVars" VALUE="audioSRC=' + src + '">'
	+ '	 <PARAM NAME="src" VALUE="mp3PlayerLarge.swf">'
	+ '	 <embed FlashVars="audioSRC=' + src + '" SRC="mp3PlayerLarge.swf"'
	+ '		 pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"'
	+ '		 filename="' + src + '"'
	+ '		 src="' + src + '"'
	+ '		 Name=mp3Player'
	+ '		 width=100'
	+ '		 height=45'
	+ '	 </embed>'
	+ '    </OBJECT>'
	+ '<p>' + strText + '</p>';

	if( document.getElementById ){
	    // close old content
	    closeSlideShow();
	    closeTimeline();
	    closeMovie();
	    closeMap();
	    showDiv('refresh01', "", 0);
	    hideDiv('overview', "", 0);
	    hideDiv('cakeLayer', "", 0);
	    showDiv('cakeBottom', "", 0);

	    // load new content
	    showDiv( div, loadInfo, 0 );
	}
  }

  // Load and play movie (Windows Media) file
  //  parameters:	div	content holder for movie
  //			src	movie source file
  //
  function showWMV( div, src, caption, text ){

	if( text )	strText = text;
	else		strText = caption;

	var loadInfo = '<OBJECT ID="WMVplayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"'
	+ '     CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"'
	+ '     standby="Loading Microsoft Windows Media Player components..."'
	+ '     TYPE="application/x-oleobject" width="280" height="220">'
	+ '	 <PARAM NAME="FileName" VALUE="' + src + '">'
	+ '	 <PARAM NAME="ClickToPlay" VALUE="TRUE">'
	+ '	 <PARAM NAME="AutoStart" VALUE="TRUE">'
	+ '	 <PARAM NAME="ShowControls" VALUE="TRUE">'
	+ '	 <PARAM NAME="ShowDisplay" VALUE="FALSE">'
	+ '	 <PARAM NAME="ShowStatusBar" VALUE="FALSE">'
	+ '	 <PARAM NAME="wmode" VALUE="transparent">'
	+ '	 <embed TYPE="application/x-mplayer2"'
	+ '		  pluginspage="http://www.microsoft.com/windows/windowsmedia/download/"'
	+ '		  filename="' + src + '"'
	+ '		  src="' + src + '"'
	+ '		  Name=MediaPlayer'
	+ '		  ClickToPlay=1'
	+ '		  AutoStart=1'
	+ '		  ShowControls=1'
	+ '		  ShowDisplay=0'
	+ '		  ShowStatusBar=0'
	+ '		  controls="PlayButton"'
	+ '		  wmode="transparent"'
	+ '		  width=280'
	+ '		  height=220'
	+ '	 </embed>'
	+ '    </OBJECT>'
	+ '<p>' + strText + '</p>';

	if( document.getElementById ){
	    // close old content
	    closeSlideShow();
	    closeTimeline();
	    closeAudio();
	    closeMap();
	    showDiv('refresh01', "", 0);
	    hideDiv('overview', "", 0);
	    hideDiv('cakeLayer', "", 0);
	    showDiv('cakeBottom', "", 0);

	    // load new content
	    //showDiv( div, loadInfo, 0 );
	    dstDiv = document.getElementById( 'box01Content' );
	    if( dstDiv ){
		dstDiv.innerHTML = loadInfo;
	    }

	    showDiv( 'box01', "", 1 );
	}
  }

  function showMap( div, img ){
	if( document.getElementById ){
	    // close old content
	    closeSlideShow();
	    closeTimeline();
	    closeAudio();
	    closeMovie();
	    showDiv('refresh01', "", 0);
	    hideDiv('overview', "", 0);
	    hideDiv('cakeLayer', "", 0);
	    showDiv('cakeBottom', "", 0);

	    // load map
	    showDiv( div, "<img src='" + img + "' />", 0 );
	}
  }

  function closeSlideShow(){
    if( document.getElementById ){

	closeTidbit();

	selectedDiv = document.getElementById( 'slide01Content' );
	if( selectedDiv ){
		selectedDiv.innerHTML = "";
	}
	hideDiv( 'slide01' );
    }
  }
  function closeTidbit(){
    if( document.getElementById ){
	hideDiv( 'content01' );

	selectedDiv = document.getElementById( 'img01Content' );
	if( selectedDiv){
		selectedDiv.innerHTML = "";
	}
	hideDiv( 'img01' );

	selectedDiv = document.getElementById( 'txt01Content' );
	if( selectedDiv){
		selectedDiv.innerHTML = "";
	}
	hideDiv( 'txt01' );
    }
  }
  function closeTimeline(){
    if( document.getElementById ){
	selectedDiv = document.getElementById( 'bigBox01Content' );
	if( selectedDiv ){
		selectedDiv.innerHTML = "";
	}
	hideDiv( 'bigBox01' );
    }
  }
  function closeMovie(){
    //WMVplayer.controls.stop();
    if( document.getElementById ){
	selectedDiv = document.getElementById( 'box01Content' );
	if( selectedDiv ){
		selectedDiv.innerHTML = "";
	}
	hideDiv( 'box01');
    }
  }
  function closeAudio(){
    //WMVplayer.controls.stop();
    if( document.getElementById ){
	hideDiv( 'box02', 1 );
    }
  }
  function closeMap(){
    if( document.getElementById ){
	hideDiv( 'map01', 1 );
    }
  }
  
  //
  //  refreshPage
  //
  //  Parameters:	
  //	imgContent
  //	txtContent
  //
  function refreshPage( imgContent, txtContent ){
    if( document.getElementById ){
	// close unnecessary divs
	closeMovie();
	closeAudio();
	closeMap();
	closeTimeline();
	closeSlideShow();
	hideDiv( 'refresh01' );
	showDiv('overview', "", 0);
	showDiv('cakeLayer', "", 0);
	hideDiv('cakeBottom', "", 0);

 	// refresh main content
	    showDiv( 'content01', "", 0 );

	    selectedDiv = document.getElementById( 'img01Content' );
	    scrollDiv = document.getElementById( 'img01' );
	    if( selectedDiv ){
	    selectedDiv = document.getElementById( 'img01Content' );
		selectedDiv.innerHTML = imgContent;
	    }
	    showDiv( 'img01', "", 1 );

	    selectedDiv = document.getElementById( 'txt01Content' );
	    scrollDiv = document.getElementById( 'txt01' );
	    if( selectedDiv ){
		selectedDiv.innerHTML = txtContent;
	      showDiv( 'txt01', "", 1 );
	    }
    }
  }

  function hideDiv( divName, clearContent ){
	selectedDiv = document.getElementById( divName );
	if( selectedDiv ){
	    selectedDiv.style.visibility="hidden";
	    selectedDiv.style.display = "none";
	    if( clearContent ) selectedDiv.innerHTML = "";
	}
  }
  function showDiv( divName, content, scrollUpdate ){
	selectedDiv = document.getElementById( divName );
	if( selectedDiv ){
	    selectedDiv.style.visibility="visible";
	    selectedDiv.style.display = "block";
	    if( content ) selectedDiv.innerHTML = content;
	    // Kludge: can only enable scroll bars when visible!
	    if( divName=="box01" || divName == "bigBox01" ){
		enableScrollBars( divName );
	    }

	    // if we've updated the content, update the scroller.
	    // in either case, reset to scroll box to the top of the display.
	    if( scrollUpdate ){
		selectedDiv.scrollUpdate();
	        selectedDiv.contentScroll( "0", "0", false );
	    }
	}
  }

  function slideLeft( divName, inc ){
    //if( isIE() ) inc -= 3;
    if( document.getElementById ){
	var selectedDiv = document.getElementById( divName );
	if( selectedDiv ){
		selectedDiv.style.visible = "visible";
		selectedDiv.style.position = "absolute";
		if( isNaN(parseInt( selectedDiv.style.left )) ){
		    selectedDiv.style.left = "0px";
		} 
		var x = parseInt( selectedDiv.style.left );
		x += inc;
		if( x > 0 )x = 0;			// limit slide to first frame   
		//selectedDiv.style.left = x + "px";
		slideDiv( selectedDiv, parseInt(selectedDiv.style.left), x );
	}
    }
  }

  function slideRight( divName, inc ){
    //if( isIE() ) inc -= 3;
    if( document.getElementById ){
	var selectedDiv = document.getElementById( divName );
	if( selectedDiv ){
		selectedDiv.style.visible = "visible";
		selectedDiv.style.position = "absolute";
		if( isNaN(parseInt( selectedDiv.style.left )) ){
		    selectedDiv.style.left = "0px";
		} 
		var x = parseInt( selectedDiv.style.left );		// current position
		var ow = parseInt( selectedDiv.offsetWidth );		// div width
		var p = selectedDiv.parentNode;				// parent div (containing box)
		var pow = parseInt( p.offsetWidth );			// parent div width
		if( ow > pow ){			// don't bother unless child wider than parent!
		    x -= inc;
		    if( x < (pow - ow)) x = (pow - ow);
		    //selectedDiv.style.left = x + "px";
		    slideDiv( selectedDiv, parseInt(selectedDiv.style.left), x );
		}
	}
    }
  }


//
//  Slider routines
//

var hTimer;		// timer handle

var slideEl;		// slide element (or div)
var slideX;		// slide movement increment
var slideStartX;	// slide start x
var slideStopX;		// slide final x

//
//  slideDiv	Slides given div horiztonally
//
//  el		div handle
//  srcX	starting point
//  dstX	ending point
//
function slideDiv( el, srcX, dstX ){
//alert("slideDiv: startX=" + srcX + "; endX=" + dstX );
    slideX = 1;
    slideEl = el;
    slideStartX = srcX;
    slideStopX = dstX;
    //hTimer = setInterval( "doSlide()", 1000 );
    doQuickSlide();
}

//
//  doSlide 	Timer driven function to actually move the div
//
function doSlide(){
	if( slideStopX > slideStartX ){
	    var x = slideStartX - slideX;
	    if( x < slideStopX ){
		clearInterval( hTimer );
		hTimer = null;
		 x = slideStopX;
	    }
	} else {
	    var x = slideStartX + slideX;
	    if( x > slideStopX ){
		clearInterval( hTimer );
		hTimer = null;
		x = slideStopX;
	    }
	}
        slideEl.style.left = x + "px";
}
function doQuickSlide(){		// manual function because I screwed up the above
  var done = 0;
  while( !done ){
	if( slideStopX > slideStartX ){
	    var x = slideStartX - slideX;
	    if( x < slideStopX ){
		x = slideStopX;
		done = 1;
	    }
	} else {
	    var x = slideStartX + slideX;
	    if( x > slideStopX ){
		x = slideStopX;
		done = 1;
	    }
	}
        slideEl.style.left = x + "px";
    }
}

// test - UTF-8 encoding
  
// method for url decoding   
function utf_decode(utftext) {
  if( isIE() ){
        var string = "";   
        var i = 0;   
        var c = c1 = c2 = 0;   
  
        while ( i < utftext.length ) {   
  
            c = utftext.charCodeAt(i);   
  
            if (c < 128) {   
                string += String.fromCharCode(c);   
                i++;   
            }   
	    else if (c == 160 ) {
                i++;   
	    }
            else if((c > 191) && (c < 224)) {   
                c2 = utftext.charCodeAt(i+1);   
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));   
                i += 2;   
            }   
            else {   
                //c2 = utftext.charCodeAt(i+1);   
                //c3 = utftext.charCodeAt(i+2);   
                //string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));   
                //i += 3;   
string += String.fromCharCode(c);   	// we were getting here erroneously; kludge to get back out gracefully.
i++;   					// I hope.
            }   
        }   
        return string;   
    } else {
	return utftext;
    }

}   
  
function isIE(){
    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();
    var is_ie = (agt.indexOf("msie") != -1);
    return is_ie;
}
