

//VERSION 2.14
//Version information
var gZViewerMajorVersion=2;
var gZViewerMinorVersion="14";
var gZViewerBaseURL="http://www.zoomify.com/";

//viewer registration globals
var gZViewerCount = 0;
var gZViewerList = new Array();
var gZViewerNames = new Array();
var gZViewerActiveXPresent = false;
var gZViewerActiveXIsOld = false;
var gZViewerActiveXNoCab = false;	//only used in autodectect mode

var gQTPresent = false;
var gQT4 = false;
var gQT5 = false;

//urls
var gZViewerWinPluginUrl = "download/zoomify" + gZViewerMajorVersion + gZViewerMinorVersion + ".exe";
var gZViewerWinActiveXUrl = "download/zoomify" + gZViewerMajorVersion + gZViewerMinorVersion + ".cab#version=" + gZViewerMajorVersion + ",0,0," + gZViewerMinorVersion;
var gZViewerMacPluginUrl = "download/zoomify" + gZViewerMajorVersion + gZViewerMinorVersion + ".sit";
var gZViewerMacPluginUpdateUrl = "download/zoomify" + gZViewerMajorVersion + gZViewerMinorVersion + ".bin";
var gZViewerMacQTUpdateUrl = "download/zoomifyQT" + gZViewerMajorVersion + gZViewerMinorVersion + ".sit";
var gZViewerOSXQTUpdateUrl = "download/zoomifyQT" + gZViewerMajorVersion + gZViewerMinorVersion + "_OSX.sit";
var gZViewerWinQTUpdateUrl = "download/zoomifyQT" + gZViewerMajorVersion + gZViewerMinorVersion + ".exe";
var gZViewerMacGif1 = "download/macIEDownload.gif";
var gZViewerMacGif2 = "download/macIEHaveViewer.gif";
var gZViewerZAToolbarGif = "download/zoomifyToolbar.gif";
var gZViewerActiveXProgress = "download/activexProgress.htm";
var gZViewerDownloadPage = "download/zoomifyVersion.asp";
var gZViewerVersionNumberString =  gZViewerMajorVersion + "," + gZViewerMinorVersion + ",";
var gZViewerVersionInfoString =  "";

//viewer modes
var	kZViewerEnhanced = 0;
var kZViewerClientless = 1;
var kZViewerAutodetect = 2;

//converter modes
var kZConverterNormal = 0;
var kZConverterZoomster = 1;
var kZConverterSave = 2;

//constants
var kZOneMonth = 30 * 24 * 3600 * 1000;
var kZOneYear = 365 * 24 * 3600 * 1000;

function ZoomifyViewer()
{
	//view prefs
	this.file = "";
	this.name = "noname";
	this.width = 400;
	this.height = 300
	this.maxZoom = 100;
	this.maxZoomOut = 100;
	this.backColor = "#000000";
	this.windowPercentWidth = 0;
	this.windowPercentHeight = 0;
	this.baseURL=gZViewerBaseURL;
	this.autoSpin=0;
	this.duration=0;
	this.xOffset=0;
	this.yOffset=0;
	this.initialZoom=0;
	this.zoomifyParamsFile="";
	this.defaultViewer = -1;		//0 == kZViewerEnhanced		- Defaults to the native viewer		
								//1 == kZViewerClientless	- Defaults to zoom anywhere		
								//2 == kZViewerAutodetect	- Smart (Tries to use viewer, and uses ZA otherwise)

	//object specific
	this.objectLooping = 1;
	this.objectFrame = 0;

	//pano specific (in degrees)  They must all be within the range to be valid
	this.panoPitch = -100;		//-90 to 90
	this.panoYaw = -1;			//0 to 360
	this.panoRoll = -1;			//0 to 360
	this.panoMinPitch = -100;		//-90 to 90
	this.panoMinYaw = -1;			//0 to 360
	this.panoMinRoll = -1;			//0 to 360
	this.panoMaxPitch = -100;		//-90 to 90
	this.panoMaxYaw = -1;			//0 to 360
	this.panoMaxRoll = -1;			//0 to 360
	
	this.panoFov = -1;			//0 to 90

	//converter prefs
	this.convertOn = false;
	this.convertID = "";
	this.convertMode = 0;
	this.fileToSave = "";
	this.progressColor = "#ffffff";
	this.completionPage = "";
	
	//this.za
	this.zaFile = "";
	this.zaCompatible = false;
	this.zaNumLevels = 0;
	this.zaXTileArray = new Array();
	this.zaYTileArray = new Array();
	this.zaNumTiles = 0;
	this.zaStartByte = 0;
	this.zaMagic = new Array();
	this.zaLevelWidths = new Array();
	this.zaLevelHeights = new Array();
	this.zaPerlFile = gZViewerBaseURL + "zoomify.pl";
	this.zaNumX = 0;
	this.zaNumY = 0;
	this.zaDefaultLevel = 0;
	this.zaTableWidth = 0;
	this.zaTableHeight = 0;
	this.zaStartX = 0;
	this.zaStartY = 0;
	this.zaEndX = 0;
	this.zaEndY = 0;
	this.zaCurrLevel = 0;
	this.zaImageName = new Array();
	this.zaOffsets = new Array();

	this.viewerWinPluginUrl = "";
	this.viewerWinActiveXUrl = "";
	this.viewerMacPluginUrl = "";
	this.viewerMacGif1 = "";
	this.viewerMacGif2 =  "";
	this.viewerZAToolbarGif =  "";
	this.viewerActiveXProgress =  "";
	this.viewerDownloadPage =  "";
	this.viewerVersionNumberString =   "";
	this.viewerVersionInfoString =   "";
	
	this.progressURL="none";
	this.paletteURL="none";
	this.cropRect="0,0,0,0";
	this.cropRectColor="#ffffff";
	this.dropIdleURL="none";
	this.dropGoodURL="none";
	this.dropBadURL="none";
	this.imageToEditURL="none";
	this.uploadURL="none";

	this.altSplash="none";
	this.altZLogo="none";
	this.infoPage="none";

	//private
	this.viewerUsed = -1;


	//public functions
	this.InsertViewer = ZInsertViewer;			

	//private functions
	this.InsertActiveX = ZActiveXEmbed;
	this.InsertPlugin = ZPluginEmbed;
	this.InsertPluginMac45 = ZInsertMacPlugin;
	this.InsertZA = ZAEmbed;
	this.InsertQT = ZQTEmbed;
	
	//private za functions
	this.GetOffset = ZAGetOffset;
	this.GetTileID = ZAGetTileID;
	this.GetTileRequest = ZAGetTileRequest;
	this.ZoomXY = ZAZoomXY;
	this.ZoomIn = ZAZoomIn;
	this.ZoomOut = ZAZoomOut;
	this.PanRight = ZAPanRight;
	this.PanLeft = ZAPanLeft;
	this.PanUp = ZAPanUp;
	this.PanDown = ZAPanDown;
	this.InitialView = ZAInitialView;
	this.UpdateTiles = ZAUpdateTiles;
	
	this.QTfile = "You must initalize the QTfile Variable.";
	
	//ZSetCookieValue("currentURL", doument.location, 0);
	
	//alert( "Zoomify Viewer()" );
	
}

