/*
ADOBE CONFIDENTIAL
Copyright 2004 Adobe Systems Incorporated
All Rights Reserved.

NOTICE:  All information contained herein is, and remains the property of Adobe Systems Incorporated and its suppliers,
if any.  The intellectual and technical concepts contained herein are proprietary to Adobe Systems Incorporated and its
suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or 
copyright law. Dissemination of this information or reproduction of this material is strictly forbidden unless prior 
written permission is obtained from Adobe Systems Incorporated.
*/

function S7ConfigObject()
{
	this.isVersion		= "2.8";
	this.isViewerRoot	= "/is-viewers";
	this.isRoot		= "/is/image/";

	this.archiveSuffix	= "";
	this.buttonPath		= this.isRoot + "/demo/buttons/";

	//used by js->flash communication.
	var ua        = navigator.userAgent.toLowerCase();
	this.isIeWin  = ua.indexOf('msie') != -1 && ua.indexOf('win') != -1 && ua.indexOf('opera') == -1 && ua.indexOf('webtv') == -1;
	this.isFsCommand = true;
}

S7ConfigObject.prototype.insert = function(s)
{
	document.write(s);
}

S7ConfigObject.prototype.defaultInstanceName = function(img)
{
	var j = img.indexOf('?');
	var j1 = img.indexOf(',');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	j1 = img.indexOf(';');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	j1 = img.indexOf(':');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	j1 = img.indexOf('%3f');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	j1 = img.indexOf('%3F');
	if (j1 > 0 && (j < 0 || j > j1)) j = j1;
	if (j < 0) j = img.length;
	var i = img.lastIndexOf('/', j) + 1;
	return img.substring(i, j);
}

S7ConfigObject.prototype.setFlashParam = function(inId) 
{
	var q = '';
	for (var i = 1; i < arguments.length; i = i + 2)
	{
		if (i + 1 < arguments.length) 
		{
			q += '&' + escape(arguments[i]) + '=' + escape(arguments[i + 1]);
		}
	}
	q = q.substr(1);

	if (this.divId > this.maxDivs)
	{
		this.divId = 1;
	}
	var divcontainer = "flash_setvariables_" + inId + "_" + this.divId;
	this.divId ++;
	
	if (!document.getElementById(divcontainer))
	{
		var divholder = document.createElement("div");
		divholder.id = divcontainer;
		document.body.appendChild(divholder);
	}
	document.getElementById(divcontainer).innerHTML = "";
	var divinfo;
	if (this.isIeWin) {
		divinfo = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='0' height='0'><param name='movie' value='" + this.isViewerRoot + "/flash/gateway.swf'><param name='FlashVars' value='lc=" + inId + "&fq=" + escape(q) + "'></object>";
	} else {
		divinfo = "<embed src='" + this.isViewerRoot + "/flash/gateway.swf' FlashVars='lc=" + inId + "&fq=" + escape(q) + "' width='0' height='0' type='application/x-shockwave-flash'></embed>";
	}
	document.getElementById(divcontainer).innerHTML = divinfo;
};

var flashOk = false;
S7ConfigObject.prototype.checkFlash = function()	//call this function and then test the flashOk variable
{
	if (S7Config.isIeWin)
	{
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flashOk = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9")) \n');
		document.write('if flashOk = false then \n');
		document.write('    flashOk = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8")) \n');
		document.write('end if \n');
		document.write('if flashOk = false then \n');
		document.write('    flashOk = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7")) \n');
		document.write('end if \n');
		document.write('</SCR' + 'IPT\> \n');
	}
	else if (navigator.plugins && navigator.plugins["Shockwave Flash"])
	{
		desc = navigator.plugins["Shockwave Flash"].description;
		flashOk = desc.indexOf(7.0) > 0 || desc.indexOf(8.0) > 0 || desc.indexOf(9.0) > 0;
	}
}

S7ConfigObject.prototype.fsCommand = function(instance)
{
	if (this.fsCommand)
	{
		document.write('<SCR'+'IPT LANGUAGE="VBScript"> Sub ' + instance + '_FSCommand(ByVal command, ByVal args)  call doFSCommand(command, args) end sub </SCR'+'IPT>');
		this.fsCommand = false;
	}
	return this.isIeWin ? 'fscommand:' : 'javascript:';
}

S7ConfigObject.prototype.maxDivs	= 10;
S7ConfigObject.prototype.divId		= 1;

var S7Config		= new S7ConfigObject();

//backwards compatibility
var root			= S7Config.isViewerRoot;
var imageServer		= S7Config.isRoot;
var archiveSuffix	= S7Config.archiveSuffix;
var buttonPath		= S7Config.buttonPath;
function checkFlash() { S7Config.checkFlash(); }

function getParam(p,d)
{
	var str = "" + unescape(document.location);
	var i = Math.max( str.indexOf('?'+p+'='), str.indexOf('&'+p+'=') );
	if ( i < 0 )
		return d;
	i+=2+p.length;
	var i2 = str.indexOf('&',i);
	var returnstr = str.substring(i,(i2<0?str.length:i2));
	return (returnstr.indexOf(',')>0?returnstr.split(','):returnstr);
};

function doFSCommand(inCommand, inArgs)
{
	eval(inArgs);
}