function ZInstertMacPluginDownload( url )
{
	document.write("<table width=" + this.width + " border=0 cellspacing=0 cellpadding=0 height=" + this.height + " >");
	document.write("  <tr>");
	document.write("    <td>We have detected that the Zoomify plugin is not installed on your machine. ");
	document.write("      To install, please do the following:<br>");
	document.write("      1. <a href='" + url + "'>Click here ");
	document.write("      to download (150K)</a><br>");
	document.write("      2. After downloading is complete, run the installer.<br>");
	document.write("      3. After installation is complete, click <a href='javascript:ZRefreshPlugin();'>here</a> to refresh this page.</td>");
	document.write("  </tr>");
	document.write("</table>");
}

function ZInstertPCPluginDownload( url )
{
	document.write("<table width=" + this.width + " border=0 cellspacing=0 cellpadding=0 height=" + this.height + " >");
	document.write("  <tr>");
	document.write("    <td>We have detected that the Zoomify plugin is not installed on your machine. ");
	document.write("      To install, please do the following:<br>");
	document.write("      1. <a href='" + url + "'>Click here ");
	document.write("      to download(350K)</a><br>");
	document.write("      2. After downloading is complete, run the installer.<br>");
	document.write("      3. After installation is complete, click <a href='javascript:ZRefreshPlugin();'>here</a> to refresh this page.</td>");
	document.write("  </tr>");
	document.write("</table>");
}

function ZInsertMacPlugin()
{
	//alert( "checking for cookie" );
	//check for a cookie
	document.write("<table width=" + this.width + " border=0 cellspacing=0 cellpadding=0 height=" + this.height + " >");
	document.write("  <tr>");
	document.write("    <td>");
	var toolbarHeight=24;
	var cookiePresent=ZGetCookie("ZoomifyInstalled2=");
	if(cookiePresent==1)
	{
		//alert( "have cookie" );
		this.InsertPlugin();
	}
	else
	{
		//alert( "no cookie" );
		this.height-=toolbarHeight;
		this.InsertPlugin();

		document.write("<table width=" + this.width + " border=0 cellspacing=0 cellpadding=0 height=" + toolbarHeight + " >");
		document.write("  <tr  align='center' valign='middle'>");
		document.write("    <td>");
		document.write("    <A HREF='" + this.viewerMacPluginUrl + "'><img border=0 alt='Download the Viewer' src='" + this.viewerMacGif1 + "'></a><A HREF='javascript:ZDropPluginCookie();'><img src='" + this.viewerMacGif2 + "'></a>");
		document.write("  </td>");
		document.write("  </tr>");
		document.write("</table>");
	}
	document.write("  </td>");
	document.write("  </tr>");
	document.write("</table>");
}

function ZInsertViewer()
{
	//alert( "Insert Viewer." );
	var wasSmart = false;

	this.viewerWinPluginUrl = "";
	this.viewerWinActiveXUrl = "";
	this.viewerMacPluginUrl = "";
	this.viewerMacGif1 = "";
	this.viewerMacGif2 =  "";
	this.viewerZAToolbarGif =  "";
	this.viewerActiveXProgress =  "";
	this.viewerDownloadPage =  "";
	this.viewerVersionNumberString =   "";
	this.viewerVersionInfoString =   "";
	
	this.viewerWinPluginUrl = this.baseURL + gZViewerWinPluginUrl;
	this.viewerWinActiveXUrl = this.baseURL + gZViewerWinActiveXUrl;
	this.viewerMacPluginUrl = this.baseURL + gZViewerMacPluginUrl;
	this.viewerMacGif1 = this.baseURL + gZViewerMacGif1;
	this.viewerMacGif2 = this.baseURL + gZViewerMacGif2;
	this.viewerZAToolbarGif = this.baseURL + "download/zoomifyToolbar.gif";
	this.viewerActiveXProgress = this.baseURL + gZViewerActiveXProgress;
	this.viewerVersionInfoString = gZViewerVersionNumberString + this.baseURL + gZViewerDownloadPage;
	
	
	if( ( this.useActiveX_Plugin != true ) &&
		( this.useActiveX_Plugin != false ) &&
		( this.useQT != true ) &&
		( this.useQT != false ) &&
		( this.useZA != true ) &&
		( this.useZA != false ) )
	{
		this.useActiveX_Plugin = true;
		this.useQT = true;
		this.useZA = false;
	};
	
	
	
	
	if( this.defaultViewer == kZViewerAutodetect )
	{
		this.useActiveX_Plugin = true;
		this.useQT = false;
		this.useZA = true;
	}
	else if( this.defaultViewer == kZViewerEnhanced )
	{
		this.useActiveX_Plugin = true;
		this.useQT = false;
		this.useZA = false;
	}
	else if( this.defaultViewer == kZViewerClientless )
	{
		this.useActiveX_Plugin = false;
		this.useQT = false;
		this.useZA = true;
	}
	
	//always register	
	ZRegisterViewer(this, this.name);
	
	if(this.windowPercentWidth > 0 || this.windowPercentHeight > 0)
	{
		if (navigator.appName.indexOf('Netscape') != -1)
		{
			tempWidth=this.windowPercentWidth/100;
			tempHeight=this.windowPercentHeight/100;
			this.width=window.innerWidth*tempWidth;
			this.height=window.innerHeight*tempHeight;
		}
		else
		{
			if (navigator.appVersion.indexOf("Mac") != -1)
			{
				tempWidth=this.windowPercentWidth/100;
				tempHeight=this.windowPercentHeight/100;
				
				this.width=document.body.scrollWidth*tempWidth;
				this.height=document.body.scrollHeight*tempHeight;
				
				
			}
			else
			{
				tempWidth=this.windowPercentWidth;
				tempHeight=this.windowPercentHeight;	
				this.width=tempWidth + "%";
				this.height=tempHeight+"%";
			}	
		}
			
	}
	
	var netscape = false;
	var ie = false;
	var macintosh = false;
	var windows = false;
	var hasPlugin = false;
	var hasActiveX = false;
	var macIE45 = false;
	
	if (navigator.appName == "Netscape")
		netscape = true;
	
	if (navigator.appVersion.indexOf("MSIE") != -1)
		ie = true;
		
	if( (navigator.appVersion.indexOf("MSIE 4.") != -1) || (navigator.appVersion.indexOf("MSIE 3.") != -1) )
		macIE45 = true;
	
	if (navigator.appVersion.indexOf("Mac") != -1)
		macintosh = true;
	
	if (navigator.appVersion.indexOf('Win') != -1)
		windows = true;
	
	if( !macIE45 )
		if( ZHasPlugin("Zoomify Plugin") == true )
			hasPlugin = true;
	
	if( windows && ie )
		ZTestQTIE();
	
	//document.write(navigator.appVersion + "<br>");
	
	if( !macIE45 )
		if( netscape || macintosh )
			ZTestQTNetscape();
	
	if( macIE45 )
	{
		//alert( "Macintosh IE 4.5" );
	}
	
	if( gQTPresent )
	{
		//alert( "QuickTime is Installed." );
	}
	
	if( gQT4 )
	{
		//alert( "QuickTime version = 4." );
	}
	
	if( gQT5 )
	{
		//alert( "QuickTime version = 5." );
	}
	
	if( windows && ie )
		ZTestActiveX();
	
	if( gZViewerActiveXPresent == true )
		hasActiveX = true;
	
	if( netscape )
	{
		//alert( "Browser is Netscape." );
	}
	
	if( ie )
	{
		//alert( "Browser is Internet Explorer." );
	}
	
	if( macintosh )
	{
		//alert( "OS is Macintosh" );
	}

	if( windows )
	{
		//alert( "OS is Windows" );
	}
	
	if( hasPlugin )
	{	
		//alert( "Has Zoomify Plugin" );
	}
	
	if( hasActiveX )
	{	
		//alert( "Has Zoomify ActiveX" );
	}
	
	//if za is on 	
	if( this.useZA && !this.useQT && !this.useActiveX_Plugin )
	{
		//is the file is compatible with za
		if (this.zaCompatible == true)
			this.InsertZA();
		else
			alert("This file is not Zoom Anywhere compatible!");
	}
	else if( this.useQT && !this.useActiveX_Plugin )
	{
		this.InsertQT();
	}
	else if( !this.useQT && this.useActiveX_Plugin )
	{
		if( netscape )
		{
			if( hasPlugin )
			{
				if( macIE45 )
					this.InsertPluginMac();
				else
					this.InsertPlugin();
			}
			else
			{
				if( macintosh )
				{
					ZInstertMacPluginDownload( this.viewerMacPluginUrl );
				}
				else if( windows )
				{
					ZInstertPCPluginDownload( this.viewerWinPluginUrl );
				}
			}
		}
		else if( ie )
		{
			if( macintosh )
			{
				if( macIE45 )
					this.InsertPluginMac();
				else
					this.InsertPlugin();
			}
			else if( windows )
			{
				//if (gZViewerActiveXIsOld == true && gZViewerActiveXPresent == true)
				//	gZViewerActiveXNoCab = true;
				
				this.InsertActiveX();
			}
		}
		else
		{
			//Can't detect Browser, try the plug-in
			this.InsertPlugin();
		}
	}
	else if( this.useQT && this.useActiveX_Plugin )
	{
		if( macIE45 )
		{
			this.InsertPluginMac45();
		}
		else if( windows && ie )
		{
			this.InsertActiveX();
		}
		else if( netscape || ( macintosh && ie && !macIE45 ) )
		{
			if( hasPlugin )
			{
				this.InsertPlugin();
			}
			else if( gQT5 )
			{
				this.InsertQT();
			}
			else
			{
				if( macintosh )
				{
					ZInstertMacPluginDownload( this.viewerMacPluginUrl );
				}
				else if( windows )
				{
					ZInstertPCPluginDownload( this.viewerWinPluginUrl );
				}
			}
		}
	
	}
	else if( this.useZA && this.useActiveX_Plugin )
	{
		if( macIE45 )
		{
			this.InsertPluginMac45();
		}
		else if( windows && ie )
		{
			if( hasActiveX )
			{
				this.InsertActiveX();
			}
			else
			{
				this.InsertZA();
			}
		}
		else if( netscape || ( macintosh && ie && !macIE45 ) )
		{
			if( hasPlugin )
			{
				this.InsertPlugin();
			}
			else
			{
				this.InsertZA();
			}
		}
	}
}


//*********DON'T USE THIS FUNCTION**************
function ZQTEmbed()
{
	//alert( "ZQTEmbed()" );

	document.write( "<OBJECT CLASSID= \"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\"" );
	document.write( "		width=" + this.width );
	document.write( "		height=" + this.height );
	document.write( "		CODEBASE= \"http://www.apple.com/qtactivex/qtplugin.cab\">" );
	document.write( "	<param name=\"src\" value='" + this.QTfile + "'>" );
	document.write( "	<param name=\"autoplay\" value=\"true\">" );
	document.write( "	<param name=\"controller\" value=\"false\">" );
	document.write( "	<embed src='" + this.QTfile + "'" );
	document.write( "		width=" + this.width );
	document.write( "		height=" + this.height );
	document.write( "		autoplay=\"true\"" );
	document.write( "		CONTROLLER=\"false\" PLUGINSPAGE= \"http://www.apple.com/quicktime/download/\">" );
	document.write( "	</EMBED>" );
	document.write( "</OBJECT>" );
}




//*********DON'T USE THIS FUNCTION**************
function ZPluginEmbed()
{

	//alert( "ZPluginEmbed()" );
	//alert( this.file );

	//is it the converter
	
	
		document.write("<embed align=absmiddle type=image/zoom");
		
		if (this.convertOn == true)
		{
			document.write(" convertOn=true");
			document.write(" convertID= '" + this.convertID + "'");
			document.write(" convertMode=" + this.convertMode);
		}
		
		if(this.panoMinPitch > -100)
			document.write(" panoMinPitch=" + this.panoMinPitch);
		if(this.panoMinYaw > -1)
			document.write(" panoMinYaw=" + this.panoMinYaw);
		if(this.panoMinRoll > -1)
			document.write(" panoMinRoll=" + this.panoMinRoll);
		if(this.panoMaxPitch > -100)
			document.write(" panoMaxPitch=" + this.panoMaxPitch);
		if(this.panoMaxYaw > -1)
			document.write(" panoMaxYaw=" + this.panoMaxYaw);
		if(this.panoMaxRoll > -1)
			document.write(" panoMaxRoll=" + this.panoMaxRoll);
		
		document.write(" src='" + this.file + "'");
		document.write(" width=" + this.width);
		document.write(" height=" + this.height);
		document.write(" backgroundColor='" + this.backColor + "'" );
		document.write(" maxZoom=" + this.maxZoom);
		document.write(" objectLooping=" + this.objectLooping);
		document.write(" objectFrame=" + this.objectFrame);
		document.write(" panoPitch=" + this.panoPitch);
		document.write(" panoYaw=" + this.panoYaw);
		document.write(" panoRoll=" + this.panoRoll);
		document.write(" panoFov=" + this.panoFov);
		document.write(" autoSpin=" + this.autoSpin);
		document.write(" duration=" + this.duration);
		document.write(" versionInfo=" + this.viewerVersionInfoString);
		document.write(" xOffset=" + this.xOffset);
		document.write(" yOffset=" + this.yOffset);
		document.write(" initialZoom=" + this.initialZoom);
		document.write(" zoomifyParamsFile='" + this.zoomifyParamsFile + "'");
		document.write(" altSplash='" + this.altSplash + "'");
		document.write(" altZLogo='" + this.altZLogo + "'");
		document.write(" infoPage='" + this.infoPage + "'");
		document.write(" completionPage='" + this.completionPage + "'");
		document.write(" fileToSave='" + this.fileToSave + "'" );
		document.write(" progressColor='" + this.progressColor + "'" );
		document.write(" progressURL='" + this.progressURL + "'");
		document.write(" paletteURL='" + this.paletteURL + "'");
		document.write(" cropRect='" + this.cropRect + "'");
		document.write(" cropRectColor='" + this.cropRectColor + "'");
		document.write(" dropIdleURL='" + this.dropIdleURL + "'");
		document.write(" dropGoodURL='" + this.dropGoodURL + "'");
		document.write(" dropBadURL='" + this.dropBadURL + "'");
		document.write(" imageToEditURL='" + this.imageToEditURL + "'");
		document.write(" uploadURL='" + this.uploadURL + "'");
		document.write(" >");
		document.write("</embed>");	
	

	//if (this.defaultViewer == kZViewerAutodetect)
	//	ZSetCookieValue("ZViewer", "0", kZOneYear);				//0 - native  1-za

}

//*********DON'T USE THIS FUNCTION**************
var gDownloadActiveXWindow;
var gDownloadActiveXInterval;
var gDownloadActiveXWindowClose = false;
function ZActiveXEmbed()
{
	
	//alert( "ZActiveXEmbed" );
	
	//same for both
	if (gZViewerActiveXNoCab == true)
		document.write("<object ID=ZControl width=" + this.width + " height=" + this.height + " id='Zoom' classid='CLSID:F7DC2A2E-FC34-11D3-B1D9-00A0C99B41BB'>");
	else
		document.write("<object ID=ZControl width=" + this.width + " height=" + this.height + " id='Zoom' classid='CLSID:F7DC2A2E-FC34-11D3-B1D9-00A0C99B41BB' codebase='" + this.viewerWinActiveXUrl + "'>");
	
	//viewer
		if (this.convertOn == true)
		{
			document.write("<param name=convertOn value=1 >");
			document.write("<param name=convertID value='" + this.convertID + "'>");

			document.write("<param name=convertMode value=" + this.convertMode + ">");
		}
		if(this.panoMinPitch > -100)
			document.write("<param name=panoMinPitch value=" + this.panoMinPitch + ">");
		if(this.panoMinYaw > -1)
			document.write("<param name=panoMinYaw value=" + this.panoMinYaw + ">");
		if(this.panoMinRoll > -1)
			document.write("<param name=panoMinRoll value=" + this.panoMinRoll + ">");
		if(this.panoMaxPitch > -100)
			document.write("<param name=panoMaxPitch value=" + this.panoMaxPitch + ">");
		if(this.panoMaxYaw > -1)
			document.write("<param name=panoMaxYaw value=" + this.panoMaxYaw + ">");
		if(this.panoMaxRoll > -1)
			document.write("<param name=panoMaxRoll value=" + this.panoMaxRoll + ">");
		
		document.write("<param name=file value='" + this.file + "'>");
		document.write("<param name=backgroundColor value='" + this.backColor + "'>");
		document.write("<param name=maxZoom value=" + this.maxZoom + ">");
		document.write("<param name=maxZoomOut value=" + this.maxZoomOut + ">");
		document.write("<param name=objectLooping value=" + this.objectLooping + ">");
		document.write("<param name=objectFrame value=" + this.objectFrame + ">");
		document.write("<param name=panoPitch value=" + this.panoPitch + ">");
		document.write("<param name=panoYaw value=" + this.panoYaw + ">");
		document.write("<param name=panoRoll value=" + this.panoRoll + ">");
		document.write("<param name=panoFov value=" + this.panoFov + ">");
		document.write("<param name=autoSpin value=" + this.autoSpin + ">");
		document.write("<param name=duration value=" + this.duration + ">");
		document.write("<param name=versionInfo value=" + this.viewerVersionInfoString + ">");
		document.write("<param name=xOffset value=" +  this.xOffset + ">");
		document.write("<param name=yOffset value=" + this.yOffset + ">");
		document.write("<param name=initialZoom value=" + this.initialZoom + ">");
		document.write("<param name=zoomifyParamsFile value=" + this.zoomifyParamsFile + ">");
		document.write("<param name=fileToSave value='" + this.fileToSave + "'>");
		document.write("<param name=backgroundColor value='" + this.backgroundColor + "'>");
		document.write("<param name=progressColor value='" + this.progressColor + "'>");
		document.write("<param name=completionPage value='" + this.completionPage + "'>");
		document.write("<param name=progressURL value='" + this.progressURL + "'>");
		document.write("<param name=paletteURL value='" + this.paletteURL + "'>");
		document.write("<param name=cropRect value='" + this.cropRect + "'>");
		document.write("<param name=cropRectColor value='" + this.cropRectColor + "'>");
		document.write("<param name=dropIdleURL value='" + this.dropIdleURL + "'>");
		document.write("<param name=dropGoodURL value='" + this.dropGoodURL + "'>");
		document.write("<param name=dropBadURL value='" + this.dropBadURL + "'>");
		document.write("<param name=imageToEditURL value='" + this.imageToEditURL + "'>");
		document.write("<param name=uploadURL value='" + this.uploadURL + "'>");
		document.write("<param name=altSplash value='" + this.altSplash + "'>");
		document.write("<param name=altZLogo value='" + this.altZLogo + "'>");
		document.write("<param name=infoPage value='" + this.infoPage + "'>");
		document.write("</object>")
	

	//if the NoCab flag is set, then there is no download to display
	if (gZViewerActiveXNoCab == false)
	{
		if (gZViewerActiveXIsOld == true || gZViewerActiveXPresent == false)
		{
			//alert(gZViewerActiveXPresent);
			theWidth = 320;
			theHeight = 230;
			theParam = "width=" + theWidth + ",height=" + theHeight + ",resizable,scrollbars=no,toolbar=no";
			gDownloadActiveXWindow = window.open(this.viewerActiveXProgress, "activeXprogress", theParam);
		
			//start a timer which checks the gDownloadActiveXWindowClose variable
			//which gets set by the activeX control via a event - yikes
			//If you can figure out a better way, more power to ya  -jg
			gDownloadActiveXInterval = setInterval("ZOnLoadCheck()", 1000);
		}
	}

	//waitg for activeX event
	document.writeln("<SCRIPT LANGUAGE=VBScript>");
	document.writeln("	 Sub ZControl_OnLoad()");
	document.writeln("     gDownloadActiveXWindowClose = true");
	document.writeln("   End Sub");
	document.writeln("</SCRIPT>");


	//if we are in smart mode, drop a cookie
	//if (this.defaultViewer == kZViewerAutodetect)
	//	ZSetCookieValue("ZViewer", "0", kZOneYear);			//0 - native  1-za
}

//This function check if the download window should be closed
function ZOnLoadCheck()
{
	if (gDownloadActiveXWindowClose == true)
	{
		gDownloadActiveXWindow.close();
		clearInterval(gDownloadActiveXInterval);
	}
}

//for use with this function (must be globals!)
//This function test both whether or not the control is there but also
//if it is out of date -jg
var gAXMajorVersion = 0;
var gAXMinorVersion = 0;
var gAXTested = false;
function ZTestActiveX()
{
	if (gAXTested == true)
		return;
	gAXTested = true;
		
	document.writeln("<SCRIPT LANGUAGE=VBScript>");
	document.writeln("	 On Error  Resume Next");
	document.writeln("     Set theObject = CreateObject(\"ZActiveX.Zoom\")");
	document.writeln("     If IsObject(theObject) Then");
	document.writeln("	     gZViewerActiveXPresent = true");
	document.writeln("	     gMajorVersion = theObject.majorVersion");
	document.writeln("	     gMinorVersion = theObject.minorVersion");
	document.writeln("	     if CLng(gZViewerMajorVersion) > gMajorVersion Then");
	document.writeln("			gZViewerActiveXIsOld = true ");
	document.writeln("	     End If");
	document.writeln("	     if CLng(gZViewerMajorVersion) <= gMajorVersion  And CLng(gZViewerMinorVersion) > gMinorVersion Then");
	document.writeln("			gZViewerActiveXIsOld = true ");
	document.writeln("	     End If");
	document.writeln("	   Else");
	document.writeln("	     gZViewerActiveXPresent = false");
	document.writeln("     End If");
	document.writeln("     Set theObject = Nothing");
	document.writeln("</SCRIPT>");
	//alert(gMajorVersion + " " + gMinorVersion);
	//alert(gZViewerMajorVersion + " " + gZViewerMinorVersion);

}

var gQTTested = false;

function ZTestQTIE()
{
	if (gQTTested == true)
		return;
	gQTTested = true;
		
	document.writeln("<SCRIPT LANGUAGE=VBScript>");
	document.writeln("	 On Error  Resume Next");
	document.writeln("     Set theObject = CreateObject(\"QuickTime.QuickTime\")");
	document.writeln("     If IsObject(theObject) Then");
	document.writeln("	     gQTPresent = true");
	document.writeln("	     majorVersion = theObject.majorVersion");
	document.writeln("	     minorVersion = theObject.minorVersion");
	document.writeln("	     if majorVersion = 4 Then");
	document.writeln("			gQT4 = true");
	document.writeln("	     End If");
	document.writeln("	     if majorVersion = 5 Then");
	document.writeln("			gQT5 = true");
	document.writeln("	     End If");
	document.writeln("	   Else");
	document.writeln("	     gQTTested = false");
	document.writeln("     End If");
	document.writeln("     Set theObject = Nothing");
	document.writeln("</SCRIPT>");

}

function ZTestQTNetscape()
{
	if (gQTTested == true)
		return;
	gQTTested = true;
		
	for (var i = 0; i<navigator.plugins.length; i++)
	{
		if( navigator.plugins[i].name.toLowerCase().indexOf("quicktime") != -1 )
		{
			gQTPresent = true;
			//document.write(navigator.plugins[i].name.toLowerCase() + "<br>");
			if( navigator.plugins[i].name.toLowerCase().indexOf(" 4") != -1 )
				gQT4 = true;
			if( navigator.plugins[i].name.toLowerCase().indexOf(" 5") != -1 )
				gQT5 = true;
			return;
		}
	}

}



function ZRefreshPlugin()
{
	navigator.plugins.refresh();
	window.location.reload();
}

function ZHasPlugin(i_plugin)
{
	for (var i = 0; i<navigator.plugins.length; i++)
	{
		//document.write(navigator.plugins[i].name + "<br>");
		//document.write(navigator.plugins[i].description + "<br>");
		if (navigator.plugins[i].name.toLowerCase() == i_plugin.toLowerCase())
		{

			return true;
		}
	}
	
	return false;
}


//delay in Milliseconds
function ZSetCookieValue(i_name, i_value, i_delay)
{
	//drop a cookie
	var theDate = new Date();
	var expireDate = theDate.getTime() + i_delay;
	
	theDate.setTime(expireDate);

	theString = "ZOOMIFY." + i_name + "=" + i_value + "; expires=" + theDate.toGMTString() + "; path=/";	
	document.cookie = theString;
}

function ZGetCookieValue(i_name)
{
	var search = "ZOOMIFY." + i_name + "=";
	var retStr;
	var offset;
	var end;

	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;

			retStr = document.cookie.substring(offset, end);
		}
	}

	return retStr;
}


//old functions
function ZDropPluginCookie()
{
	
	//drop a cookie
	var exp = new Date();
	var oneYearFromNow=exp.getTime() + (365*24*60*60*1000);
	exp.setTime(oneYearFromNow);
	document.cookie = "ZoomifyInstalled2=Yes; expires=" + exp.toGMTString()  + "; path=/";
	document.location.reload();
}


//old functions
function ZGetCookie(arg)
{
	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 1;
		i=document.cookie.indexOf(" ", i) +1;
		if(i==0) break;
	}
	return 0;
}


function ZRegisterViewer(i_obj, i_name)
{
	gZViewerList[gZViewerCount] = i_obj;
	gZViewerNames[gZViewerCount] = i_name;
	gZViewerCount++;
}

function ZGetViewer(i_name)
{
	for (i=0; i<gZViewerCount; i++)
	{
		if (gZViewerNames[i] == i_name)
			return gZViewerList[i];
	}
	
	return null;
}



//--Zoom anywhere--
function ZAEmbed()
{
	//alert( "ZAEmbed" );

	currOffset = this.zaStartByte;
	for(i=0; i<this.zaNumTiles + 1; i++)
	{
		this.zaOffsets[i] = currOffset;
		currOffset += this.GetOffset(i);
	}
	
	for(i=this.zaNumLevels-1;i>=0;i--)
	{	
		if(this.zaYTileArray[i]*64 > this.height || this.zaXTileArray[i]*64 > this.width)
		{
			this.zaDefaultLevel=i+1;
			this.zaNumX=this.zaXTileArray[this.zaDefaultLevel];
			this.zaNumY=this.zaYTileArray[this.zaDefaultLevel];
			this.zaTableWidth=this.zaNumX*64;
			this.zaTableHeight=this.zaNumY*64;
			i=0;
		}
	}
	
	

	this.zaStartX=0;
	this.zaStartY=0;
	this.zaEndX=this.zaNumX-1;
	this.zaEndY=this.zaNumY-1;
	this.zaCurrLevel=this.zaDefaultLevel;
	
	document.writeln("<table width=" + this.width + " border=0 height=" + this.height + " cellpadding=0 cellspacing=0 align='center' >");
	document.writeln("<td align=center valign=middle halign=middle bgcolor=" + this.backColor + " >");
	document.writeln("<table width=" + this.zaTableWidth + " border=0 height=" + this.zaTableHeight + " cellpadding=0 cellspacing=0 align='center' >");
	for(y=0;y<this.zaNumY;y++)
	{
		document.writeln("<tr border=0 cellpadding=0 >");
		for(x=0;x<this.zaNumX;x++)
		{
			tileRequest= this.GetTileRequest(this.zaDefaultLevel,x,y);
			tempImageName="image" + x + "_" + y;
			document.writeln("<td border=0 width=64 height=64 bgcolor=" + this.backColor + " >");
			document.write("<A HREF='javascript:ZAZoomXY(\"" + this.name + "\"," + x + "," + y + ");' >");
			document.write("<img border=0  src=" + tileRequest + " name=" + tempImageName + " width=64 height=64 >");
			document.writeln("</a></td>");
			this.zaImageName[y*this.zaNumX+x]=tempImageName;
		}
	   document.writeln("</tr>");
	}
	document.writeln("</table>");
	document.writeln("</td>");
	document.writeln("</table>");


	//the toolbar
	document.writeln("<table>");
	document.writeln("<tr align=center width=192 height=32 valign=middle halign=middle>");
	document.writeln("<td align=center valign=middle halign=middle bgcolor=#FFFFFF ><img border=0 src='" + this.viewerZAToolbarGif + "' usemap=#ZAToolBar></a></td>");
	document.writeln("</tr>");
	document.writeln("</table>");

	document.writeln("<map name=ZAToolBar>");
	document.writeln("  <area shape=rect coords='123,16,183,28' href='javascript:ZAInitialView(\"" + this.name + "\");'>");
	document.writeln("  <area shape=rect coords='129,2,179,14' href='http://www.zoomify.com/' target=_blank>");
	document.writeln("  <area shape=rect coords='91,17,116,28' href='javascript:ZAPanDown(\"" + this.name + "\");'>");
	document.writeln("  <area shape=rect coords='91,4,115,16' href='javascript:ZAPanUp(\"" + this.name + "\");'>");
	document.writeln("  <area shape=rect coords='74,5,85,27' href='javascript:ZAPanRight(\"" + this.name + "\");'>");
	document.writeln("  <area shape=rect coords='58,5,72,27' href='javascript:ZAPanLeft(\"" + this.name + "\");'>");
	document.writeln("  <area shape=rect coords='32,5,51,27' href='javascript:ZAZoomOut(\"" + this.name + "\");'>");
	document.writeln("  <area shape=rect coords='6,5,28,28' href='javascript:ZAZoomIn(\"" + this.name + "\");'>");
	document.writeln("</map>");


	//if (this.defaultViewer == kZViewerAutodetect)
	//	ZSetCookieValue("ZViewer", "1", kZOneYear);		//0 - native  1-za
}


function ZAGetOffset(i_tileID)
{
	tileIndex=i_tileID*2;
	arrayIndex=Math.floor(tileIndex/1024);
	charIndex=tileIndex%1024;
	
	temp=this.zaMagic[arrayIndex].charCodeAt(charIndex);
	if(temp==126)
		offset=(92-40)*86;
	else
		offset=(temp-40)*86;
		
	//alert(arrayIndex+","+this.zaMagic[arrayIndex].charCodeAt(charIndex)+","+offset);
	charIndex++;
	temp=this.zaMagic[arrayIndex].charCodeAt(charIndex);
	if(temp==126)
		offset+=(92-40);
	else
		offset+=(temp-40);

	//alert(arrayIndex+","+this.zaMagic[arrayIndex].charCodeAt(charIndex)+","+offset);
	return offset;
}

function ZAGetTileID(i_level, i_xTile, i_yTile)
{
	currTile=0;
	
	for(i=0;i<i_level;i++)
		currTile+=this.zaXTileArray[i]*this.zaYTileArray[i];
		
	currTile+=this.zaXTileArray[i_level]*i_yTile+i_xTile;
		
	return currTile;
}

function ZAGetTileRequest(i_level, i_xTile, i_yTile)
{
	tileID = this.GetTileID(i_level, i_xTile, i_yTile);
	
	offset1=this.zaOffsets[tileID];
	offset2=this.zaOffsets[tileID+1];
	
	tileRequest = this.zaPerlFile + "?file=" + this.zaFile + "&begin=" + offset1 + "&end=" + offset2;
	return tileRequest;
}


function ZAUpdateTiles()
{

	while(this.zaEndX > this.zaXTileArray[this.zaCurrLevel]-1)
	{
		this.zaStartX--;
		this.zaEndX--;
	}
	
	while(this.zaEndY > this.zaYTileArray[this.zaCurrLevel]-1)
	{
		this.zaStartY--;
		this.zaEndY--;
	}
	
	while(this.zaStartX < 0)
	{
		this.zaStartX++;
		this.zaEndX++;
	}
	
	while(this.zaStartY < 0)
	{
		this.zaStartY++;
		this.zaEndY++;
	}

	for(y=0;y<this.zaNumY;y++)
	{
		for(x=0;x<this.zaNumX;x++)
		{
			tileRequest= this.GetTileRequest(this.zaCurrLevel,this.zaStartX+x,this.zaStartY+y);
			theName=this.zaImageName[y*this.zaNumX+x];
			document.images[theName].src=tileRequest;
		}
	}
}

//special functions
// i_name is used to get the object for the viewer
function ZAZoomXY(i_name, i_x, i_y)
{

	obj = ZGetViewer(i_name);

	obj.zaCurrLevel--;
	if(obj.zaCurrLevel < 0)
	{
		obj.zaCurrLevel=0;
		obj.UpdateTiles();
		return;
	}
	diffX=2*(i_x-Math.floor((obj.zaNumX)/2));
	diffY=2*(i_y-Math.floor((obj.zaNumY)/2));
	obj.zaStartX=diffX+2*obj.zaStartX+Math.floor((obj.zaEndX-obj.zaStartX)/2)+1;
	obj.zaStartY=diffY+2*obj.zaStartY+Math.floor((obj.zaEndY-obj.zaStartY)/2)+1;
	obj.zaEndX=obj.zaStartX+obj.zaNumX-1;
	obj.zaEndY=obj.zaStartY+obj.zaNumY-1;
	
	obj.UpdateTiles();
}



function ZAZoomIn(i_name)
{
	obj = ZGetViewer(i_name);
	
	x=Math.floor(obj.zaNumX/2);
	y=Math.floor(obj.zaNumY/2);
	obj.ZoomXY(i_name, x,y);
}

function ZAZoomOut(i_name)
{
	obj = ZGetViewer(i_name);
	
	
	obj.zaCurrLevel++;
	if(obj.zaCurrLevel > obj.zaDefaultLevel)
	{
		obj.zaCurrLevel=obj.zaDefaultLevel;
		return;
	}
	
	obj.zaStartX=obj.zaStartX-Math.floor((obj.zaEndX-obj.zaStartX)/2);
	obj.zaStartY=obj.zaStartY-Math.floor((obj.zaEndY-obj.zaStartY)/2);
	
	if(obj.zaStartX<0) obj.zaStartX=0;
	if(obj.zaStartY<0) obj.zaStartY=0;
	
	obj.zaStartX=Math.floor(obj.zaStartX/2);
	obj.zaStartY=Math.floor(obj.zaStartY/2);

	obj.zaEndX=obj.zaStartX+obj.zaNumX-1;
	obj.zaEndY=obj.zaStartY+obj.zaNumY-1;
	
	
	
	obj.UpdateTiles();
	
}

function ZAPanRight(i_name)
{
	obj = ZGetViewer(i_name);
	
	if(obj.zaEndX==obj.zaXTileArray[obj.zaCurrLevel]-1)
		return;
	
	obj.zaStartX++;
	obj.zaEndX++;
	
	obj.UpdateTiles();
}

function ZAPanLeft(i_name)
{
	obj = ZGetViewer(i_name);
	
	if(obj.zaStartX==0)
		return;
	
	obj.zaStartX--;
	obj.zaEndX--;
	
	obj.UpdateTiles();
}

function ZAPanUp(i_name)
{
	obj = ZGetViewer(i_name);
	
	if(obj.zaStartY==0)
		return;
	
	obj.zaStartY--;
	obj.zaEndY--;
	
	obj.UpdateTiles();
}

function ZAPanDown(i_name)
{
	obj = ZGetViewer(i_name);
	
	if(obj.zaEndY==obj.zaYTileArray[obj.zaCurrLevel]-1)
		return;
	
	obj.zaStartY++;
	obj.zaEndY++;
	
	obj.UpdateTiles();
}

function ZAInitialView(i_name)
{
	obj = ZGetViewer(i_name);
	
	obj.zaStartX=0;
	obj.zaStartY=0;
	obj.zaCurrLevel=obj.zaDefaultLevel;
	obj.zaEndX=obj.zaXTileArray[obj.zaCurrLevel]-1;
	obj.zaEndY=obj.zaYTileArray[obj.zaCurrLevel]-1;
	
	obj.UpdateTiles();
}





